Changeset 905
- Timestamp:
- 03/15/08 03:57:42 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r904 r905 254 254 self.err('OpenOpt error: this function should be overdetermined by child class') 255 255 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)256 def checkdf(self, *args, **kwargs): 257 return ooCheckGradient(self, 'df', *args, **kwargs) 258 259 def checkdc(self, *args, **kwargs): 260 return ooCheckGradient(self, 'dc', *args, **kwargs) 261 262 def checkdh(self, *args, **kwargs): 263 return ooCheckGradient(self, 'dh', *args, **kwargs) 264 264 265 265 def __makeCorrectArgs__(self): trunk/openopt/scikits/openopt/Kernel/ooCheckGradient.py
r904 r905 1 from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs, a rray1 from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs, asfarray 2 2 from string import rjust, ljust 3 3 class autocreate: … … 5 5 6 6 7 def ooCheckGradient(p, fun_, xCheck=None, separator='========================'): 7 #def ooCheckGradient(p, fun_, xCheck=None, separator='========================'): 8 def ooCheckGradient(p, fun_, *args, **kwargs): 8 9 """ 9 10 fun_ is string name like 'df', 'dc', 'dh' … … 11 12 lately I intend to fix the problem. // D. 12 13 """ 14 x0 = p.x0 15 p.x0 = asfarray(p.x0) 16 17 if len(args)>0: 18 if len(args)>1 or kwargs.has_key('x'): 19 p.err('checkd<func> funcs can have single argument x only (then x should be absent in kwargs )') 20 xCheck = asfarray(args[0]) 21 elif kwargs.has_key('x'): 22 xCheck = asfarray(kwargs['x']) 23 else: 24 xCheck = asfarray(p.x0) 25 26 for fn in kwargs.keys(): 27 setattr(p.check, fn, kwargs[fn]) 28 29 separator='========================' 30 13 31 if p.isObjFunValueASingleNumber: singleColumn, doubleColumn = ['df'] , ['dc', 'dh'] 14 32 else: singleColumn, doubleColumn = [], ['df', 'dc', 'dh'] 15 33 16 x0 = p.x0 17 p.x0 = array(p.x0, float) 18 if xCheck is None: xCheck = p.x0 34 19 35 20 36 nskiplines = 0 … … 65 81 print('according to:') 66 82 print('prob.diffInt = ' + str(p.diffInt))#TODO: ADD other parameters: allowed epsilon, maxDiffLines etc 67 print(' prob.check.maxViolation = '+ str(p.check.maxViolation))83 print('values greater than maxViolation = '+ str(p.check.maxViolation) + ' will be shown') 68 84 69 85 if (abs(Diff) >= p.check.maxViolation).any(): … … 109 125 p.x0 = x0 110 126 111 return counter127 #return counter 112 128 113 129 trunk/openopt/scikits/openopt/examples/checkDerivatives.py
r904 r905 37 37 p.checkdc() 38 38 p.checkdh() 39 # you can use p.checkdF(x) for other point than x0 (F is f, c or h) 39 """ 40 you can use p.checkdF(x) for other point than x0 (F is f, c or h) 41 p.checkdc(myX) 42 or 43 p.checkdc(x=myX) 44 values with difference greater than 45 maxViolation (default 1e-5) 46 will be shown 47 p.checkdh(maxViolation=1e-4) 48 p.checkdh(myX, maxViolation=1e-4) 49 p.checkdh(x=myX, maxViolation=1e-4) 50 """ 51 40 52 41 53 # if you'll use solvers that use derivatives,
