1 | """ |
---|
2 | """ |
---|
3 | from __future__ import division |
---|
4 | import thread |
---|
5 | import numpy |
---|
6 | |
---|
7 | from snobfit.snobfit import snobfit |
---|
8 | |
---|
9 | import fit,fitresult |
---|
10 | |
---|
11 | __all__ = ['Snobfit'] |
---|
12 | |
---|
13 | class 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 | |
---|
50 | if __name__ == "__main__": |
---|
51 | fit.demo2(fitter=Snobfit()) |
---|