source: mystic/examples/example05.py @ 855

Revision 855, 1.1 KB checked in by mmckerns, 5 months ago (diff)

updated copyright to 2016

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4# Copyright (c) 1997-2016 California Institute of Technology.
5# License: 3-clause BSD.  The full license text is available at:
6#  - http://trac.mystic.cacr.caltech.edu/project/mystic/browser/mystic/LICENSE
7"""
8Example:
9    - Minimize Rosenbrock's Function with Powell's method.
10    - Dynamic print of parameter convergence to function minimum.
11
12Demonstrates:
13    - standard models
14    - minimal solver interface
15    - parameter trajectories using callback
16"""
17
18# Powell's Directonal solver
19from mystic.solvers import fmin_powell
20
21# Rosenbrock function
22from mystic.models import rosen
23
24iter = 0
25# plot the parameter trajectories
26def print_params(params):
27    global iter
28    from numpy import asarray
29    print "Generation %d has best fit parameters: %s" % (iter,asarray(params))
30    iter += 1
31    return
32
33
34if __name__ == '__main__':
35
36    # initial guess
37    x0 = [0.8,1.2,0.7]
38    print_params(x0)
39
40    # use Powell's method to minimize the Rosenbrock function
41    solution = fmin_powell(rosen,x0,disp=1,callback=print_params,handler=True)
42    print solution
43
44# end of file
Note: See TracBrowser for help on using the repository browser.