Changeset aa36f96 in sasview
- Timestamp:
- Jun 3, 2010 2:50:08 PM (15 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:
- d84a90c
- Parents:
- 6126c25
- Location:
- park_integration
- Files:
-
- 47 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r9e8c150 raa36f96 1 2 1 3 import logging, sys 2 4 import park,numpy,math, copy 3 5 from DataLoader.data_info import Data1D 4 6 from DataLoader.data_info import Data2D 7 5 8 class SansParameter(park.Parameter): 6 9 """ 7 8 9 10 SANS model parameters for use in the PARK fitting service. 11 The parameter attribute value is redirected to the underlying 12 parameter value in the SANS model. 10 13 """ 11 14 def __init__(self, name, model): 12 15 """ 13 @param name: the name of the model parameter 14 @param model: the sans model to wrap as a park model 16 :param name: the name of the model parameter 17 :param model: the sans model to wrap as a park model 18 15 19 """ 16 20 self._model, self._name = model,name … … 20 24 def _getvalue(self): 21 25 """ 22 override the _getvalue of park parameter 23 @return value the parameter associates with self.name 26 override the _getvalue of park parameter 27 28 :return value the parameter associates with self.name 29 24 30 """ 25 31 return self._model.getParam(self.name) … … 27 33 def _setvalue(self,value): 28 34 """ 29 override the _setvalue pf park parameter 30 @param value: the value to set on a given parameter 35 override the _setvalue pf park parameter 36 37 :param value: the value to set on a given parameter 38 31 39 """ 32 40 self._model.setParam(self.name, value) … … 36 44 def _getrange(self): 37 45 """ 38 39 46 Override _getrange of park parameter 47 return the range of parameter 40 48 """ 41 49 #if not self.name in self._model.getDispParamList(): … … 54 62 def _setrange(self,r): 55 63 """ 56 override _setrange of park parameter 57 @param r: the value of the range to set 64 override _setrange of park parameter 65 66 :param r: the value of the range to set 67 58 68 """ 59 69 self._model.details[self.name][1:3] = r … … 62 72 class Model(park.Model): 63 73 """ 64 74 PARK wrapper for SANS models. 65 75 """ 66 76 def __init__(self, sans_model, **kw): 67 77 """ 68 @param sans_model: the sans model to wrap using park interface 78 :param sans_model: the sans model to wrap using park interface 79 69 80 """ 70 81 park.Model.__init__(self, **kw) … … 79 90 self.pars=[] 80 91 81 82 92 def getParams(self,fitparams): 83 93 """ 84 return a list of value of paramter to fit 85 @param fitparams: list of paramaters name to fit 94 return a list of value of paramter to fit 95 96 :param fitparams: list of paramaters name to fit 97 86 98 """ 87 99 list=[] … … 94 106 return list 95 107 96 97 108 def setParams(self,paramlist, params): 98 109 """ 99 Set value for parameters to fit 100 @param params: list of value for parameters to fit 110 Set value for parameters to fit 111 112 :param params: list of value for parameters to fit 113 101 114 """ 102 115 try: … … 111 124 def eval(self,x): 112 125 """ 113 override eval method of park model. 114 @param x: the x value used to compute a function 126 override eval method of park model. 127 128 :param x: the x value used to compute a function 129 115 130 """ 116 131 try: … … 122 137 class FitData1D(Data1D): 123 138 """ 124 125 126 139 Wrapper class for SANS data 140 FitData1D inherits from DataLoader.data_info.Data1D. Implements 141 a way to get residuals from data. 127 142 """ 128 143 def __init__(self,x, y,dx= None, dy=None, smearer=None): 129 144 Data1D.__init__(self, x=numpy.array(x), y=numpy.array(y), dx=dx, dy=dy) 130 145 """ 131 @param smearer: is an object of class QSmearer or SlitSmearer132 133 134 135 136 do the following:137 146 :param smearer: is an object of class QSmearer or SlitSmearer 147 that will smear the theory data (slit smearing or resolution 148 smearing) when set. 149 150 The proper way to set the smearing object would be to 151 do the following: :: 152 138 153 from DataLoader.qsmearing import smear_selection 139 154 smearer = smear_selection(some_data) … … 142 157 dx=None, 143 158 dy=[1,2...], smearer= smearer) 144 145 Note that some_data _HAS_ to be of class DataLoader.data_info.Data1D 146 159 160 :Note: that some_data _HAS_ to be of class DataLoader.data_info.Data1D 147 161 Setting it back to None will turn smearing off. 148 162 … … 210 224 def getFitRange(self): 211 225 """ 212 @return the range of data.x to fit226 return the range of data.x to fit 213 227 """ 214 228 return self.qmin, self.qmax … … 216 230 def residuals(self, fn): 217 231 """ 218 Compute residuals. 219 220 If self.smearer has been set, use if to smear 221 the data before computing chi squared. 222 223 @param fn: function that return model value 224 @return residuals 232 Compute residuals. 233 234 If self.smearer has been set, use if to smear 235 the data before computing chi squared. 236 237 :param fn: function that return model value 238 239 :return: residuals 240 225 241 """ 226 242 # Compute theory data f(x) … … 239 255 return (self.y[self.idx]-fx[self.idx])/self.dy[self.idx] 240 256 241 242 243 257 def residuals_deriv(self, model, pars=[]): 244 258 """ 245 @return residuals derivatives . 246 @note: in this case just return empty array 259 :return: residuals derivatives . 260 261 :note: in this case just return empty array 262 247 263 """ 248 264 return [] … … 254 270 Data2D.__init__(self, data= data, err_data= err_data) 255 271 """ 256 257 272 Data can be initital with a data (sans plottable) 273 or with vectors. 258 274 """ 259 275 self.res_err_image=[] … … 267 283 def set_data(self, sans_data2d, qmin=None, qmax=None ): 268 284 """ 269 285 Determine the correct qx_data and qy_data within range to fit 270 286 """ 271 287 self.data = sans_data2d.data … … 299 315 def set_smearer(self,smearer): 300 316 """ 301 317 Set smearer 302 318 """ 303 319 if smearer == None: … … 320 336 self.index_model = (self.index_model) & (numpy.isfinite(self.data)) 321 337 self.index_model = (self.index_model) & (self.res_err_data!=0) 338 322 339 def getFitRange(self): 323 340 """ 324 @return the range of data.x to fit341 return the range of data.x to fit 325 342 """ 326 343 return self.qmin, self.qmax … … 328 345 def residuals(self, fn): 329 346 """ 330 @return the residuals347 return the residuals 331 348 """ 332 349 if self.smearer != None: … … 342 359 return res 343 360 344 345 361 def residuals_deriv(self, model, pars=[]): 346 362 """ 347 @return residuals derivatives . 348 @note: in this case just return empty array 363 :return: residuals derivatives . 364 365 :note: in this case just return empty array 366 349 367 """ 350 368 return [] … … 352 370 class FitAbort(Exception): 353 371 """ 354 355 """ 356 print"Creating fit abort Exception"372 Exception raise to stop the fit 373 """ 374 #print"Creating fit abort Exception" 357 375 358 376 359 377 class SansAssembly: 360 378 """ 361 379 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 362 380 """ 363 381 def __init__(self, paramlist, model=None , data=None, fitresult=None, 364 382 handler=None, curr_thread=None): 365 383 """ 366 @param Model: the model wrapper fro sans -model 367 @param Data: the data wrapper for sans data 384 :param Model: the model wrapper fro sans -model 385 :param Data: the data wrapper for sans data 386 368 387 """ 369 388 self.model = model … … 378 397 def chisq(self, params): 379 398 """ 380 Calculates chi^2 381 @param params: list of parameter values 382 @return: chi^2 399 Calculates chi^2 400 401 :param params: list of parameter values 402 403 :return: chi^2 404 383 405 """ 384 406 sum = 0 … … 391 413 def __call__(self,params): 392 414 """ 393 Compute residuals 394 @param params: value of parameters to fit 415 Compute residuals 416 417 :param params: value of parameters to fit 418 395 419 """ 396 420 #import thread … … 414 438 def __init__(self): 415 439 """ 416 440 Base class for scipy and park fit engine 417 441 """ 418 442 #List of parameter names to fit … … 423 447 def _concatenateData(self, listdata=[]): 424 448 """ 425 _concatenateData method concatenates each fields of all data contains ins listdata. 426 @param listdata: list of data 427 @return Data: Data is wrapper class for sans plottable. it is created with all parameters 428 of data concatenanted 429 @raise: if listdata is empty will return None 430 @raise: if data in listdata don't contain dy field ,will create an error 449 _concatenateData method concatenates each fields of all data 450 contains ins listdata. 451 452 :param listdata: list of data 453 454 :return Data: Data is wrapper class for sans plottable. it is created with all parameters 455 of data concatenanted 456 457 :raise: if listdata is empty will return None 458 :raise: if data in listdata don't contain dy field ,will create an error 431 459 during fitting 460 432 461 """ 433 462 #TODO: we have to refactor the way we handle data. … … 474 503 475 504 476 def set_model(self,model,Uid,pars=[], constraints=[]): 477 """ 478 set a model on a given uid in the fit engine. 479 @param model: sans.models type 480 @param Uid :is the key of the fitArrange dictionnary where model is saved as a value 481 @param pars: the list of parameters to fit 482 @param constraints: list of 483 tuple (name of parameter, value of parameters) 484 the value of parameter must be a string to constraint 2 different 485 parameters. 486 Example: 487 we want to fit 2 model M1 and M2 both have parameters A and B. 488 constraints can be: 489 constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,] 490 @note : pars must contains only name of existing model's paramaters 505 def set_model(self, model, Uid, pars=[], constraints=[]): 506 """ 507 set a model on a given uid in the fit engine. 508 509 :param model: sans.models type 510 :param Uid: is the key of the fitArrange dictionary where model is 511 saved as a value 512 :param pars: the list of parameters to fit 513 :param constraints: list of 514 tuple (name of parameter, value of parameters) 515 the value of parameter must be a string to constraint 2 different 516 parameters. 517 Example: 518 we want to fit 2 model M1 and M2 both have parameters A and B. 519 constraints can be: 520 constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,] 521 522 523 :note: pars must contains only name of existing model's parameters 524 491 525 """ 492 526 if model == None: … … 535 569 536 570 def set_data(self,data,Uid,smearer=None,qmin=None,qmax=None): 537 """ Receives plottable, creates a list of data to fit,set data 538 in a FitArrange object and adds that object in a dictionary 539 with key Uid. 540 @param data: data added 541 @param Uid: unique key corresponding to a fitArrange object with data 571 """ 572 Receives plottable, creates a list of data to fit,set data 573 in a FitArrange object and adds that object in a dictionary 574 with key Uid. 575 576 :param data: data added 577 :param Uid: unique key corresponding to a fitArrange object with data 578 542 579 """ 543 580 if data.__class__.__name__=='Data2D': … … 558 595 def get_model(self,Uid): 559 596 """ 560 @param Uid: Uid is key in the dictionary containing the model to return 561 @return a model at this uid or None if no FitArrange element was created 597 598 :param Uid: Uid is key in the dictionary containing the model to return 599 600 :return: a model at this uid or None if no FitArrange element was created 562 601 with this Uid 602 563 603 """ 564 604 if self.fitArrangeDict.has_key(Uid): … … 574 614 def select_problem_for_fit(self,Uid,value): 575 615 """ 576 select a couple of model and data at the Uid position in dictionary 577 and set in self.selected value to value 578 @param value: the value to allow fitting. can only have the value one or zero 616 select a couple of model and data at the Uid position in dictionary 617 and set in self.selected value to value 618 619 :param value: the value to allow fitting. 620 can only have the value one or zero 621 579 622 """ 580 623 if self.fitArrangeDict.has_key(Uid): 581 624 self.fitArrangeDict[Uid].set_to_fit( value) 582 625 583 584 626 def get_problem_to_fit(self,Uid): 585 627 """ 586 return the self.selected value of the fit problem of Uid 587 @param Uid: the Uid of the problem 628 return the self.selected value of the fit problem of Uid 629 630 :param Uid: the Uid of the problem 631 588 632 """ 589 633 if self.fitArrangeDict.has_key(Uid): … … 593 637 def __init__(self): 594 638 """ 595 Class FitArrange contains a set of data for a given model 596 to perform the Fit.FitArrange must contain exactly one model 597 and at least one data for the fit to be performed. 598 model: the model selected by the user 599 Ldata: a list of data what the user wants to fit 639 Class FitArrange contains a set of data for a given model 640 to perform the Fit.FitArrange must contain exactly one model 641 and at least one data for the fit to be performed. 642 643 model: the model selected by the user 644 Ldata: a list of data what the user wants to fit 600 645 601 646 """ … … 609 654 def set_model(self,model): 610 655 """ 611 set_model save a copy of the model 612 @param model: the model being set 656 set_model save a copy of the model 657 658 :param model: the model being set 659 613 660 """ 614 661 self.model = model … … 616 663 def add_data(self,data): 617 664 """ 618 add_data fill a self.dList with data to fit 619 @param data: Data to add in the list 665 add_data fill a self.dList with data to fit 666 667 :param data: Data to add in the list 668 620 669 """ 621 670 if not data in self.dList: … … 623 672 624 673 def get_model(self): 625 """ @return: saved model """ 674 """ 675 676 :return: saved model 677 678 """ 626 679 return self.model 627 680 628 681 def get_data(self): 629 """ @return: list of data dList""" 682 """ 683 684 :return: list of data dList 685 686 """ 630 687 #return self.dList 631 688 return self.dList[0] … … 633 690 def remove_data(self,data): 634 691 """ 635 Remove one element from the list 636 @param data: Data to remove from dList 692 Remove one element from the list 693 694 :param data: Data to remove from dList 695 637 696 """ 638 697 if data in self.dList: 639 698 self.dList.remove(data) 699 640 700 def set_to_fit (self, value=0): 641 701 """ 642 set self.selected to 0 or 1 for other values raise an exception 643 @param value: integer between 0 or 1 702 set self.selected to 0 or 1 for other values raise an exception 703 704 :param value: integer between 0 or 1 705 644 706 """ 645 707 self.selected= value … … 647 709 def get_to_fit(self): 648 710 """ 649 @return self.selected value711 return self.selected value 650 712 """ 651 713 return self.selected -
park_integration/Fitting.py
r393f0f3 raa36f96 1 1 """ 2 @organization:Class Fit contains ScipyFit and ParkFit methods declaration3 4 2 Class Fit contains ScipyFit and ParkFit methods declaration 3 allows to create instance of type ScipyFit or ParkFit to perform either 4 a park fit or a scipy fit. 5 5 """ 6 6 … … 12 12 class Fit: 13 13 """ 14 15 can be used as follow:16 14 Wrap class that allows to select the fitting type.this class 15 can be used as follow : :: 16 17 17 from sans.fit.Fitting import Fit 18 18 fitter= Fit() … … 24 24 25 25 chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) 26 26 27 """ 27 28 def __init__(self, engine='scipy'): 28 29 """ 29 self._engine will contain an instance of ScipyFit or ParkFit30 30 """ 31 #self._engine will contain an instance of ScipyFit or ParkFit 31 32 self._engine = None 32 33 self.set_engine(engine) 33 34 34 35 35 def set_engine(self,word): 36 36 """ 37 Select the type of Fit 38 @param word: the keyword to select the fit type 39 @raise: if the user does not enter 'scipy' or 'park', 40 a valueError is rase 37 Select the type of Fit 38 39 :param word: the keyword to select the fit type 40 41 :raise: if the user does not enter 'scipy' or 'park', 42 a valueError is raised 43 41 44 """ 42 45 if word=="scipy": … … 46 49 else: 47 50 raise ValueError, "enter the keyword scipy or park" 48 49 50 51 def fit(self,q=None,handler=None, curr_thread=None): 51 52 def fit(self, q=None, handler=None, curr_thread=None): 52 53 """Perform the fit """ 53 54 try: … … 55 56 except: 56 57 raise 57 58 58 59 59 def set_model(self,model,Uid,pars=[],constraints=[]): … … 66 66 def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None): 67 67 """ 68 Store data to fit at the psotion Uid of the fit engine 69 @param data: data to fit 70 @param smearer: smearerobject to smear data 71 @param qmin: the minimum q range to fit 72 @param qmax: the minimum q range to fit 68 Store data to fit at the psotion Uid of the fit engine 69 70 :param data: data to fit 71 :param smearer: smearerobject to smear data 72 :param qmin: the minimum q range to fit 73 :param qmax: the minimum q range to fit 74 73 75 """ 74 76 self._engine.set_data(data,Uid,smearer,qmin, qmax) … … 81 83 82 84 def remove_Fit_Problem(self,Uid): 83 """remove 85 """remove fitarrange in Uid""" 84 86 self._engine.remove_Fit_Problem(Uid) 85 87 … … 87 89 def select_problem_for_fit(self,Uid,value): 88 90 """ 89 select a couple of model and data at the Uid position in dictionary 90 and set in self.selected value to value 91 @param value: the value to allow fitting. can only have the value one or zero 91 select a couple of model and data at the Uid position in dictionary 92 and set in self.selected value to value 93 94 :param value: the value to allow fitting. 95 can only have the value one or zero 92 96 """ 93 97 self._engine.select_problem_for_fit(Uid,value) … … 96 100 def get_problem_to_fit(self,Uid): 97 101 """ 98 return the self.selected value of the fit problem of Uid 99 @param Uid: the Uid of the problem 102 return the self.selected value of the fit problem of Uid 103 104 :param Uid: the Uid of the problem 105 100 106 """ 101 107 return self._engine.get_problem_to_fit(Uid) -
park_integration/Loader.py
r4408fb0 raa36f96 4 4 class Load: 5 5 """ 6 6 This class is loading values from given file or value giving by the user 7 7 """ 8 8 … … 17 17 def set_filename(self,path=None): 18 18 """ 19 Store path into a variable.If the user doesn't give a path as a parameter a pop-up 20 window appears to select the file. 21 @param path: the path given by the user 19 Store path into a variable.If the user doesn't give a path as a parameter a pop-up 20 window appears to select the file. 21 22 :param path: the path given by the user 23 22 24 """ 23 25 self.filename = path … … 29 31 30 32 def set_values(self): 31 """ Store the values loaded from file in local variables 33 """ Store the values loaded from file in local variables""" 32 34 if not self.filename == None: 33 35 input_f = open(self.filename,'r') … … 61 63 62 64 def get_values(self): 63 """ Return x, y, dx, dy 65 """ Return x, y, dx, dy""" 64 66 return self.x,self.y,self.dx,self.dy 65 67 66 68 def load_data(self,data): 67 """ Return plottable 69 """ Return plottable""" 68 70 #load data 69 71 data.x = self.x -
park_integration/ParkFitting.py
rfd6b789 raa36f96 1 2 3 1 4 """ 2 @organization:ParkFitting module contains SansParameter,Model,Data3 4 5 ParkFitting module contains SansParameter,Model,Data 6 FitArrange, ParkFit,Parameter classes.All listed classes work together to perform a 7 simple fit with park optimizer. 5 8 """ 6 9 import time … … 17 20 class ParkFit(FitEngine): 18 21 """ 19 ParkFit performs the Fit.This class can be used as follow: 20 #Do the fit Park 21 create an engine: engine = ParkFit() 22 Use data must be of type plottable 23 Use a sans model 22 ParkFit performs the Fit.This class can be used as follow: 23 #Do the fit Park 24 create an engine: engine = ParkFit() 25 Use data must be of type plottable 26 Use a sans model 27 28 Add data with a dictionnary of FitArrangeList where Uid is a key and data 29 is saved in FitArrange object. 30 engine.set_data(data,Uid) 31 32 Set model parameter "M1"= model.name add {model.parameter.name:value}. 33 34 :note: Set_param() if used must always preceded set_model() 35 for the fit to be performed. 36 engine.set_param( model,"M1", {'A':2,'B':4}) 37 38 Add model with a dictionnary of FitArrangeList{} where Uid is a key and model 39 is save in FitArrange object. 40 engine.set_model(model,Uid) 41 42 engine.fit return chisqr,[model.parameter 1,2,..],[[err1....][..err2...]] 43 chisqr1, out1, cov1=engine.fit({model.parameter.name:value},qmin,qmax) 44 45 :note: {model.parameter.name:value} is ignored in fit function since 46 the user should make sure to call set_param himself. 24 47 25 Add data with a dictionnary of FitArrangeList where Uid is a key and data26 is saved in FitArrange object.27 engine.set_data(data,Uid)28 29 Set model parameter "M1"= model.name add {model.parameter.name:value}.30 @note: Set_param() if used must always preceded set_model()31 for the fit to be performed.32 engine.set_param( model,"M1", {'A':2,'B':4})33 34 Add model with a dictionnary of FitArrangeList{} where Uid is a key and model35 is save in FitArrange object.36 engine.set_model(model,Uid)37 38 engine.fit return chisqr,[model.parameter 1,2,..],[[err1....][..err2...]]39 chisqr1, out1, cov1=engine.fit({model.parameter.name:value},qmin,qmax)40 @note: {model.parameter.name:value} is ignored in fit function since41 the user should make sure to call set_param himself.42 48 """ 43 49 def __init__(self): 44 50 """ 45 46 51 Creates a dictionary (self.fitArrangeList={})of FitArrange elements 52 with Uid as keys 47 53 """ 48 54 self.fitArrangeDict={} … … 87 93 self.problem = park.Assembly(mylist) 88 94 89 90 95 def fit(self,q=None,handler=None, curr_thread= None): 91 96 """ 92 Performs fit with park.fit module.It can perform fit with one model 93 and a set of data, more than two fit of one model and sets of data or 94 fit with more than two model associated with their set of data and constraints 97 Performs fit with park.fit module.It can perform fit with one model 98 and a set of data, more than two fit of one model and sets of data or 99 fit with more than two model associated with their set of data and constraints 100 101 :param pars: Dictionary of parameter names for the model and their values. 102 :param qmin: The minimum value of data's range to be fit 103 :param qmax: The maximum value of data's range to be fit 104 105 :note: all parameter are ignored most of the time.Are just there to keep ScipyFit 106 and ParkFit interface the same. 95 107 96 97 @param pars: Dictionary of parameter names for the model and their values. 98 @param qmin: The minimum value of data's range to be fit 99 @param qmax: The maximum value of data's range to be fit 100 @note:all parameter are ignored most of the time.Are just there to keep ScipyFit 101 and ParkFit interface the same. 102 @return result.fitness: Value of the goodness of fit metric 103 @return result.pvec: list of parameter with the best value found during fitting 104 @return result.cov: Covariance matrix 108 :return: result.fitness Value of the goodness of fit metric 109 :return: result.pvec list of parameter with the best value found during fitting 110 :return: result.cov Covariance matrix 111 105 112 """ 106 113 self.createAssembly() … … 127 134 raise ValueError, "SVD did not converge" 128 135 129 130 131 132 -
park_integration/ScipyFitting.py
r59d8b56 raa36f96 1 2 1 3 """ 2 @organization:ScipyFitting module contains FitArrange , ScipyFit,3 4 4 ScipyFitting module contains FitArrange , ScipyFit, 5 Parameter classes.All listed classes work together to perform a 6 simple fit with scipy optimizer. 5 7 """ 6 8 … … 12 14 class fitresult(object): 13 15 """ 14 16 Storing fit result 15 17 """ 16 18 def __init__(self, model=None, paramList=None): … … 29 31 30 32 def set_model(self, model): 33 """ 34 """ 31 35 self.model = model 32 36 33 37 def set_fitness(self, fitness): 38 """ 39 """ 34 40 self.fitness = fitness 35 41 36 42 def __str__(self): 43 """ 44 """ 37 45 if self.pvec == None and self.model is None and self.paramList is None: 38 46 return "No results" … … 45 53 46 54 def print_summary(self): 55 """ 56 """ 47 57 print self 48 58 49 59 class ScipyFit(FitEngine): 50 60 """ 51 ScipyFit performs the Fit.This class can be used as follow: 52 #Do the fit SCIPY 53 create an engine: engine = ScipyFit() 54 Use data must be of type plottable 55 Use a sans model 56 57 Add data with a dictionnary of FitArrangeDict where Uid is a key and data 58 is saved in FitArrange object. 59 engine.set_data(data,Uid) 60 61 Set model parameter "M1"= model.name add {model.parameter.name:value}. 62 @note: Set_param() if used must always preceded set_model() 63 for the fit to be performed.In case of Scipyfit set_param is called in 64 fit () automatically. 65 engine.set_param( model,"M1", {'A':2,'B':4}) 66 67 Add model with a dictionnary of FitArrangeDict{} where Uid is a key and model 68 is save in FitArrange object. 69 engine.set_model(model,Uid) 70 71 engine.fit return chisqr,[model.parameter 1,2,..],[[err1....][..err2...]] 72 chisqr1, out1, cov1=engine.fit({model.parameter.name:value},qmin,qmax) 61 ScipyFit performs the Fit.This class can be used as follow: 62 #Do the fit SCIPY 63 create an engine: engine = ScipyFit() 64 Use data must be of type plottable 65 Use a sans model 66 67 Add data with a dictionnary of FitArrangeDict where Uid is a key and data 68 is saved in FitArrange object. 69 engine.set_data(data,Uid) 70 71 Set model parameter "M1"= model.name add {model.parameter.name:value}. 72 73 :note: Set_param() if used must always preceded set_model() 74 for the fit to be performed.In case of Scipyfit set_param is called in 75 fit () automatically. 76 77 engine.set_param( model,"M1", {'A':2,'B':4}) 78 79 Add model with a dictionnary of FitArrangeDict{} where Uid is a key and model 80 is save in FitArrange object. 81 engine.set_model(model,Uid) 82 83 engine.fit return chisqr,[model.parameter 1,2,..],[[err1....][..err2...]] 84 chisqr1, out1, cov1=engine.fit({model.parameter.name:value},qmin,qmax) 73 85 """ 74 86 def __init__(self): 75 87 """ 76 77 88 Creates a dictionary (self.fitArrangeDict={})of FitArrange elements 89 with Uid as keys 78 90 """ 79 91 self.fitArrangeDict={} … … 83 95 84 96 def fit(self, q=None, handler=None, curr_thread=None): 85 97 """ 98 """ 86 99 fitproblem=[] 87 100 for id ,fproblem in self.fitArrangeDict.iteritems(): -
park_integration/temp_code_exchange.py
rb9d5f88 raa36f96 1 1 """ 2 3 4 2 This file is intended to be a temporary file to communicate in-progress code 3 to the developers. 4 This file should be removed after its content has been used by the team. 5 5 """ 6 6 … … 10 10 def setFitRange(self,qmin=None,qmax=None): 11 11 """ 12 13 14 15 12 Change the fit range. 13 Take into account the fact that if smearing is applied, 14 a wider range in unsmeared Q might be necessary to cover 15 the smeared (observed) Q range. 16 16 """ 17 17 … … 49 49 def residuals(self, fn): 50 50 """ 51 Compute residuals. 52 53 If self.smearer has been set, use if to smear 54 the data before computing chi squared. 55 56 This is a version based on the current version of residuals. 57 58 It takes into account the fact that the unsmearing range 59 might need to be wider than the smeared (observed) range. 60 61 @param fn: function that return model value 62 @return residuals 51 Compute residuals. 52 53 If self.smearer has been set, use if to smear 54 the data before computing chi squared. 55 56 This is a version based on the current version of residuals. 57 58 It takes into account the fact that the unsmearing range 59 might need to be wider than the smeared (observed) range. 60 61 :param fn: function that return model value 62 63 :return: residuals 64 63 65 """ 64 66 x,y = [numpy.asarray(v) for v in (self.x,self.y)] … … 111 113 def residuals_alt(self, fn): 112 114 """ 113 Compute residuals. 114 115 If self.smearer has been set, use if to smear 116 the data before computing chi squared. 117 118 This is a more streamlined version of the above. To use this version, 119 the _BaseSmearer class below needs to be modified to have its __call__ 120 method have the following signature: 121 122 __call__(self, iq, first_bin, last_bin) 123 124 This is because we are storing results in arrays of a length 125 corresponding to the full Q-range. 126 127 It takes into account the fact that the unsmearing range 128 might need to be wider than the smeared (observed) range. 129 130 @param fn: function that return model value 131 @return residuals 115 Compute residuals. 116 117 If self.smearer has been set, use if to smear 118 the data before computing chi squared. 119 120 This is a more streamlined version of the above. To use this version, 121 the _BaseSmearer class below needs to be modified to have its __call__ 122 method have the following signature: 123 124 __call__(self, iq, first_bin, last_bin) 125 126 This is because we are storing results in arrays of a length 127 corresponding to the full Q-range. 128 129 It takes into account the fact that the unsmearing range 130 might need to be wider than the smeared (observed) range. 131 132 :param fn: function that return model value 133 134 :return: residuals 135 132 136 """ 133 137 # Make sure the arrays are numpy arrays, which are … … 187 191 def __call__(self, iq, first_bin=0): 188 192 """ 189 Return the smeared I(q) value at the given q. 190 The smeared I(q) is computed using a predetermined 191 smearing matrix for a particular binning. 192 193 @param q: I(q) array 194 @param first_bin: first bin of the given iq array if shorter than full data length 195 @return: smeared I(q) 193 Return the smeared I(q) value at the given q. 194 The smeared I(q) is computed using a predetermined 195 smearing matrix for a particular binning. 196 197 :param q: I(q) array 198 :param first_bin: first bin of the given iq array if shorter than full data length 199 200 :return: smeared I(q) 201 196 202 """ 197 203 # Sanity check
Note: See TracChangeset
for help on using the changeset viewer.