1. Georg Brandl
  2. ufit

Commits

Georg Brandl  committed 1bc3f5d

model: add multi_fit

  • Participants
  • Parent commits 3365f37
  • Branches default

Comments (0)

Files changed (2)

File ufit/models/base.py

View file
 from numpy import concatenate
 
 from ufit import param, backends, UFitError, Param, Dataset
-from ufit.result import Result, GlobalResult
+from ufit.result import Result, MultiResult
 from ufit.utils import get_chisqr, cached_property
 from ufit.plotting import DataPlotter
 
         """
         return GlobalModel(self, datas).fit(datas, **kw)
 
+    def multi_fit(self, datas, **kw):
+        results = []
+        for data in datas:
+            self.reset()
+            results.append(self.fit(data, **kw))
+        return MultiResult(results)
+
     def reset(self):
         if self._orig_params is not None:
             self.params = [p.copy() for p in self._orig_params]
             chi2 = get_chisqr(self._model.fcn, data.x, data.y, data.dy, paramlist)
             reslist.append(Result(overall_res.success, data, self._model,
                                   paramlist, overall_res.message, chi2))
-        return GlobalResult(reslist)
+        return MultiResult(reslist)

File ufit/result.py

View file
 
     @cached_property
     def paramdict(self):
+        """Returns a dictionary mapping parameter names to parameter objects."""
         return dict((p.name, p) for p in self.params)
 
     @cached_property
     def paramvalues(self):
+        """Returns a dictionary mapping parameter names to values."""
+        return dict((p.name, p.value) for p in self.params)
+
+    @cached_property
+    def paramerrors(self):
+        """Returns a dictionary mapping parameter names to errors."""
         return dict((p.name, p.value) for p in self.params)
 
     @cached_property
     def values(self):
+        """Returns a list with all parameter values."""
         return [p.value for p in self.params]
 
     @cached_property
     def errors(self):
+        """Returns a list with all parameter errors."""
         return [p.error for p in self.params]
 
     @cached_property
+    def results(self):
+        """Returns a list with the parameter values, then the parameter errors
+        and the chi-square value concatenated.
+        """
+        return self.values + self.errors + [self.chisqr]
+
+    @cached_property
     def residuals(self):
+        """Returns the array of residuals."""
         return self.model.fcn(self.paramvalues, self.data.x) - self.data.y
 
     @cached_property
     def xx(self):
-        return linspace(self.data.x[0], self.data.x[-1], 1000)
+        """Returns a fine-spaced array of X values between the minimum and maximum
+        of the original data X values.
+        """
+        return linspace(self.data.x.min(), self.data.x.max(), 1000)
 
     @cached_property
     def yy(self):
+        """Returns the model evaluated at self.xx."""
         return self.model.fcn(self.paramvalues, self.xx)
 
     def printout(self):
     return num//10 + 1, 10
 
 
-class GlobalResult(list):
+class MultiResult(list):
     def plot(self):
         dims = calc_panel_size(len(self))
         fig, axarray = pl.subplots(dims[1], dims[0])