0

I have a dataset and uncertainty both single arrays of length 100. I have a "model" array also of length 100. Goal: Optimize only one parameter (scaling the amplitude) of this model array to better fit the data given its uncertainty.

so far I've tried:

def residual(params, x, data, eps_data):
   amp = params['amp'].value
   model = amp * x 
   return (data - model)/eps_data
params = Parameters()
params.add('amp',value=100)
out = minimize(residual,params,args=(mod_array,data_array,unc_array))

Then, I multiply the best fit value amplitude with the original model array:

fit = params['amp'].value*mod_array

Then, I plot the fit over the original dataset and it looks absolutely terrible, I don't even see the model anywhere close to the data. What's wrong in the code/algorithm?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Arya
  • 189
  • 4
  • 17

1 Answers1

0

That looks like it should work. But you have not given enough information to be sure. What are the data types for the arrays (they should be numpy ndarrays of dtype numpy.float64 or numpy.float32), and what is the output you get? How much as the value of 'amp' changed in the fit?

Note that if you're using a very recent devel version of numpy, you would (and, in the future will) need to use 'out.params['amp']' for the best-fit value.

M Newville
  • 7,486
  • 2
  • 16
  • 29