MPFITFUN AND PARINFO [message #48702] |
Wed, 17 May 2006 08:45  |
JJMeyers2
Messages: 12 Registered: October 2005
|
Junior Member |
|
|
Hello,
I am trying to use MPFITFUN to fit the sum of 2 Gaussians to my data. I
need both of the Gaussians to give curves with positive numbers because
a negative value will not make physical sense. When I run the MPFITFUN
it gives me 1 Gaussian that has all positive values and one Gaussian
that some values are negative. I tried to use PARINFO to costrain the
values for the second Gaussian but I think I am using it wrong.
Here is what I did:
guess_2g=[0.70,0.11,0.3,0.13,532.,1.]
parinfo(5).limited(0)=1.
parinfo(5).limits(0)=0.
fit=mpfitfun('twogauss',X,Y,1,guess_2g,PARINFO=parinfo)
and the error message i receive is:
% Expression must be a structure in this context: PARINFO.
% Execution halted at: fit.pro
I am only interested in constraining the last number for the guess
because that number gives the sign of the second Gaussian. I understand
that I will have to make an array like guess_2g for parinfo but I do
not want to do that because I want to the program to take the initial
values from guess_2g and just turn to parinfo only for the constraints
if it is needed.
Any suggestions on how to do that?
Thank you in advance,
JJM
|
|
|
Re: MPFITFUN AND PARINFO [message #48761 is a reply to message #48702] |
Thu, 18 May 2006 14:32   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
JJMeyers2@gmail.com writes:
> Thank you Graig for the response and the fitting routines of course!
> It works fine now.
>
> I would like to ask you how MPFITFUN handles the case when both parinfo
> and start_parms are set. Does start_parms take precedent over parinfo?
I'm confused, since I answered that question in the previous post.
However, if one reads the documentation, one finds,
; START_PARAMS - ...
; This parameter is optional if the PARINFO keyword
; is used (but see PARINFO). The PARINFO keyword
; provides a mechanism to fix or constrain individual
; parameters. If both START_PARAMS and PARINFO are
; passed, then the starting *value* is taken from
; START_PARAMS, but the *constraints* are taken from
; PARINFO.
> What happens in the case that start_parms and parinfo are in conflict?
> For example if start_parms=[2,1] and parinfo(1).limited(0)=1,
> parinfo(1).limits(0)=2.
Of course you could try it and find out :-)
An error message is returned. You might get one of these errors:
errmsg = 'ERROR: parameters are not within PARINFO limits'
errmsg = 'ERROR: PARINFO parameter limits are not consistent'
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: MPFITFUN [message #50945 is a reply to message #48702] |
Fri, 27 October 2006 11:20  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
nolan.smith1@gmail.com wrote:
> Hello,
>
> I have a little problem with mpfitfun.pro and I was wondering if anyone
> has any suggestions
> on how to solve it. I am using mpfitfun to perform a fit in a function
> that is the sum of 2 exponentials
> and a quadratic. The fit works very good but the result is giving me
> some negative values Y values
> which physically do not make sense (the numbers on Y are numbers per
> bin so they are positive).
> The negative values are only 3 (out of the 50 bins) and they never go
> lower than -1, so they do not go very low. Is there any way to limit
> the Y to be positive (like we do with the parameters?).
The simplest approach is simply to treat fitted values less than 0 as
if they were 0.
A more complicated approach would be to parameterize your model in such
a way that it's easy to impose non-negative results as a constraint on
model parameters. For instance, instead of using a*x^2+b*x+c for the
quadratic part of your model, use a*(x-b)^2+c, so that non-negativety
can be imposed by the requirements that "a GE 0 and c GE 0".
|
|
|