Diff of /trunk/escript/py_src/minimize.py

revision 865 by gross, Fri Oct 6 10:02:18 2006 UTC revision 1811 by ksteube, Thu Sep 25 23:11:13 2008 UTC
# Line 1  Line 1
1
2    ########################################################
3    #
4    # Copyright (c) 2003-2008 by University of Queensland
5    # Earth Systems Science Computational Center (ESSCC)
6    # http://www.uq.edu.au/esscc
7    #
8    # Primary Business: Queensland, Australia
11    #
12    ########################################################
13
15    Earth Systems Science Computational Center (ESSCC)
16    http://www.uq.edu.au/esscc
20    __url__="http://www.uq.edu.au/esscc/escript-finley"
21
22  # ******NOTICE***************  # ******NOTICE***************
23  # optimize.py module by Travis E. Oliphant  # optimize.py module by Travis E. Oliphant
24  #  #
# Line 14  A collection of general-purpose optimiza Line 35  A collection of general-purpose optimiza
35
36  fmin        ---      Nelder-Mead Simplex algorithm (uses only function calls)  fmin        ---      Nelder-Mead Simplex algorithm (uses only function calls)
37  fminBFGS    ---      Quasi-Newton method (uses function and gradient)  fminBFGS    ---      Quasi-Newton method (uses function and gradient)
38  fminNCG     ---      Line-search Newton Conjugate Gradient (uses function, gradient  fminNCG     ---      Line-search Newton Conjugate Gradient (uses function, gradient and hessian (if it's provided))
and hessian (if it's provided))
39
40  """  """
41  import numarray  import numarray
# Line 205  def zoom(a_lo, a_hi): Line 225  def zoom(a_lo, a_hi):
225
226
227  def line_search(f, fprime, xk, pk, gfk, args=(), c1=1e-4, c2=0.9, amax=50):  def line_search(f, fprime, xk, pk, gfk, args=(), c1=1e-4, c2=0.9, amax=50):
228      """alpha, fc, gc = line_search(f, xk, pk, gfk,      """alpha, fc, gc = line_search(f, xk, pk, gfk, args=(), c1=1e-4, c2=0.9, amax=1)
args=(), c1=1e-4, c2=0.9, amax=1)
229
230      minimize the function f(xk+alpha pk) using the line search algorithm of      minimize the function f(xk+alpha pk) using the line search algorithm of
231      Wright and Nocedal in 'numarrayerical Optimization', 1999, pg. 59-60      Wright and Nocedal in 'numarrayerical Optimization', 1999, pg. 59-60
# Line 256  def line_search(f, fprime, xk, pk, gfk, Line 275  def line_search(f, fprime, xk, pk, gfk,
275
276
277  def line_search_BFGS(f, xk, pk, gfk, args=(), c1=1e-4, alpha0=1):  def line_search_BFGS(f, xk, pk, gfk, args=(), c1=1e-4, alpha0=1):
278      """alpha, fc, gc = line_search(f, xk, pk, gfk,      """alpha, fc, gc = line_search(f, xk, pk, gfk, args=(), c1=1e-4, alpha0=1)
args=(), c1=1e-4, alpha0=1)
279
280      minimize over alpha, the function f(xk+alpha pk) using the interpolation      minimize over alpha, the function f(xk+alpha pk) using the interpolation
281      algorithm (Armiijo backtracking) as suggested by      algorithm (Armiijo backtracking) as suggested by
# Line 329  def approx_fhess_p(x0,p,fprime,*args): Line 347  def approx_fhess_p(x0,p,fprime,*args):
347
348
349  def fminBFGS(f, x0, fprime=None, args=(), avegtol=1e-5, maxiter=None, fulloutput=0, printmessg=1):  def fminBFGS(f, x0, fprime=None, args=(), avegtol=1e-5, maxiter=None, fulloutput=0, printmessg=1):
350      """xopt = fminBFGS(f, x0, fprime=None, args=(), avegtol=1e-5,      """xopt = fminBFGS(f, x0, fprime=None, args=(), avegtol=1e-5, maxiter=None, fulloutput=0, printmessg=1)
maxiter=None, fulloutput=0, printmessg=1)
351
352      Optimize the function, f, whose gradient is given by fprime using the      Optimize the function, f, whose gradient is given by fprime using the
353      quasi-Newton method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS)      quasi-Newton method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS)
# Line 410  def fminBFGS(f, x0, fprime=None, args=() Line 427  def fminBFGS(f, x0, fprime=None, args=()
427
428
429  def fminNCG(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, maxiter=None, fulloutput=0, printmessg=1):  def fminNCG(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, maxiter=None, fulloutput=0, printmessg=1):
430      """xopt = fminNCG(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5,      """xopt = fminNCG(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, maxiter=None, fulloutput=0, printmessg=1)
maxiter=None, fulloutput=0, printmessg=1)
431
432      Optimize the function, f, whose gradient is given by fprime using the      Optimize the function, f, whose gradient is given by fprime using the
433      Newton-CG method.  fhess_p must compute the hessian times an arbitrary      Newton-CG method.  fhess_p must compute the hessian times an arbitrary

Legend:
 Removed from v.865 changed lines Added in v.1811