Changeset 160


Ignore:
Timestamp:
08/02/09 21:14:05 (7 years ago)
Author:
altafang
Message:

Adding Newton-CG solver and making some edits to other solvers

Location:
branches/alta/mystic-0.1a2
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/alta/mystic-0.1a2/examples/test_bfgs.py

    r159 r160  
    33""" 
    44Example: 
    5     - Minimize simple test functions using BFGS optimization. 
     5    - Minimize the Rosenbrock function using BFGS optimization. 
    66 
    77Demonstrates: 
     
    3939    print 
    4040    print "Using BFGS Quasi-Newton:" 
    41     y = fmin_bfgs(rosen, x0, fprime=rosen_der, gtol=1e-4, maxiter=100) 
    42     print y 
     41    x = fmin_bfgs(rosen, x0, fprime=rosen_der, gtol=1e-4, maxiter=100) 
     42    print x 
  • branches/alta/mystic-0.1a2/mystic/anneal_solver.py

    r158 r160  
    4040Adapted for Mystic, 2009 
    4141""" 
     42 
     43__all__ = ['AnnealSolver','anneal'] 
    4244 
    4345# Mystic and numpy imports 
     
    200202    def __init__(self, dim): 
    201203        """ 
    202 Takes two initial inputs:  
     204Takes one initial input:  
    203205    dim  -- dimensionality of the problem 
    204206 
  • branches/alta/mystic-0.1a2/mystic/scipy_bfgs.py

    r159 r160  
    336336    def __init__(self, dim): 
    337337        """ 
    338 Takes two initial inputs:  
     338Takes one initial input:  
    339339    dim  -- dimensionality of the problem 
    340340 
     
    345345    def Solve(self, func, sigint_callback=None, 
    346346              EvaluationMonitor=Null, StepMonitor=Null, GradMonitor=Null, 
    347               InvHessianMonitor=Null, ExtraArgs=((), ()), **kwds): 
     347              InvHessianMonitor=Null, ExtraArgs=(), **kwds): 
    348348        """Minimize a function using BFGS. 
    349349 
     
    366366    GradMonitor -- Monitors the gradient.  
    367367    InvHessianMonitor -- Monitors the inverse Hessian.  
    368     ExtraArgs -- extra arguments for func and fprime. 
     368    ExtraArgs -- extra arguments for func and fprime (same for both) 
    369369 
    370370Further Inputs: 
     
    405405        self._EARLYEXIT = False 
    406406 
    407         fcalls, func = wrap_function(func, args[0], EvaluationMonitor) 
     407        fcalls, func = wrap_function(func, args, EvaluationMonitor) 
    408408        if self._useStrictRange: 
    409409            x0 = self._clipGuessWithinRangeBoundary(x0) 
     
    426426            gcalls, myfprime = wrap_function(approx_fprime, (func, epsilon), GradMonitor) 
    427427        else: 
    428             gcalls, myfprime = wrap_function(fprime, args[1], GradMonitor) 
     428            gcalls, myfprime = wrap_function(fprime, args, GradMonitor) 
    429429 
    430430        gfk = myfprime(x0) 
     
    442442        while (gnorm > gtol) and (k < self._maxiter): 
    443443            pk = -numpy.dot(Hk,gfk) 
     444 
    444445       #     alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \ 
    445446       #        linesearch.line_search(func,myfprime,xk,pk,gfk, 
     
    447448       # how do I get linesearch.line_search? it is in scipy, but  
    448449       # requires minpack2.so.... 
     450 
    449451            # temporary fix: 
    450452            alpha_k = None 
     
    531533# Interface for using BFGSSolver 
    532534 
    533 def fmin_bfgs(func, x0, fprime=None, args=((),()), gtol=1e-5, norm=Inf, 
     535def fmin_bfgs(func, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, 
    534536              epsilon=_epsilon, maxiter=None, full_output=0, disp=1, 
    535537              retall=0, callback=None): 
     
    547549      fprime : callable f'(x,*args) 
    548550          Gradient of f. 
    549       args : tuple of tuples 
    550           Extra arguments passed to f and fprime. 
     551      args : tuple 
     552          Extra arguments passed to f and fprime (same to both) 
    551553      gtol : float 
    552554          Gradient norm must be less than gtol before successful termination. 
     
    585587        warnflag : integer 
    586588            1 : Maximum number of iterations exceeded. 
    587             2 : Gradient and/or function calls not changing. 
    588589        allvecs  :  list 
    589590            Results at each iteration.  Only returned if retall is True. 
     
    622623    Hk = invhessianmon.y[-1] 
    623624 
    624     if fcalls >= solver._maxfun: 
     625    if iterations >= solver._maxiter: 
    625626        warnflag = 1 
    626     elif iterations >= solver._maxiter: 
    627         warnflag = 2 
    628627 
    629628    if full_output: 
  • branches/alta/mystic-0.1a2/mystic/snobfit_solver.py

    r158 r160  
    5252Adapted to Mystic 7/2009 -- Alta Fang 
    5353""" 
     54 
     55__all__ = ['SnobfitSolver','snobfit'] 
    5456 
    5557# Snobfit imports 
Note: See TracChangeset for help on using the changeset viewer.