Changeset 1538

Show
Ignore:
Timestamp:
10/12/08 09:41:51 (2 months ago)
Author:
dmitrey.kroshko
Message:

minor updates for speedup.py description

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openopt/scikits/openopt/examples/oofun/speedup.py

    r1536 r1538  
    44even for unconstrained functions. 
    55 
     6The speedup is due to changes in derivatives numerical approximation approach: 
     7instead of handling whole dF/dx = d(g(f))/dx 
     8we find dg/df, df/dx and 
     9dF/dx = dg/df * df/dx 
     10 
     11Here's example of unconstrained problem, but constrained ones can be used as well 
     12for NLP, NSP, NLSP, LSP classes 
     13 
    614Concider the NL problem 
    715g(f(x)) -> min 
    816g is costly and g derivative are not available 
    917f(x) = (x[0]-0)^2 + (x[1]-1)^2 + ... + (x[N-1]-(N-1))^2 
    10 see below for declaration g (R -> R) 
     18see below for definition of g 
     19here I have chosed g: R -> R for the sake of simplicity, 
     20but R^m -> R^k can be handled as well 
    1121""" 
    1222def CostlyFunction(z): 
     
    3646g = oofun(CostlyFunction, input = ff) 
    3747p = NLP(g, maxIter=1e4, iprint=iprint, ftol=ftol, xtol=xtol, gtol=gtol) 
     48print 'using oofun:' 
    3849r = p.solve(solver) 
    39 print 'evals f: ', counter['f'], 'evals of costly func g:', counter['g'] 
     50print 'evals f:', counter['f'], '  evals of costly func g:', counter['g'] 
    4051"""                               2: classic                                  """ 
    4152counter = {'f':0, 'g':0} 
    4253g = CostlyFunction 
    4354p = NLP(lambda x: g(f(x)), x0=zeros(N), maxIter=1e4, ftol=ftol, xtol=xtol, gtol=gtol, iprint=iprint) 
     55print '\nwithout oofun:' 
    4456r = p.solve(solver) 
    45 print 'evals f: ', counter['f'], 'evals of costly func g:', counter['g'] 
     57print 'evals f:', counter['f'], '  evals of costly func g:', counter['g'] 
    4658""" 
    47 My computer output
     59using oofun
    4860----------------------------------------------------- 
    4961solver: scipy_ncg   problem: unnamed   goal: minimum 
     
    5870   31  4.862e+02 
    5971istop:  1000 
    60 Solver:   Time Elapsed = 1.59  CPU Time Elapsed = 1.52 
     72Solver:   Time Elapsed = 1.51  CPU Time Elapsed = 1.49 
    6173objFunValue: 486.20891 
    62 evals f:  17887 evals of costly func g: 305 
     74evals f: 17887   evals of costly func g: 305 
     75 
     76without oofun: 
    6377----------------------------------------------------- 
    6478solver: scipy_ncg   problem: unnamed   goal: minimum 
     
    7286   27  4.861e+02 
    7387istop:  1000 
    74 Solver:   Time Elapsed = 14.86         CPU Time Elapsed = 14.26 
     88Solver:   Time Elapsed = 15.09         CPU Time Elapsed = 14.29 
    7589objFunValue: 486.07635 
    76 evals f: 13660 evals of costly func g: 13660 
     90evals f: 13660  evals of costly func g: 13660 
    7791"""