source: sasview/park-1.2.1/park/parkde.py @ 0d417ac8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0d417ac8 was 3570545, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Adding park Part 2

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"""
2"""
3from __future__ import division
4import thread
5import numpy
6
7import diffev
8
9import fit,fitresult
10
11__all__ = ['DiffEv']
12
13class DiffEv(fit.Fitter):
14    """
15    Differential evolution optimizer
16
17    This implements `park.fit.Fitter`.
18    """
19
20    maxiter=1000
21    """Maximum number of iterations"""
22    pop_scale=4
23    """Number of active points per dimension"""
24    crossover_rate=0.9
25    """Amount of mixing in population"""
26    Fscale=0.5
27    """Step size along difference vector"""
28    tolerance=1e-5
29    """Fit tolerance"""
30
31    def progress(self, k, n):
32        self.handler.progress(k,n)
33    def improvement(self, x, fx, ncalls=-1):
34        self.handler.result.update(x,fx,-1)
35        self.handler.improvement()
36
37    def _call(self, objective, x0, bounds):
38        x,fx,calls = diffev.diffev(objective, bounds,
39                                   maxiter=self.maxiter,
40                                   pop_scale=self.pop_scale,
41                                   crossover_rate=self.crossover_rate,
42                                   Fscale=self.Fscale,
43                                   tolerance=self.tolerance,
44                                   x0=x0, monitor=self)
45
46        # Post the result
47        self.handler.result.update(x, fx, calls)
48        self.handler.result.calc_cov(objective)
49        self.handler.done = True
50        self.handler.finalize()
51
52    def _fit(self, objective, x0, bounds):
53        self._threaded(self._call, objective, x0, bounds)
54
55if __name__ == "__main__":
56    fit.demo2(fitter=DiffEv())
Note: See TracBrowser for help on using the repository browser.