Using weights in non-linear optimization

Hello all,
I am using Optimize function to minimize the value of a multi-variate function. This multi-variate function takes experimental data, and a simulated data is optimized for 4 parameters and this process works perfect.
//---------------------------------------------------------------------------------

function fit_parameters_nlo_IRF(w,p,q,r,T)
// params
//  w   : optional params (not used presently)
//  p   : coef for gas 1
//  q   : coef for gas 2
//  r   : coef for gas 3
//  T   : temperature of the system
wave w
variable p,q,r,T

//  print w[0],w[1],w[2],w[3]
variable E

variable n1, n2, n3

//------------ define experimental waves ---------------
wave expt_1 = root:intensity:ins_1
wave expt_2 = root:intensity:ins_2
wave expt_3 = root:intensity:ins_3
//------------------------------------------------------

// compute spectra for A
spectra_1( T, 5 , 5 )
wave calc_1 = tDependent_spe_1_norm
n1 = dimsize(calc_1,0)

// compute spectra for B
spectra_2( T, 8 , 8 )
wave calc_2 = tDependent_spe_2_norm
n2 = dimsize(calc_2,0)

// compute spectra for C
spectra_3( T, 5 , 5 )
wave calc_3 = tDependent_spe_3_norm
n3 = dimsize(calc_3,0)

// compute error
make /o /d /n = (n_1) diff_1 = ( expt_1  -  ( p  * calc_1 ) )^2
make /o /d /n = (n_2) diff_2 = ( expt_2 - ( q * calc_2 ) )^2
make /o /d /n = (n_3) diff_3 = ( expt_3 - ( r * calc_3 ) )^2

E= wavesum( diff_1 ) + wavesum( diff_2 ) + wavesum( diff_3 )

//  report error
//  printf "Error : %5.9f\r",E

return (E) // E will be minimized by 'optimize'

end
//---------------------------------------------------------------------------------


Some of the experimental data points have high counts ( large y-values) while other have very small counts.
This means I should ideally use weighted non-linear optimization, giving higher weight to high y-value data points. But I could not figure out how to do that.
How can I implement this in the function (given above) which I am optimizing.
I think the only way to do that is to incorporate the weighting in the merit function you are optimizing.

It sounds like you are trying to do a fit to count data. Why not use FitFunc? FitFunc allows you to weight any way you want. Typically, for count data you would weight by sqrt(n).

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com