source: sasview/park-1.2.1/park/parksnob.py @ f80236f

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 f80236f was 3570545, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Adding park Part 2

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"""
2"""
3from __future__ import division
4import thread
5import numpy
6
7from snobfit.snobfit import snobfit
8
9import fit,fitresult
10
11__all__ = ['Snobfit']
12
13class Snobfit(fit.Fitter):
14    """
15    Response surface optimizer
16
17    This implements `park.fit.Fitter`.
18    """
19
20    p=0.5
21    """Locality: 1.0 for completely global, 0. for local"""
22    dn=5
23    """Number of surplus points in quadratic fit; increase for noisy functions"""
24    maxiter=1000
25    """Maximum number of iterations"""
26    maxfun=1000
27    """Maximum number of function evaluations"""
28    nstop=50
29    """Number of times no improvement is tolerated"""
30
31    def _monitor(self, k, x, fx, improved):
32        self.handler.progress(k,self.maxiter)
33        if improved:
34            self.handler.result.update(x,fx,-1)
35            self.handler.improvement()
36
37    def _call_snobfit(self, objective, x0, bounds):
38        x,fx,calls = snobfit(objective, x0, bounds, fglob=0,
39                             callback=self._monitor)
40
41        # Post the result
42        self.handler.result.update(x, fx, calls)
43        self.handler.result.calc_cov(objective)
44        self.handler.done = True
45        self.handler.finalize()
46
47    def _fit(self, objective, x0, bounds):
48        self._threaded(self._call_snobfit, objective, x0, bounds)
49
50if __name__ == "__main__":
51    fit.demo2(fitter=Snobfit())
Note: See TracBrowser for help on using the repository browser.