Changeset 1538
- Timestamp:
- 10/12/08 09:41:51 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/examples/oofun/speedup.py
r1536 r1538 4 4 even for unconstrained functions. 5 5 6 The speedup is due to changes in derivatives numerical approximation approach: 7 instead of handling whole dF/dx = d(g(f))/dx 8 we find dg/df, df/dx and 9 dF/dx = dg/df * df/dx 10 11 Here's example of unconstrained problem, but constrained ones can be used as well 12 for NLP, NSP, NLSP, LSP classes 13 6 14 Concider the NL problem 7 15 g(f(x)) -> min 8 16 g is costly and g derivative are not available 9 17 f(x) = (x[0]-0)^2 + (x[1]-1)^2 + ... + (x[N-1]-(N-1))^2 10 see below for declaration g (R -> R) 18 see below for definition of g 19 here I have chosed g: R -> R for the sake of simplicity, 20 but R^m -> R^k can be handled as well 11 21 """ 12 22 def CostlyFunction(z): … … 36 46 g = oofun(CostlyFunction, input = ff) 37 47 p = NLP(g, maxIter=1e4, iprint=iprint, ftol=ftol, xtol=xtol, gtol=gtol) 48 print 'using oofun:' 38 49 r = p.solve(solver) 39 print 'evals f: ', counter['f'], 'evals of costly func g:', counter['g']50 print 'evals f:', counter['f'], ' evals of costly func g:', counter['g'] 40 51 """ 2: classic """ 41 52 counter = {'f':0, 'g':0} 42 53 g = CostlyFunction 43 54 p = NLP(lambda x: g(f(x)), x0=zeros(N), maxIter=1e4, ftol=ftol, xtol=xtol, gtol=gtol, iprint=iprint) 55 print '\nwithout oofun:' 44 56 r = p.solve(solver) 45 print 'evals f: ', counter['f'], 'evals of costly func g:', counter['g']57 print 'evals f:', counter['f'], ' evals of costly func g:', counter['g'] 46 58 """ 47 My computer output:59 using oofun: 48 60 ----------------------------------------------------- 49 61 solver: scipy_ncg problem: unnamed goal: minimum … … 58 70 31 4.862e+02 59 71 istop: 1000 60 Solver: Time Elapsed = 1.5 9 CPU Time Elapsed = 1.5272 Solver: Time Elapsed = 1.51 CPU Time Elapsed = 1.49 61 73 objFunValue: 486.20891 62 evals f: 17887 evals of costly func g: 305 74 evals f: 17887 evals of costly func g: 305 75 76 without oofun: 63 77 ----------------------------------------------------- 64 78 solver: scipy_ncg problem: unnamed goal: minimum … … 72 86 27 4.861e+02 73 87 istop: 1000 74 Solver: Time Elapsed = 1 4.86 CPU Time Elapsed = 14.2688 Solver: Time Elapsed = 15.09 CPU Time Elapsed = 14.29 75 89 objFunValue: 486.07635 76 evals f: 13660evals of costly func g: 1366090 evals f: 13660 evals of costly func g: 13660 77 91 """
