Changeset 905

Show
Ignore:
Timestamp:
03/15/08 03:57:42 (9 months ago)
Author:
dmitrey.kroshko
Message:

some changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openopt/scikits/openopt/Kernel/BaseProblem.py

    r904 r905  
    254254        self.err('OpenOpt error: this function should be overdetermined by child class') 
    255255     
    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
    264264     
    265265    def __makeCorrectArgs__(self): 
  • trunk/openopt/scikits/openopt/Kernel/ooCheckGradient.py

    r904 r905  
    1 from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs, array 
     1from numpy import hstack, ceil, floor, log10, inf, tile, argmax, abs, asfarray 
    22from string import rjust, ljust 
    33class autocreate: 
     
    55 
    66 
    7 def ooCheckGradient(p, fun_, xCheck=None, separator='========================'): 
     7#def ooCheckGradient(p, fun_, xCheck=None, separator='========================'): 
     8def ooCheckGradient(p, fun_, *args, **kwargs):     
    89    """ 
    910    fun_ is string name like 'df', 'dc', 'dh' 
     
    1112    lately I intend to fix the problem. // D. 
    1213    """ 
     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     
    1331    if p.isObjFunValueASingleNumber: singleColumn, doubleColumn = ['df'] , ['dc', 'dh'] 
    1432    else: singleColumn, doubleColumn = [], ['df', 'dc', 'dh'] 
    1533     
    16     x0 = p.x0 
    17     p.x0 = array(p.x0, float) 
    18     if xCheck is None: xCheck = p.x0 
     34     
    1935         
    2036    nskiplines = 0 
     
    6581    print('according to:') 
    6682    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'
    6884     
    6985    if (abs(Diff) >= p.check.maxViolation).any(): 
     
    109125    p.x0 = x0 
    110126 
    111     return counter 
     127    #return counter 
    112128 
    113129 
  • trunk/openopt/scikits/openopt/examples/checkDerivatives.py

    r904 r905  
    3737p.checkdc() 
    3838p.checkdh() 
    39 # you can use p.checkdF(x) for other point than x0 (F is f, c or h) 
     39""" 
     40you can use p.checkdF(x) for other point than x0 (F is f, c or h) 
     41p.checkdc(myX) 
     42or 
     43p.checkdc(x=myX) 
     44values with difference greater than  
     45maxViolation (default 1e-5) 
     46will be shown 
     47p.checkdh(maxViolation=1e-4) 
     48p.checkdh(myX, maxViolation=1e-4) 
     49p.checkdh(x=myX, maxViolation=1e-4) 
     50""" 
     51 
    4052 
    4153# if you'll use solvers that use derivatives,