Changeset 904
- Timestamp:
- 03/15/08 03:09:13 (9 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/BaseProblem.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/ooCheck.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/ooCheckGradient.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/runProbSolver.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/examples/checkDerivatives.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/examples/lsp_1.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/examples/nlp_1.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/examples/nlp_ALGENCAN.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/Standalone/bvls_oo.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r884 r904 8 8 from Residuals import Residuals 9 9 from ooIter import ooIter 10 10 from ooCheckGradient import ooCheckGradient 11 11 ProbDefaults = {'diffInt': 1e-7, 'xtol': 1e-6, 'noise': 0} 12 12 … … 254 254 self.err('OpenOpt error: this function should be overdetermined by child class') 255 255 256 257 258 259 260 261 262 256 def checkdf(self, x=None): 257 return ooCheckGradient(self, 'df', x) 258 259 def checkdc(self, x=None): 260 return ooCheckGradient(self, 'dc', x) 261 262 def checkdh(self, x=None): 263 return ooCheckGradient(self, 'dh', x) 264 265 def __makeCorrectArgs__(self): 266 argslist = dir(self.args) 267 if not ('f' in argslist and 'c' in argslist and 'h' in argslist): 268 tmp, self.args = self.args, autocreate() 269 self.args.f = self.args.c = self.args.h = tmp 270 for j in ('f', 'c', 'h'): 271 v = getattr(self.args, j) 272 if type(v) != type(()): setattr(self.args, j, (v,)) 273 trunk/openopt/scikits/openopt/Kernel/ooCheck.py
r701 r904 15 15 p.err('the solver ' + p.solverName + ' cannot handle ' + "'" + fn + "' constraints") 16 16 17 separator='========================'18 19 17 for fn in ('df', 'dc', 'dh'): 20 nothing2checkMsg = 'you must provide gradient for check or turn option prob.check.' + fn + ' off'21 isSomething2Check = 022 18 if getattr(p.check, fn): 23 if hasattr(p.user, fn): 24 for j in getattr(p.user, fn): 25 if callable(j): isSomething2Check = 1 26 if isSomething2Check: ooCheckGradient(p, fn) 27 else: p.warn(nothing2checkMsg) 19 p.info('the option p.check.'+fn+' is obsolete, use p.check'+fn+'() or p.check'+fn+'(x) instead') 20 21 # separator='========================' 22 # 23 # for fn in ('df', 'dc', 'dh'): 24 # nothing2checkMsg = 'you must provide gradient for check or turn option prob.check.' + fn + ' off' 25 # isSomething2Check = 0 26 # if getattr(p.check, fn): 27 # if hasattr(p.user, fn): 28 # for j in getattr(p.user, fn): 29 # if callable(j): isSomething2Check = 1 30 # if isSomething2Check: ooCheckGradient(p, fn) 31 # else: p.warn(nothing2checkMsg) 28 32 29 33 return nErrors trunk/openopt/scikits/openopt/Kernel/ooCheckGradient.py
r806 r904 1 from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs 1 from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs, array 2 2 from string import rjust, ljust 3 #from objFunRelated import objFunRelated 3 class autocreate: 4 def __init__(self):pass 5 6 4 7 def ooCheckGradient(p, fun_, xCheck=None, separator='========================'): 5 8 """ … … 11 14 else: singleColumn, doubleColumn = [], ['df', 'dc', 'dh'] 12 15 16 x0 = p.x0 17 p.x0 = array(p.x0, float) 13 18 if xCheck is None: xCheck = p.x0 19 14 20 nskiplines = 0 15 21 16 if not getattr(p.userProvided, fun_): 17 p.err("check gradient for complex user-gradient func isn't implemented yet") 22 if not getattr(p, fun_): 23 p.warn('you must provide gradient for check ' + fn+'. Turning the option off') 24 return 25 26 genericUserFunc1 = getattr(p, fun_) # df, dc, dh 27 genericUserFunc2 = getattr(p, fun_[1:]) # f, c, h 28 29 setattr(p, 'nEvals', autocreate()) 30 setattr(p.nEvals, fun_[1:], 0) 31 setattr(p.nEvals, fun_, 0) 32 33 #for genericUserFunc in [genericUserFunc1, genericUserFunc2]: 34 for fn in [fun_[1:], fun_]: 35 genericUserFunc = getattr(p, fn) 36 if type(genericUserFunc) in [list, tuple]: 37 setattr(p.user, fn, genericUserFunc) 38 else: 39 setattr(p.user, fn, [genericUserFunc]) 40 setattr(p, fn, getattr(p, 'user_' + fn)) 41 42 diffInt = p.diffInt 43 if type(p.diffInt) not in [list, tuple]: 44 p.diffInt = [p.diffInt] 45 46 p.__makeCorrectArgs__() 18 47 19 48 setattr(p.userProvided, fun_, False) … … 72 101 73 102 print(separator) 103 104 delattr(p.user, fun_) 105 delattr(p.user, fun_[1:]) 106 setattr(p, fun_, genericUserFunc1) # df, dc, dh 107 setattr(p, fun_[1:], genericUserFunc2) # f, c, h 108 p.diffInt = diffInt 109 p.x0 = x0 110 74 111 return counter 75 112 trunk/openopt/scikits/openopt/Kernel/runProbSolver.py
r900 r904 62 62 if p.graphics.xlabel == 'nf': p.iterValues.nf = [] # iter ObjFunc evaluation number 63 63 64 argslist = dir(p.args) 65 if not ('f' in argslist and 'c' in argslist and 'h' in argslist): 66 tmp, p.args = p.args, EmptyClass() 67 p.args.f = p.args.c = p.args.h = tmp 68 for j in ('f', 'c', 'h'): 69 v = getattr(p.args, j) 70 if type(v) != type(()): setattr(p.args, j, (v,)) 64 p.__makeCorrectArgs__() 71 65 72 66 if p.probType in ('LP', 'MILP', 'QP') and p.plot: … … 168 162 #assert hasattr(p, 'xk') or hasattr(p, 'xf') 169 163 if not hasattr(p, 'xf') or all(p.xf==nan): p.xf = p.xk 170 if not hasattr(p, 'ff') or p.ff==nan: p.ff = p.fk164 if not hasattr(p, 'ff') or any(p.ff==nan): p.ff = p.fk 171 165 if p.probType in ['NLP', 'NSP', 'GNLP']:#TODO:handle it more correctly 172 166 if not hasattr(p, 'fk'): p.fk = p.f(p.xk) trunk/openopt/scikits/openopt/examples/checkDerivatives.py
r613 r904 34 34 p.dh = dh 35 35 36 p.check.df=1 37 p.check.dc=1 38 p.check.dh=1 39 #!! fmin_cobyla can't use user-supplied gradient 40 # but OpenOpt will do derivatives check anyway 41 r = p.solve('scipy_cobyla') 36 p.checkdf() 37 p.checkdc() 38 p.checkdh() 39 # you can use p.checkdF(x) for other point than x0 (F is f, c or h) 42 40 43 41 # if you'll use solvers that use derivatives, 44 42 # they will hardly converge to feasible point 45 43 # because of the bugs in calculating derivatives made: 46 # r = p.solve('lincher') 47 # r = p.solve('ALGENCAN') 44 # r = p.solve('ralg') 48 45 49 46 """ … … 82 79 sum(abs(dh_user - dh_numerical)) = 15.0000144464 83 80 ======================== 84 starting solver scipy_cobyla (BSD license) with problem unnamed85 solver scipy_cobyla has finished solving the problem unnamed86 istop: 100087 Solver: Time Elapsed = 1.01 CPU Time Elapsed = 0.9488 objFunValue: 55.8770221887 (feasible, max constraint = 1.24892e-21)89 81 """ trunk/openopt/scikits/openopt/examples/lsp_1.py
r763 r904 41 41 42 42 #optional: user-supplied gradient check: 43 p.check .df = 143 p.checkdf() 44 44 45 45 #optional: graphical output, requires matplotlib installed trunk/openopt/scikits/openopt/examples/nlp_1.py
r771 r904 95 95 96 96 #optional: user-supplied 1st derivatives check 97 p.check.df=1 98 p.check.dc=1 99 p.check.dh=1 97 p.checkdf() 98 p.checkdc() 99 p.checkdh() 100 100 101 101 102 p.maxIter = 10000 … … 107 108 108 109 #r = p.solve('ALGENCAN') 109 r = p.solve('ralg') 110 #r = p.solve('ralg') 111 r = p.solve('lincher') 110 112 ##p.iprint = 1 111 113 ##p.plot = 0 trunk/openopt/scikits/openopt/examples/nlp_ALGENCAN.py
r710 r904 99 99 100 100 # optional: check of user-supplied derivatives 101 p.check .df = 1102 p.check .dc = 1103 p.check .dh = 1101 p.checkdf() 102 p.checkdc() 103 p.checkdh() 104 104 105 105 # last but not least: trunk/openopt/scikits/openopt/solvers/Standalone/bvls_oo.py
r899 r904 5 5 import bvls as BVLS 6 6 except: 7 print 'You should have bvls.f compiled via f2py, see OO LLSP doc webpage for details' 7 from oologfcn import OpenOptException 8 raise OpenOptException('You should have bvls.f compiled via f2py, see OO LLSP doc webpage for details') 8 9 9 10 class bvls(BaseAlg):
