Commits

Georg Brandl  committed 53dfa8e

models: fix problems with global fit

  • Participants
  • Parent commits 2aa0f45

Comments (0)

Files changed (1)

File ufit/models/base.py

 # ufit base models
 
+import re
 import inspect
 import operator
 import cPickle as pickle
 __all__ = ['Model', 'CombinedModel', 'Function', 'eval_model']
 
 
+data_re = r'\bdata\b'
+
 def eval_model(modeldef, paramdef=None):
     from ufit import models
     d = models.__dict__.copy()
     Parameters are extracted from the function's arguments and passed
     positionally.
     """
-    def __init__(self, fcn, name='', **init):
+    def __init__(self, fcn, name=None, **init):
         self._real_fcn = fcn
-        if not name and fcn.__name__ != '<lambda>':
-            name = fcn.__name__
+        if name is None:
+            if fcn.__name__ != '<lambda>':
+                name = fcn.__name__
+            else:
+                name = ''
         pvs = self._init_params(name, inspect.getargspec(fcn)[0][1:], init)
 
         self.fcn = lambda p, x: \
                     continue
                 for oldname0, p0 in dplist:
                     param.expr = param.expr.replace(oldname0, p0.name)
-                param.expr = param.expr.replace('data.', 'data.d%d.' % i)
+                param.expr = data_re.sub('data.d%d' % i, param.expr)
 
         # global fitting function: call model function once for each dataset
         # with the original data, with the parameter values taken from the
                     paramlist.append(p)
                 elif p.name.endswith(suffix):
                     clone_param = p.copy(p.name[:-len(suffix)])
-                    clone_param.expr = clone_param._orig_expr
+                    clone_param.expr = p._orig_expr
                     paramlist.append(clone_param)
             chi2 = get_chisqr(self._model.fcn, data.x, data.y, data.dy, paramlist)
             reslist.append(Result(overall_res.success, data, self._model,