Changeset aa36f96 in sasview


Ignore:
Timestamp:
Jun 3, 2010 2:50:08 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

working on documentation

Location:
park_integration
Files:
47 added
6 edited

Legend:

Unmodified
Added
Removed
  • park_integration/AbstractFitEngine.py

    r9e8c150 raa36f96  
     1 
     2 
    13import logging, sys 
    24import park,numpy,math, copy 
    35from DataLoader.data_info import Data1D 
    46from DataLoader.data_info import Data2D 
     7 
    58class SansParameter(park.Parameter): 
    69    """ 
    7         SANS model parameters for use in the PARK fitting service. 
    8         The parameter attribute value is redirected to the underlying 
    9         parameter value in the SANS model. 
     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. 
    1013    """ 
    1114    def __init__(self, name, model): 
    1215        """ 
    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         
    1519        """ 
    1620        self._model, self._name = model,name 
     
    2024    def _getvalue(self): 
    2125        """ 
    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         
    2430        """ 
    2531        return self._model.getParam(self.name) 
     
    2733    def _setvalue(self,value): 
    2834        """ 
    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         
    3139        """ 
    3240        self._model.setParam(self.name, value) 
     
    3644    def _getrange(self): 
    3745        """ 
    38             Override _getrange of park parameter 
    39             return the range of parameter 
     46        Override _getrange of park parameter 
     47        return the range of parameter 
    4048        """ 
    4149        #if not  self.name in self._model.getDispParamList(): 
     
    5462    def _setrange(self,r): 
    5563        """ 
    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         
    5868        """ 
    5969        self._model.details[self.name][1:3] = r 
     
    6272class Model(park.Model): 
    6373    """ 
    64         PARK wrapper for SANS models. 
     74    PARK wrapper for SANS models. 
    6575    """ 
    6676    def __init__(self, sans_model, **kw): 
    6777        """ 
    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         
    6980        """ 
    7081        park.Model.__init__(self, **kw) 
     
    7990        self.pars=[] 
    8091   
    81    
    8292    def getParams(self,fitparams): 
    8393        """ 
    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         
    8698        """ 
    8799        list=[] 
     
    94106        return list 
    95107     
    96      
    97108    def setParams(self,paramlist, params): 
    98109        """ 
    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         
    101114        """ 
    102115        try: 
     
    111124    def eval(self,x): 
    112125        """ 
    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         
    115130        """ 
    116131        try: 
     
    122137class FitData1D(Data1D): 
    123138    """  
    124         Wrapper class  for SANS data  
    125         FitData1D inherits from DataLoader.data_info.Data1D. Implements  
    126         a way to get residuals from data. 
     139    Wrapper class  for SANS data  
     140    FitData1D inherits from DataLoader.data_info.Data1D. Implements  
     141    a way to get residuals from data. 
    127142    """ 
    128143    def __init__(self,x, y,dx= None, dy=None, smearer=None): 
    129144        Data1D.__init__(self, x=numpy.array(x), y=numpy.array(y), dx=dx, dy=dy) 
    130145        """ 
    131             @param smearer: is an object of class QSmearer or SlitSmearer 
    132             that will smear the theory data (slit smearing or resolution  
    133             smearing) when set. 
    134              
    135             The proper way to set the smearing object would be to 
    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         
    138153            from DataLoader.qsmearing import smear_selection 
    139154            smearer = smear_selection(some_data) 
     
    142157                                    dx=None, 
    143158                                    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 
    147161            Setting it back to None will turn smearing off. 
    148162             
     
    210224    def getFitRange(self): 
    211225        """ 
    212             @return the range of data.x to fit 
     226        return the range of data.x to fit 
    213227        """ 
    214228        return self.qmin, self.qmax 
     
    216230    def residuals(self, fn): 
    217231        """  
    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         
    225241        """ 
    226242        # Compute theory data f(x) 
     
    239255        return (self.y[self.idx]-fx[self.idx])/self.dy[self.idx] 
    240256      
    241    
    242          
    243257    def residuals_deriv(self, model, pars=[]): 
    244258        """  
    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         
    247263        """ 
    248264        return [] 
     
    254270        Data2D.__init__(self, data= data, err_data= err_data) 
    255271        """ 
    256             Data can be initital with a data (sans plottable) 
    257             or with vectors. 
     272        Data can be initital with a data (sans plottable) 
     273        or with vectors. 
    258274        """ 
    259275        self.res_err_image=[] 
     
    267283    def set_data(self, sans_data2d, qmin=None, qmax=None ): 
    268284        """ 
    269             Determine the correct qx_data and qy_data within range to fit 
     285        Determine the correct qx_data and qy_data within range to fit 
    270286        """ 
    271287        self.data     = sans_data2d.data 
     
    299315    def set_smearer(self,smearer):   
    300316        """ 
    301             Set smearer 
     317        Set smearer 
    302318        """ 
    303319        if smearer == None: 
     
    320336        self.index_model = (self.index_model) & (numpy.isfinite(self.data)) 
    321337        self.index_model = (self.index_model) & (self.res_err_data!=0) 
     338         
    322339    def getFitRange(self): 
    323340        """ 
    324             @return the range of data.x to fit 
     341        return the range of data.x to fit 
    325342        """ 
    326343        return self.qmin, self.qmax 
     
    328345    def residuals(self, fn):  
    329346        """ 
    330             @return the residuals 
     347        return the residuals 
    331348        """  
    332349        if self.smearer != None: 
     
    342359        return res 
    343360         
    344   
    345361    def residuals_deriv(self, model, pars=[]): 
    346362        """  
    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         
    349367        """ 
    350368        return [] 
     
    352370class FitAbort(Exception): 
    353371    """ 
    354         Exception raise to stop the fit 
    355     """ 
    356     print"Creating fit abort Exception" 
     372    Exception raise to stop the fit 
     373    """ 
     374    #print"Creating fit abort Exception" 
    357375 
    358376 
    359377class SansAssembly: 
    360378    """ 
    361          Sans Assembly class a class wrapper to be call in optimizer.leastsq method 
     379    Sans Assembly class a class wrapper to be call in optimizer.leastsq method 
    362380    """ 
    363381    def __init__(self, paramlist, model=None , data=None, fitresult=None, 
    364382                 handler=None, curr_thread=None): 
    365383        """ 
    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         
    368387        """ 
    369388        self.model = model 
     
    378397    def chisq(self, params): 
    379398        """ 
    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         
    383405        """ 
    384406        sum = 0 
     
    391413    def __call__(self,params): 
    392414        """ 
    393             Compute residuals 
    394             @param params: value of parameters to fit 
     415        Compute residuals 
     416         
     417        :param params: value of parameters to fit 
     418         
    395419        """ 
    396420        #import thread 
     
    414438    def __init__(self): 
    415439        """ 
    416             Base class for scipy and park fit engine 
     440        Base class for scipy and park fit engine 
    417441        """ 
    418442        #List of parameter names to fit 
     
    423447    def _concatenateData(self, listdata=[]): 
    424448        """   
    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 
    431459            during fitting 
     460             
    432461        """ 
    433462        #TODO: we have to refactor the way we handle data. 
     
    474503         
    475504         
    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         
    491525        """ 
    492526        if model == None: 
     
    535569     
    536570    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         
    542579        """ 
    543580        if data.__class__.__name__=='Data2D': 
     
    558595    def get_model(self,Uid): 
    559596        """  
    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 
    562601            with this Uid 
     602             
    563603        """ 
    564604        if self.fitArrangeDict.has_key(Uid): 
     
    574614    def select_problem_for_fit(self,Uid,value): 
    575615        """ 
    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                 
    579622        """ 
    580623        if self.fitArrangeDict.has_key(Uid): 
    581624             self.fitArrangeDict[Uid].set_to_fit( value) 
    582625              
    583               
    584626    def get_problem_to_fit(self,Uid): 
    585627        """ 
    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         
    588632        """ 
    589633        if self.fitArrangeDict.has_key(Uid): 
     
    593637    def __init__(self): 
    594638        """ 
    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 
    600645             
    601646        """ 
     
    609654    def set_model(self,model): 
    610655        """  
    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         
    613660        """ 
    614661        self.model = model 
     
    616663    def add_data(self,data): 
    617664        """  
    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         
    620669        """ 
    621670        if not data in self.dList: 
     
    623672             
    624673    def get_model(self): 
    625         """ @return: saved model """ 
     674        """  
     675         
     676        :return: saved model  
     677         
     678        """ 
    626679        return self.model    
    627680      
    628681    def get_data(self): 
    629         """ @return:  list of data dList""" 
     682        """  
     683         
     684        :return: list of data dList 
     685         
     686        """ 
    630687        #return self.dList  
    631688        return self.dList[0]  
     
    633690    def remove_data(self,data): 
    634691        """ 
    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         
    637696        """ 
    638697        if data in self.dList: 
    639698            self.dList.remove(data) 
     699             
    640700    def set_to_fit (self, value=0): 
    641701        """ 
    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         
    644706        """ 
    645707        self.selected= value 
     
    647709    def get_to_fit(self): 
    648710        """ 
    649             @return self.selected value 
     711        return self.selected value 
    650712        """ 
    651713        return self.selected 
  • park_integration/Fitting.py

    r393f0f3 raa36f96  
    11""" 
    2     @organization: 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. 
     2Class Fit contains ScipyFit and ParkFit methods declaration 
     3allows to create instance of type ScipyFit or ParkFit to perform either 
     4a park fit or a scipy fit. 
    55""" 
    66 
     
    1212class Fit: 
    1313    """  
    14         Wrap class that allows to select the fitting type.this class  
    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     
    1717        from sans.fit.Fitting import Fit 
    1818        fitter= Fit() 
     
    2424         
    2525        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) 
     26         
    2627    """   
    2728    def __init__(self, engine='scipy'): 
    2829        """ 
    29             self._engine will contain an instance of ScipyFit or ParkFit 
    3030        """ 
     31        #self._engine will contain an instance of ScipyFit or ParkFit 
    3132        self._engine = None 
    3233        self.set_engine(engine) 
    3334           
    34            
    3535    def set_engine(self,word): 
    3636        """ 
    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              
    4144        """ 
    4245        if word=="scipy": 
     
    4649        else: 
    4750            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): 
    5253        """Perform the fit """ 
    5354        try: 
     
    5556        except: 
    5657            raise 
    57      
    5858     
    5959    def set_model(self,model,Uid,pars=[],constraints=[]): 
     
    6666    def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None): 
    6767        """ 
    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         
    7375        """ 
    7476        self._engine.set_data(data,Uid,smearer,qmin, qmax) 
     
    8183 
    8284    def remove_Fit_Problem(self,Uid): 
    83         """remove   fitarrange in Uid""" 
     85        """remove fitarrange in Uid""" 
    8486        self._engine.remove_Fit_Problem(Uid) 
    8587         
     
    8789    def select_problem_for_fit(self,Uid,value): 
    8890        """ 
    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 
    9296        """ 
    9397        self._engine.select_problem_for_fit(Uid,value) 
     
    96100    def get_problem_to_fit(self,Uid): 
    97101        """ 
    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         
    100106        """ 
    101107        return self._engine.get_problem_to_fit(Uid) 
  • park_integration/Loader.py

    r4408fb0 raa36f96  
    44class Load: 
    55    """ 
    6         This class is loading values from given file or value giving by the user 
     6    This class is loading values from given file or value giving by the user 
    77    """ 
    88     
     
    1717    def set_filename(self,path=None): 
    1818        """ 
    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         
    2224        """ 
    2325        self.filename = path 
     
    2931     
    3032    def set_values(self): 
    31         """ Store the values loaded from file in local variables """ 
     33        """ Store the values loaded from file in local variables""" 
    3234        if not self.filename == None: 
    3335            input_f =  open(self.filename,'r') 
     
    6163             
    6264    def get_values(self): 
    63         """ Return x, y, dx, dy """ 
     65        """ Return x, y, dx, dy""" 
    6466        return self.x,self.y,self.dx,self.dy 
    6567     
    6668    def load_data(self,data): 
    67         """ Return plottable """ 
     69        """ Return plottable""" 
    6870        #load data 
    6971        data.x = self.x 
  • park_integration/ParkFitting.py

    rfd6b789 raa36f96  
     1 
     2 
     3 
    14""" 
    2     @organization: ParkFitting module contains SansParameter,Model,Data 
    3     FitArrange, ParkFit,Parameter classes.All listed classes work together to perform a  
    4     simple fit with park optimizer. 
     5ParkFitting module contains SansParameter,Model,Data 
     6FitArrange, ParkFit,Parameter classes.All listed classes work together to perform a  
     7simple fit with park optimizer. 
    58""" 
    69import time 
     
    1720class ParkFit(FitEngine): 
    1821    """  
    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. 
    2447         
    25         Add data with a dictionnary of FitArrangeList where Uid is a key and data 
    26         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 model 
    35         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 since  
    41         the user should make sure to call set_param himself. 
    4248    """ 
    4349    def __init__(self): 
    4450        """ 
    45             Creates a dictionary (self.fitArrangeList={})of FitArrange elements 
    46             with Uid as keys 
     51        Creates a dictionary (self.fitArrangeList={})of FitArrange elements 
     52        with Uid as keys 
    4753        """ 
    4854        self.fitArrangeDict={} 
     
    8793        self.problem =  park.Assembly(mylist) 
    8894         
    89      
    9095    def fit(self,q=None,handler=None, curr_thread= None): 
    9196        """ 
    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. 
    95107             
    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         
    105112        """ 
    106113        self.createAssembly() 
     
    127134            raise ValueError, "SVD did not converge" 
    128135             
    129  
    130   
    131      
    132     
  • park_integration/ScipyFitting.py

    r59d8b56 raa36f96  
     1 
     2 
    13""" 
    2     @organization: ScipyFitting module contains FitArrange , ScipyFit, 
    3     Parameter classes.All listed classes work together to perform a  
    4     simple fit with scipy optimizer. 
     4ScipyFitting module contains FitArrange , ScipyFit, 
     5Parameter classes.All listed classes work together to perform a  
     6simple fit with scipy optimizer. 
    57""" 
    68 
     
    1214class fitresult(object): 
    1315    """ 
    14         Storing fit result 
     16    Storing fit result 
    1517    """ 
    1618    def __init__(self, model=None, paramList=None): 
     
    2931      
    3032    def set_model(self, model): 
     33        """ 
     34        """ 
    3135        self.model = model 
    3236         
    3337    def set_fitness(self, fitness): 
     38        """ 
     39        """ 
    3440        self.fitness = fitness 
    3541         
    3642    def __str__(self): 
     43        """ 
     44        """ 
    3745        if self.pvec == None and self.model is None and self.paramList is None: 
    3846            return "No results" 
     
    4553     
    4654    def print_summary(self): 
     55        """ 
     56        """ 
    4757        print self    
    4858 
    4959class ScipyFit(FitEngine): 
    5060    """  
    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) 
    7385    """ 
    7486    def __init__(self): 
    7587        """ 
    76             Creates a dictionary (self.fitArrangeDict={})of FitArrange elements 
    77             with Uid as keys 
     88        Creates a dictionary (self.fitArrangeDict={})of FitArrange elements 
     89        with Uid as keys 
    7890        """ 
    7991        self.fitArrangeDict={} 
     
    8395 
    8496    def fit(self, q=None, handler=None, curr_thread=None): 
    85         
     97        """ 
     98        """ 
    8699        fitproblem=[] 
    87100        for id ,fproblem in self.fitArrangeDict.iteritems(): 
  • park_integration/temp_code_exchange.py

    rb9d5f88 raa36f96  
    11""" 
    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. 
     2This file is intended to be a temporary file to communicate in-progress code  
     3to the developers.  
     4This file should be removed after its content has been used by the team. 
    55""" 
    66 
     
    1010    def setFitRange(self,qmin=None,qmax=None): 
    1111        """  
    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.         
     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.         
    1616        """ 
    1717         
     
    4949    def residuals(self, fn): 
    5050        """  
    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         
    6365        """ 
    6466        x,y = [numpy.asarray(v) for v in (self.x,self.y)] 
     
    111113    def residuals_alt(self, fn): 
    112114        """  
    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         
    132136        """ 
    133137        # Make sure the arrays are numpy arrays, which are 
     
    187191    def __call__(self, iq, first_bin=0): 
    188192        """ 
    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         
    196202        """ 
    197203        # Sanity check 
Note: See TracChangeset for help on using the changeset viewer.