[SciPy-User] changing covariance factor in scipy.stats.kde.gaussian_kde

josef.pktd@gmai... josef.pktd@gmai...
Mon Dec 6 13:26:30 CST 2010


On Mon, Dec 6, 2010 at 2:07 PM, Carolin Villforth <carovi@utu.fi> wrote:
> Do you mean I should inherit gaussian_kde into my own class and then override  covariance_factor in the inherited class?

yes

http://stackoverflow.com/questions/2678425/fitting-gaussian-kde-in-numpy-scipy-in-python
http://mail.scipy.org/pipermail/scipy-user/2010-January/023877.html

I never checked if there are redundant calculations

Josef

>
> Thanks
>
> On Dec 6, 2010, at 1:48 PM, Robert Kern wrote:
>
>> On Mon, Dec 6, 2010 at 12:47, Carolin Villforth <carovi@utu.fi> wrote:
>>> Hello,
>>>
>>> I have a question concerning the usage of gaussian_kde. I am trying to change the covariance factor for the KDE, this is what I am doing it at the moment:
>>>
>>> myKDE = scipy.stats.kde.gaussian_kde(data)
>>> myKDE.covariance_factor = myKDE.silverman_factor
>>> myKDE._compute_covariance()
>>>
>>> The last line seems to be necessary for the changes to take effect.
>>>
>>> While the above code works, this might create quite an overhead since _compute_variance is executed twice, once in __init__ and then again after the covariance factor has been changed. If I understood correctly, this is not really necessary since silverman_factor does not depend on outputs from _compute_covariance. Also, I always assumed that one should avoid calling '._functions' from outside the class.
>>>
>>> Is there another way to change the covariance factor?
>>
>> Subclass.
>>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>>   -- Umberto Eco
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
> ----------------------------------------------------------
> Carolin Villforth
> PhD Student
> Tuorla Observatory Finland and
> Space Telescope Science Institute
> 3700 San Martin Drive
> 21218 Baltimore, MD
> USA
> phone: +1-410-338-4334
> email: carovi@utu.fi, villfort@stsci.edu
> ----------------------------------------------------------
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list