[SciPy-User] Fitting a Gaussian

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Jan 17 17:45:04 EST 2011


On Mon, Jan 17, 2011 at 5:29 PM, Benedikt Riedel <briedel at wisc.edu> wrote:
> Mygaussfit basically fits for the sigma, mu and A, for the function
> f(x)=Aexp(-(x-mu)^2/(2sigma^2)). What I am most interested is the A in this
> case and the sigma, since I am trying to compare two gaussians.

f(x) is not a proper density function (A cannot be freely chosen), so
maybe you just want to use scipy.optimize.curve_fit.

What kind of data do you have?

Josef


>
> Thanks for the input.
>
> Cheers,
>
> Ben
>
> On Mon, Jan 17, 2011 at 16:09, <josef.pktd at gmail.com> wrote:
>>
>> On Mon, Jan 17, 2011 at 4:55 PM, Benedikt Riedel <briedel at wisc.edu> wrote:
>> > Hi all,
>> >
>> > I am a bit dumbfounded. I have been trying to figure out how to fit a
>> > gaussian to a data set that I have. The only thing I have been able to
>> > dig
>> > up with so far is that I have to get scipy to compute the mean and
>> > standard
>> > deviation for me and then basically plug those into a gaussian. Just
>> > seems a
>> > little bit odd to me considering that Octave has the mygaussfit function
>> > included or is there an easier method?
>>
>> I don't know what a mygaussfit does, but we have this:
>>
>> >>> rvs = np.random.randn(200)
>> >>> from scipy import stats
>> >>> stats.norm.fit(rvs)
>> (-0.0092383641087203858, 1.0567583206929831)
>> >>> loc, scale = stats.norm.fit(rvs)
>> >>> rvs.mean()
>> -0.0092383641087203858
>> >>> rvs.std()
>> 1.0567583206929831
>> >>> loc, scale
>> (-0.0092383641087203858, 1.0567583206929831)
>> >>> myfrozennorm = stats.norm(loc=loc, scale=scale)
>> >>> myfrozennorm.cdf(2)
>> 0.97137010763982468
>> >>>
>>
>> This assumes that all observations are identically distributed and
>> independent from each other. Otherwise, it get's a little bit more
>> complicated.
>>
>> Josef
>>
>> >
>> > Cheers,
>> >
>> > Ben
>> >
>> > _______________________________________________
>> > SciPy-User mailing list
>> > SciPy-User at scipy.org
>> > http://mail.scipy.org/mailman/listinfo/scipy-user
>> >
>> >
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
> --
> Benedikt Riedel
> Graduate Student University of Wisconsin-Madison
> Department of Physics
> Office: 2304 Chamberlin Hall
> Lab: 6247 Chamberlin Hall
> Tel:  (608) 301-5736
> Cell: (213) 519-1771
> Lab: (608) 262-5916
>
> _______________________________________________
> 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