ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/curvefitting.py
(Generate patch)
# Line 1 | Line 1
1
1   """
2 < Perform the curve fitting for the data object.
2 > CurveFitting: Perform the curve fitting for the data object.
3  
4 < Yuhang Wan, Feb25, 2010
5 < __version__ = "1.0"
4 > Yuhang Wan
5 > Last modified on 100427 (yymmdd) by YW
6  
7 + Typical Pipeline:(work together with "converter.py" and some model class
8 +                    here take the basicmodel as example )
9 + >----------load data-----------
10 + >import converter as cv
11 + >dat = cv.datafile_read("dat_example.obj")
12 + >----------load model----------
13 + >import basicmodel as bm
14 + >m = bm.basicmodel()
15 + >m = m.load_model('model_example.obj')
16 + >---------do the fitting-------
17 + >import curvefitting as cf
18 + >pfit, m2 = cf.fitting(dat, m)
19  
20   """
21 <
21 > __version__ = "100427"
22  
23   import numpy as np
24   import pylab as plt
25   import copy
26   from scipy.optimize import leastsq
27 + import time
28   ## import packageClamp_100225 as Pack
29   ## import SPRdataclass_100225 as SPR
30   ## import modelclass1_1 as Model
# Line 32 | Line 44
44          else:   print 'unreadable status.\n\
45                      please check the parameter infomation!'
46      
47 <    print '-'*50
47 >    print '--'*30
48      print 'The fixed parameters are:', pfix_name
49      print 'The fixed value:'
50      for i,j in enumerate(pfix_name):
51          print j,':',pfix[i]
52          
53 <    print '\n','-'*50    
53 >    print '\n','--'*30    
54      print 'The float parameters are:', pfloat_name
55      print 'The initial value:'
56      for i,j in enumerate(pfloat_name):
57          print j,':',pfloat0[i]
58  
59 <    print '\n','-'*50
59 >    print '\n','--'*30
60  
61      
62      # format examination
# Line 199 | Line 211
211          plt.plot(t, y, ',')  # Plot real data
212          plt.plot(t, sprfunction(t, paralist))  # Plot fitted data
213      plt.show()
202    
214  
215 <    print '\n','-'*50
215 >    print '\n','-'*60
216      print 'The fitted parameters are:', pfit_name
217      print 'The fitted value:'
218      for i,j in enumerate(pfit_name):
# Line 212 | Line 223
223      
224   def updateparainfo(parainfo, pfit, pfit_name):
225      new_parainfo = copy.deepcopy(parainfo)
226 <    print '-'*50
227 <    print 'name\t initial value \t fitted value'
226 >
227 >    print '\n', '+'*25, "Comparison", '+'*25
228 > ##    print '-'*60
229 >    print 'name\t\t initial value \t\t fitted value'
230      for i in new_parainfo:
231          for n,j in enumerate(pfit_name):
232              if i['name'] == j:
233 <                print j, '\t', i['value'], '\t', pfit[n]
233 >                print j, '\t\t ', i['value'], ' \t\t ', pfit[n]
234                  i['value'] = pfit[n]
235              
236      return new_parainfo
# Line 229 | Line 242
242      Input the data object and the model object.
243      '''
244      modelobj = copy.deepcopy(mobj)
245 +    time1 = time.time()
246      global pfloat0_1D, pfix, pfloat_name_1D, pfix_name, sprfunction
247      data = dataobj.data
248      parainfo = modelobj.parainfo
# Line 237 | Line 251
251  
252      pfit = lmafit(data, pfix)
253      parainfo = updateparainfo(parainfo, pfit, pfloat_name)
254 +    
255 +    time2 = time.time()
256 +    print '-'*60
257 +    print "Time elapsed:   %s seconds\n" %(time2-time1)
258      print 'Do you want to update the model with fitted value?'
259      if str.upper(raw_input('y/n : ')) == 'Y':        
260          modelobj.updatemodel(parainfo)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines