MPFIT2DPEAK with constraints

  • Follow


Greetings. I'm trying to understand how Craig 
Markwardt's peak fitting function MPFIT2DPEAK 
works when you wish to require that certain 
parameters be held constant.

Specifically, I know that my data should peak
at the origin and so I'd like to force the 
fitted Gaussian to peak there as well. 

Despite specifying that A[4] and A[5] be 
fixed using the PARINFO structure, the fitted
Gaussian is not centered at the origin. 
Supplying PARINFO to MPFIT2DPEAK does change 
the fit but it actually makes it slighly worse.
Anyone know what I might be doing wrong?

Here's my sample code:

;------------------------------------------------
; Construct a sample gaussian surface in range [-5,5] centered at
[0,0]
   x = findgen(100)*0.1 - 5. & y = x
   xx = x # (y*0 + 1)
   yy = (x*0 + 1) # y
   rr = sqrt((xx-0*2.)^2 + (yy+0*3.)^2)

; Gaussian surface with sigma=0.5, peak value of 3, noise with
sigma=0.2
   seed=6 
   z = 3.*exp(-(rr/0.5)^2) + randomn(seed,100,100)*.2

   pi = replicate({value:0.D, fixed:0, limited:[0,0], $
                       limits:[0.D,0]}, 7)

   pi(4).fixed = 1
   pi(5).fixed = 1

   a0=[0., 3., 1.0, 1.0, 0.0, 0.0, 0.0]
   pi(*).value = a0

; Fit gaussian parameters A
   zfit = mpfit2dpeak(z, a1, x, y, /tilt, PARINFO=pi)

   zfit = mpfit2dpeak(z, a2, x, y, /tilt)

   print,a1
   print,a2
------------------------------------------------

IDL prints:

a1=[-0.000156282, 2.82180, 0.382853, 0.347286, -0.0999999, 0.0999999,
0.716917]

a2=[-0.000266513, 3.06073, 0.345753, 0.351519, -0.000407959,
0.00455947,     1.98130]
0
Reply c.carrano (3) 10/9/2003 10:40:07 PM

c.carrano@att.net (Charles Carrano) writes:
> Greetings. I'm trying to understand how Craig 
> Markwardt's peak fitting function MPFIT2DPEAK 
> works when you wish to require that certain 
> parameters be held constant.
> 
> Specifically, I know that my data should peak
> at the origin and so I'd like to force the 
> fitted Gaussian to peak there as well. 
> 
> Despite specifying that A[4] and A[5] be 
> fixed using the PARINFO structure, the fitted
> Gaussian is not centered at the origin. 
> Supplying PARINFO to MPFIT2DPEAK does change 
> the fit but it actually makes it slighly worse.
> Anyone know what I might be doing wrong?

Greetings--

>    zfit = mpfit2dpeak(z, a1, x, y, /tilt, PARINFO=pi)

The documented way to enter the initial parameters to MPFIT2DPEAK is
using the ESTIMATES keyword.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.      EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------
0
Reply craigmnet (368) 10/10/2003 3:00:26 AM


Craig Markwardt <craigmnet@REMOVEcow.physics.wisc.edu> wrote in message news:<onzng9lrud.fsf@cow.physics.wisc.edu>...
> c.carrano@att.net (Charles Carrano) writes:
> > Greetings. I'm trying to understand how Craig 
> > Markwardt's peak fitting function MPFIT2DPEAK 
> > works when you wish to require that certain 
> > parameters be held constant.
> > 
> > Specifically, I know that my data should peak
> > at the origin and so I'd like to force the 
> > fitted Gaussian to peak there as well. 
> > 
> > Despite specifying that A[4] and A[5] be 
> > fixed using the PARINFO structure, the fitted
> > Gaussian is not centered at the origin. 
> > Supplying PARINFO to MPFIT2DPEAK does change 
> > the fit but it actually makes it slighly worse.
> > Anyone know what I might be doing wrong?
> 
> Greetings--
> 
> >    zfit = mpfit2dpeak(z, a1, x, y, /tilt, PARINFO=pi)
> 
> The documented way to enter the initial parameters to MPFIT2DPEAK is
> using the ESTIMATES keyword.
> 
> Craig

Thank you. I had inadvertently confused the functions 
of the parinfo.value and ESTIMATES parameters. Passing
ESTIMATES=a0 to mpfit2dpeak fixes the sample code
above. Thank you for your help and, of course, your
valuable software contribution to the scientific 
community.

- Charles
0
Reply c.carrano (3) 10/10/2003 2:51:18 PM

2 Replies
65 Views

(page loaded in 0.046 seconds)


Reply: