source: mystic/examples/example03.py @ 855

Revision 855, 1.2 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://mmckerns.github.io/project/mystic/browser/mystic/LICENSE
7"""
8Example:
9    - Minimize Rosenbrock's Function with Nelder-Mead.
10    - Plot of parameter convergence to function minimum.
11
12Demonstrates:
13    - standard models
14    - minimal solver interface
15    - parameter trajectories using retall
16"""
17
18# Nelder-Mead solver
19from mystic.solvers import fmin
20
21# Rosenbrock function
22from mystic.models import rosen
23
24# tools
25import pylab
26
27
28if __name__ == '__main__':
29
30    # initial guess
31    x0 = [0.8,1.2,0.7]
32
33    # use Nelder-Mead to minimize the Rosenbrock function
34    solution = fmin(rosen,x0,disp=0,retall=1)
35    allvecs = solution[-1]
36
37    # plot the parameter trajectories
38    pylab.plot([i[0] for i in allvecs])
39    pylab.plot([i[1] for i in allvecs])
40    pylab.plot([i[2] for i in allvecs])
41
42    # draw the plot
43    pylab.title("Rosenbrock parameter convergence")
44    pylab.xlabel("Nelder-Mead solver iterations")
45    pylab.ylabel("parameter value")
46    pylab.legend(["x", "y", "z"])
47    pylab.show()
48 
49# end of file
Note: See TracBrowser for help on using the repository browser.