Package boxmin :: Package tests :: Module FitParameters
[hide private]

Source Code for Module boxmin.tests.FitParameters

  1  # This program is public domain. 
  2   
  3  ## \file 
  4  #  \brief Parameter management class for box constrained fitting 
  5  # 
  6   
7 -class FitParameters:
8 """ 9 class FitParameters 10 11 A fitting engine adjusts parameters to find a minimum value. The user 12 will want to guide the fit by fixing some of the parameters at a 13 specific value or to a specific range. The fit application will need 14 to switch easily between different parameter sets, e.g., to keep hold 15 of the current best parameters while restarting the fit at a different 16 point, so the fit parameters must be stored separately from the model 17 structure. 18 19 By allowing simple expressions instead of just values for fit 20 parameters users can create sophisticated derived models with no 21 programming effort. This includes simultaneous fitting of related 22 models, with the parameters for dependent models computed from the 23 values in the base model. Some care will be required when updating 24 the results. Much like a spreadsheet, an expression must be evaluated 25 before any of the expressions which depend on it, and cycles must be 26 avoided. A cell reference such as model.parameter[index] would work 27 automatically in python with the appropriate dictionary. Rather than 28 hardcoding index numbers, using a variable such as i to represent 29 the current index would be convenient, making it easy to copy a 30 formula from cell to cell. 31 32 Consider allowing expressions for upper and lower bounds as well in a 33 later release. In the current implementation of genetic algorithms 34 changing the bounds is an expensive operation because the variables 35 are mapped into the range [0,1], so any time the bounds change the 36 entire population needs to be remapped. 37 38 To keep its programming interface simple, the fitting engine will see 39 the fit parameters as contiguous arrays of values and bounds. 40 Normally this will require shuffling parameters between the fit and 41 the model. In cases were speed is critical, the model can operate 42 directly off the fitting engine parameters with no copying required. 43 A choice between [v lo hi v lo hi ...], [v v ...] [lo hi lo hi ...], 44 and [v v ...] [lo lo ...] [hi hi ...] must be made for the interface 45 to the fitting engine. Locality of reference favours the first while 46 programming flexibility favours the last. 47 48 The user needs to be able to save and restore the entire state of the 49 fit. A extensible text format such as XML will be used, with each 50 model component stored in a different section with tag identifying the 51 type of model. The application will be responsible for saving and 52 restoring the model, presumably delegating to the various model 53 components which make up the fit for converting to and from their own 54 representation in the model file. Saving and restoring information 55 the actual model values, the expressions, which parameters are varying 56 and the user specified bounds on all parameters is the responsibility 57 of fit parameter object. 58 59 Global parameters not associated with any particular model can be added 60 to a generic model and referenced as any other external model. 61 """ 62
63 - def add(self,model):
64 """Add a model to the fit""" 65 self.model.append(model) 66 return
67
68 - def title(self,n=None):
69 """Return title for model n or for the whole fit""" 70 if n == None: t = self.fit_title 71 else: t = self.model[n].title() 72 return t
73
74 - def tip(self,n=None):
75 """Return tip for model n or for the whole fit""" 76 if n == None: t = self.fit_tip 77 else: t = self.model[n].tip() 78 return t
79
80 - def __init__(self,title,tip=None):
81 """Construct a set of fit parameters""" 82 self.fit_title=title 83 self.fit_tip = tip 84 # Start of with an always available 85 self.model = [ ModelParameters('V','virtual parameters') ] 86 self.value = [] 87 self.bounds = [] 88 self.fixed = [] 89 return
90
91 - def _count_varying(self):
92 pass
93
94 - def _generate(self):
95 pass
96 97 98 # version 99 __id__ = "$Id: FitParameters.py 70 2008-11-18 00:10:29Z pkienzle $" 100 101 # End of file 102