Changeset 9e85792 in sasview
- Timestamp:
- Jul 2, 2008 5:37:38 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 96510c8
- Parents:
- c125e0c
- Location:
- park_integration
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/.pydevproject
r4408fb0 r9e85792 4 4 <pydev_project> 5 5 <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> 6 <path>/park_integration 3/src</path>6 <path>/park_integration/src</path> 7 7 </pydev_pathproperty> 8 8 <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property> -
park_integration/ParkFitting.py
r4408fb0 r9e85792 11 11 #from sans.guitools import plottables 12 12 from Loader import Load 13 13 from park import expression 14 14 class SansParameter(park.Parameter): 15 15 """ … … 20 20 def __init__(self, name, model): 21 21 self._model, self._name = model,name 22 self.set(model.getParam(name)) 22 23 def _getvalue(self): return self._model.getParam(self.name) 23 def _setvalue(self,value): self._model.setParam(self.name, value) 24 def _setvalue(self,value): 25 if numpy.isnan(value): 26 print "setting %s.%s to"%(self._model.name,self.name),value 27 self._model.setParam(self.name, value) 24 28 value = property(_getvalue,_setvalue) 25 29 def _getrange(self): … … 130 134 """ 131 135 mylist=[] 136 listmodel=[] 132 137 for k,value in self.fitArrangeList.iteritems(): 133 couple=() 134 model=value.get_model() 135 parameters= self.set_param(model, pars) 136 model = Model(model) 138 #couple=() 139 sansmodel=value.get_model() 140 141 #parameters= self.set_param(model,model.name, pars) 142 parkmodel = Model(sansmodel) 137 143 #print "model created",model.parameterset[0].value,model.parameterset[1].value 138 144 # Make all parameters fitting parameters 139 for p in model.parameterset: 140 p.set([-numpy.inf,numpy.inf]) 141 #p.set([-10,10]) 145 146 147 for p in parkmodel.parameterset: 148 #p.range([-numpy.inf,numpy.inf]) 149 # Convert parameters with initial values into fitted parameters 150 # spanning all possible values. Parameters which are expressions 151 # will remain as expressions. 152 if p.isfixed(): 153 p.set([-numpy.inf,numpy.inf]) 154 142 155 Ldata=value.get_data() 143 156 data=self._concatenateData(Ldata) 144 #print "this data",data 145 #print "data.residuals in createProblem",Ldata[0].residuals 146 #print "data.residuals in createProblem",data.residuals 147 #couple1=(model,Ldata[0]) 148 #mylist.append(couple1) 149 couple=(model,data) 157 data1=Data(data) 158 159 couple=(parkmodel,data1) 150 160 mylist.append(couple) 151 161 #print mylist … … 153 163 #return model,data 154 164 155 def fit(self,pars , qmin=None, qmax=None):165 def fit(self,pars=None, qmin=None, qmax=None): 156 166 """ 157 167 Do the fit 158 168 """ 159 160 modelList=self.createProblem(pars) 161 #model,data=self.createProblem() 162 #fitness=assembly.Fitness(model,data) 163 169 170 print "starting ParkFit.fit()" 171 modelList=self.createProblem() 164 172 problem = park.Assembly(modelList) 165 print "problem :",problem[0].parameterset,problem[0].parameterset.fitted 173 pars=problem.fit_parameters() 174 print "About to call eval",pars 175 print "initial",[p.value for p in pars] 176 problem.eval() 177 #print "M2.B",problem.parameterset['M2.B'].expression,problem.parameterset['M2.B'].value 178 #print "problem :",problem[0].parameterset,problem[0].parameterset.fitted 179 166 180 #problem[0].parameterset['A'].set([0,1000]) 167 181 #print "problem :",problem[0].parameterset,problem[0].parameterset.fitted 168 182 fit.fit(problem, handler= fitresult.ConsoleUpdate(improvement_delta=0.1)) 169 #fit.fit(problem, handler= fitresult.ConsoleUpdate(improvement_delta=0.1))170 183 171 184 … … 182 195 def set_data(self,data,Uid): 183 196 """ Receive plottable and create a list of data to fit""" 184 data=Data(data)197 185 198 if self.fitArrangeList.has_key(Uid): 186 199 self.fitArrangeList[Uid].add_data(data) … … 194 207 return self.fitArrangeList[Uid] 195 208 196 def set_param(self,model, pars):209 def set_param(self,model,name, pars): 197 210 """ Recieve a dictionary of parameter and save it """ 198 211 parameters=[] … … 200 213 raise ValueError, "Cannot set parameters for empty model" 201 214 else: 202 #for key ,value in pars:215 model.name=name 203 216 for key, value in pars.iteritems(): 204 217 param = Parameter(model, key, value) -
park_integration/test/testfitting.py
r7705306 r9e85792 165 165 self.assertEqual(cov1[1][1],cov2[1][1]) 166 166 """ 167 def test2models2dataonconstraint(self): 168 """ test for 2 Models two data one constraint""" 169 from sans.fit.Loader import Load 170 load= Load() 171 #Load the first set of data 172 load.set_filename("testdata1.txt") 173 load.set_values() 174 data1 = Data1D(x=[], y=[],dx=None, dy=None) 175 load.load_data(data1) 176 177 #Load the second set of data 178 load.set_filename("testdata2.txt") 179 load.set_values() 180 data2 = Data1D(x=[], y=[],dx=None, dy=None) 181 load.load_data(data2) 182 183 #Importing the Fit module 184 from sans.fit.Fitting import Fit 185 fitter= Fit() 186 # Receives the type of model for the fitting 187 from sans.guitools.LineModel import LineModel 188 model1 = LineModel() 189 model1.name='M1' 190 model2 = LineModel() 191 model2.name='M2' 192 #set engine for scipy 193 fitter.fit_engine('scipy') 194 engine = fitter.returnEngine() 195 #Do the fit 196 engine.set_model(model1,1) 197 engine.set_data(data1,1) 198 engine.set_model(model2,2) 199 engine.set_data(data2,2) 200 201 try: engine.fit({'A':2,'B':1},None,None) 202 except ValueError,msg: 203 assert str(msg)=="cannot fit more than one model",'Message: <%s>'%(msg) 204 205 #set engine for park 206 fitter= Fit() 207 fitter.fit_engine('park') 208 engine = fitter.returnEngine() 209 #Do the fit 210 engine.set_data(data1,1) 211 engine.set_param(model1,{'A':2,'B':1}) 212 engine.set_model(model1,1) 213 214 engine.set_param(model2,{'A':3,'B':'5*M1.B'}) 215 engine.set_model(model2,2) 216 engine.set_data(data2,2) 217 engine.fit({'A':2,'B':1},None,None) 218
Note: See TracChangeset
for help on using the changeset viewer.