PEATDB/Ekin/Fitting.py
def createClass(equation, varnames,
                   guess=None, name=None, 
                   labels=['x','y'], **kwargs):                       
    """Dynamically create an instance of LM_fitter class using presets
       this function requires we pass varnames and equation at minimum"""
    class tempfitter(LM_Fitter):
        def __init__(self, variables, exp_data, callback, name=None):
            LM_Fitter.__init__(self,variables,exp_data,callback, name=None)
            
            self.name = name
            self.varnames = varnames
            if type(self.varnames) is not types.ListType:
                self.varnames = self.varnames.split(',')
            
            self.labels = labels
            self.equation = equation
            self.guess = guess
            if variables == None:
                self.variables = [1.0 for i in self.varnames]
            else:
                self.variables = variables            
            self.setChangeVars()

        def get_value(self, variables, data_point):
            """Evaluate string equation"""
            try:
                x=data_point[0]
            except:
                x=data_point
            eq=self.equation                
            for i in range(len(self.varnames)):
                #print i, self.varnames[i],variables[i] 
                globals()[self.varnames[i]] = variables[i]
            
            try:   
                value = eval(eq)
            except Exception, e:
                value = 1.0
                print e
            return value

        def guess_start(self):
            """Guess start vals using provided strings in guess dict"""
            if self.guess==None:
                return
            guess = self.guess
            #print guess
            if type(guess) is not types.DictType:
                guess = eval(guess)
            x=[i[0] for i in self.exp_data]
            y=[i[1] for i in self.exp_data]                
            for i in range(len(self.varnames)):
                var = self.varnames[i]                    
                if var in guess:
                    self.variables[i] = eval(guess[var])
                    #print  i, var, guess[var],self.variables[i]
            return
        
    return tempfitter
Dynamically create an instance of LM_fitter class using presets
       this function requires we pass varnames and equation at minimum
Dynamically create an instance of LM_fitter class using presets
this function requires we pass varnames and equation at minimum
Dynamically create an instance of LM_fitter class using presets this function requires we pass varnames and equation at minimum
def createClass(equation, varnames,
                   guess=None, name=None, 
                   labels=['x','y'], **kwargs):                       
    class tempfitter(LM_Fitter):
        def __init__(self, variables, exp_data, callback, name=None):
            LM_Fitter.__init__(self,variables,exp_data,callback, name=None)
            self.name = name
            self.varnames = varnames
            if type(self.varnames) is not types.ListType:
                self.varnames = self.varnames.split(',')
            self.labels = labels
            self.equation = equation
            self.guess = guess
            if variables == None:
                self.variables = [1.0 for i in self.varnames]
            else:
                self.variables = variables            
            self.setChangeVars()
        def get_value(self, variables, data_point):
            try:
                x=data_point[0]
            except:
                x=data_point
            eq=self.equation                
            for i in range(len(self.varnames)):
                globals()[self.varnames[i]] = variables[i]
            try:   
                value = eval(eq)
            except Exception, e:
                value = 1.0
                print e
            return value
        def guess_start(self):
            if self.guess==None:
                return
            guess = self.guess
            if type(guess) is not types.DictType:
                guess = eval(guess)
            x=[i[0] for i in self.exp_data]
            y=[i[1] for i in self.exp_data]                
            for i in range(len(self.varnames)):
                var = self.varnames[i]                    
                if var in guess:
                    self.variables[i] = eval(guess[var])
            return
    return tempfitter
def createClass ( equation , varnames , guess = None , name = None , labels = [ 'x' , 'y' ] , ** kwargs ) : class tempfitter ( LM_Fitter ) : def __init__ ( self , variables , exp_data , callback , name = None ) : LM_Fitter . __init__ ( self , variables , exp_data , callback , name = None ) self . name = name self . varnames = varnames if type ( self . varnames ) is not types . ListType : self . varnames = self . varnames . split ( ',' ) self . labels = labels self . equation = equation self . guess = guess if variables == None : self . variables = [ 1.0 for i in self . varnames ] else : self . variables = variables self . setChangeVars ( ) def get_value ( self , variables , data_point ) : """Evaluate string equation""" try : x = data_point [ 0 ] except : x = data_point eq = self . equation for i in range ( len ( self . varnames ) ) : globals ( ) [ self . varnames [ i ] ] = variables [ i ] try : value = eval ( eq ) except Exception , e : value = 1.0 print e return value def guess_start ( self ) : """Guess start vals using provided strings in guess dict""" if self . guess == None : return guess = self . guess if type ( guess ) is not types . DictType : guess = eval ( guess ) x = [ i [ 0 ] for i in self . exp_data ] y = [ i [ 1 ] for i in self . exp_data ] for i in range ( len ( self . varnames ) ) : var = self . varnames [ i ] if var in guess : self . variables [ i ] = eval ( guess [ var ] ) return return tempfitter
Dynamically create an instance of LM_fitter class using presets
this function requires we pass varnames and equation at minimum
Dynamically create an instance of LM_fitter class using presets this function requires we pass varnames and equation at minimum
"""Dynamically create an instance of LM_fitter class using presets
       this function requires we pass varnames and equation at minimum""" """Evaluate string equation""" #print i, self.varnames[i],variables[i]  """Guess start vals using provided strings in guess dict""" #print guess #print  i, var, guess[var],self.variables[i]
equation
varnames
guess
name
labels