ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/fit_module.py
(Generate patch)
# Line 8 | Line 8
8   #import fit_module as fit
9   #import mdl_module as mdl
10   #ba1.roi[0].model = mdl.drift
11 < #ba1.roi[0].params = {'rate': {'value':1, 'min':-100.0, 'max':100.0, 'fixed':False} }
11 > #ba1.roi[0].params = {'rate': {'value':1, 'min':-100.0, 'max':100.0, 'fixed':'float'} }
12   #success = lma(ba1.roi[0])
13   #for i in ba1.roi: lma(i)
14   """
# Line 58 | Line 58
58   def checkparams(params):
59      """
60      Check that each dictionary in the params dictionary contains the four
61 <    keys (value, min, max, fixed) and add them if necessary. Default is 'fixed':True.
61 >    keys (value, min, max, fixed) and add them if necessary. Default is 'fixed':'fixed'.
62      Also check that when parameters float, min<value<max.    
63      """
64      flag = False
# Line 67 | Line 67
67          if ('value' not in dict.keys()): dict['value'] = 0
68          if ('min' not in dict.keys()): dict['min'] = dict['value']
69          if ('max' not in dict.keys()): dict['max'] = dict['value']
70 <        if ('fixed' not in dict.keys()): dict['fixed'] = True
70 >        if ('fixed' not in dict.keys()): dict['fixed'] = 'fixed'
71          ## Check that when parameters float, min<value<max.
72 <        if (dict['fixed'] == False):
72 >        if (dict['fixed'] == 'float'):
73              if (dict['min'] >= dict['max']):
74                  ## Set max to be 1+min.
75                  dict['max'] = float(dict['min']) + 1.0
# Line 84 | Line 84
84      ## End of checkparams() function.
85  
86  
87 < #### The code below is an alternative strategy for constrained parameters ####
87 > #### The code below is a variant allowing parameter constraints ####
88   def transform(a, b, x0):
89      """
90      A transformation to convert x from range (-inf,+inf) to (a,b).
# Line 171 | Line 171
171          checkparams(roi.params)
172          ## For each parameter with its dictionary...
173          for pkey,pd in roi.params.iteritems():
174 <            if (pd['fixed'] == True):  
174 >            if (pd['fixed'] == 'fixed'):  
175                  ## Fixed parameter.
176                  pass
177 <            elif (pd['fixed'] == False):  
177 >            elif (pd['fixed'] == 'float'):  
178                  ## Floating parameter.
179                  pval.append(pd['value'])  ## e.g. 1e5
180                  ## Perform transform based on min/max constraints.
# Line 209 | Line 209
209          print j, # Temp
210          ## For each parameter with its dictionary...
211          for pkey,pd in roi.params.iteritems():
212 <            if (pd['fixed'] == False): ## Floating parameter. Transform back.
212 >            if (pd['fixed'] == 'float'):
213 >                ## Floating parameter. Transform back.
214                  i += 1
215                  a, b = float(pd['min']), float(pd['max'])
216                  pd['value'] = transform(a, b, pfloat[i])
# Line 218 | Line 219
219      ## Second, do the floating parameters shared across ROIs.
220      for j,roi in enumerate(rois):
221          for pkey,pd in roi.params.iteritems():
222 <            if (pd['fixed'] == True) or (pd['fixed'] == False):
222 >            if (pd['fixed'] == 'fixed') or (pd['fixed'] == 'float'):
223                  pass
224 <            else:  ## Shared, fixed to a floating parameter in another ROI.
224 >            else:  
225 >                ## Shared--fixed to a floating parameter in another ROI.
226                  refroi = int(pd['fixed'])
227                  pd['value'] = rois[refroi].params[pkey]['value']
228      
# Line 228 | Line 230
230      erf = zeros(0)
231      for roi in rois:
232          e = roi.model(roi.time, roi.value, roi.params) - roi.value
233 <        erf = hstack( (erf, e) )
234 <    print "sum %0.1f" % sum(erf) # Temp.
233 >        erf = hstack( (erf, e) )  ## Concatenation of nparrays.
234 >    print "ssq %0.1f" % sum(erf**2) # Temp.
235      
236      return erf
237      ## End of multi-roi constrained lma erf() function.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines