scipy - Python- Chi Squared Minimization Problems -


i have been trying fit fourier series solution given equation 21 paper http://arxiv.org/ftp/arxiv/papers/1202/1202.4380.pdf. code not minimizing chi_squared function correctly. have looked through documentation of scipy.optimize , have managed minimize other functions. please suggest fix code or suggest alternative.

from __future__ import division import numpy import scipy.optimize  z            = 0.0314 #m length between thermocouples t1_data      = numpy.array(       [20.0,20.1,20.4,21.0,21.8,22.4,23.1,23.8,25.5,25.2,26.0,26.7,27.3,28.0,28.7,29.3,29.9,30.6,31.2]) t_theory     = numpy.array( [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]) t2_data      = numpy.array( [20.0,20.6,21.7,22.6,23.6,24.4,25.0,25.7,26.5,27.2,27.9,28.6,29.3,30.0,30.7,31.3,31.9,32.6,33.2]) time_diff    = 10 f            = 100  t1_max       = t1_data.max() t1_data      = t1_data/t1_max  t2_max       = t2_data.max() t2_data      = t2_data/t2_max   def omega_n(n):     return ((2*n)+1)*numpy.pi / (2*z)  def phi_n(n):     return numpy.sin(omega_n(n)*z)  def f_n(n):     return 2/ (z*omega_n(n))  def theoretical2(dif):     t_theory[0]=t1_data[0]     d in range(1,len(t1_data)): # calculate theoretical data          n in range((f+1)): # n power of fourier co-efficient go             p in range(1, d+1):                 exp_pow3 = -1 * dif * time_diff * (d-p)* (omega_n(n))**2                         t_theory[d] = t_theory[d-1] + (t1_data[(p-1)] -    t1_data[p])*f_n(n)*phi_n(n)*numpy.exp(exp_pow3)   def chi_squared(dif):     theoretical2(dif)     chi_sum = 0     c in range ( len(t2_data)):         chi_sum = chi_sum + (t_theory[c] - t1_data[c])**2     return chi_sum  if __name__ == "__main__":     x0 = 0.0075      diff = scipy.optimize.minimize(chi_squared,x0)     print diff 

thank having through code. appreciated.

thank you, alex


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -