[SciPy-User] log pdf, cdf, etc

josef.pktd at gmail.com josef.pktd at gmail.com
Sat May 29 12:49:06 EDT 2010


On Sat, May 29, 2010 at 12:18 PM, John Reid <j.reid at mail.cryst.bbk.ac.uk> wrote:
> josef.pktd at gmail.com wrote:
>> On Fri, May 28, 2010 at 7:29 AM, Chris Strickland
>> <christophermarkstrickland at gmail.com> wrote:
>>> Hi,
>>>
>>> When using any of the distributions of scipy.stats there does not seem to be
>>> the ability (or at least I cannot figure out how) to have the function
>>> return
>>> the log of the pdf, cdf, sf, etc. For statistical analysis this is
>>> essential.
>>> For instance suppose we are interested in an exponential distribution for a
>>> random variable x with a hyperparameter lambda there needs to be an option
>>> that returns -log(lambda)-x/lambda. It is not sufficient (numerically) to
>>> calculate log(scipy.stats.expon.pdf(x,lambda)).
>>>
>>> Is there a way to do this using the distributions in scipy.stats?
>>
>> It would need a new method for each distribution, e.g. _loglike, _logpdf
>> So, this is work, and for some distributions the log wouldn't simplify much.
>
> Presumably it would be easy to add a method to all distributions that
> called the pdf and took its log. This could be over-riden for those
> distributions for which a specialised log_pdf implementation was
> available. This would make the entry cost of providing the functionality
> lower.

Yes, I haven't thought about it yet for this case, but that's how the
system for the current methods works, only _pdf or _cdf is required,
all other methods have generic substitutes (which are sometimes very
slow.)

For testing, not having the generic version is easier, I have to
figure out again how to check whether a method was defined in the
super or the sub class (instead of using hasattr).

a naming question
_lnpdf or _logpdf ? _lncdf or _logcdf ?

Josef

>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list