Changeset 1216

Show
Ignore:
Timestamp:
08/10/08 04:27:06 (4 months ago)
Author:
dmitrey.kroshko
Message:

some changes in Kernel, primarily for oofun

Files:

Legend:

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

    r1168 r1216  
    22# created by Dmitrey 
    33#from numpy import copy, isnan, array, argmax, abs, zeros 
    4 from numpy import inf, asfarray, copy, all, any 
     4from numpy import inf, asfarray, copy, all, any, empty 
    55from oologfcn import OpenOptException 
    66from copy import deepcopy 
     
    3737        return tuple(r) 
    3838 
     39    def __getDep__(self): 
     40        if hasattr(self, 'dep'): 
     41            pass 
     42        elif self.input is None: 
     43            self.dep = None 
     44        else: 
     45            r = empty(self.x.size, bool).fill(False) 
     46            if not type(self.input) in (list, tuple): 
     47                self.input = (self.input, ) 
     48            for oofunInstance in self.input: 
     49                tmp = oofunInstance.__getDep__() 
     50                if tmp is None: 
     51                    r = self.dep = None # depends on all x coords 
     52                    break 
     53                else: 
     54                    r[tmp] = True 
     55            if r is not None: 
     56                self.dep = where(r)[0] 
     57            else: 
     58                self.dep = None 
     59        return self.dep 
     60 
     61 
    3962    def __getFunc__(self, x=None): 
    4063        if x is None: x = self.x 
    4164        else: self.x = x 
    4265 
    43         if self.input is not None: 
    44             Input = key_to_compare = self.__getInput__() 
    45         else: 
    46             #assert x is not None #or xxxx is not None 
    47             #if x is None: x = xxxx 
    48             Input = x 
    49             if hasattr(self, 'dep'): 
    50                 key_to_compare = x[self.dep] 
    51             else: 
    52                 key_to_compare = x 
     66        dep = self.__getDep__() 
     67        if dep is None: key_to_compare = x 
     68        else: key_to_compare = x[dep] 
    5369 
    5470        if not hasattr(self, 'f_key_prev') or any(self.f_key_prev != key_to_compare): 
    5571            self.evals += 1 
     72            if self.input is not None: 
     73                Input = self.__getInput__() 
     74            else: 
     75                Input = x 
    5676#            if self.fun.__module__ == 'scikits.openopt.Kernel.Function': 
    5777#                setattr(fun, 'x', x) 
     
    6080            else: 
    6181                self.f_val_prev = self.fun(Input) 
     82            self.f_key_prev = copy(key_to_compare) 
    6283        else: 
    6384            self.same += 1 
    6485 
    65         self.f_key_prev = copy(key_to_compare) 
    6686        return deepcopy(self.f_val_prev) 
    6787 
     
    7494        else: self.x = x 
    7595 
    76         if self.input is not None: 
    77             Input = key_to_compare = self.__getInput__() 
    78         else: 
    79             #assert x is not None or xxxx is not None 
    80             Input = x 
    81             if hasattr(self, 'dep'): 
    82                 key_to_compare = x[self.dep] 
    83             else: 
    84                 key_to_compare = x 
     96        dep = self.__getDep__() 
     97        if dep is None: key_to_compare = x 
     98        else: key_to_compare = x[dep] 
    8599 
    86100        if hasattr(self, 'd'): 
    87101            ########################## 
    88102            if not hasattr(self, 'd_key_prev') or any(self.d_key_prev != key_to_compare): 
     103                if self.input is not None: 
     104                    Input = self.__getInput__() 
     105                else: 
     106                    Input = x 
    89107                self.d_val_prev = self.d(Input) 
    90             self.d_key_prev = copy(key_to_compare) 
     108                self.d_key_prev = copy(key_to_compare) 
    91109            return copy(asfarray(self.d_val_prev)) 
    92110        else: 
  • trunk/openopt/scikits/openopt/Kernel/objFunRelated.py

    r1162 r1216  
    190190                        r0 = copy(r[agregate_counter:agregate_counter+v.size, 0]) 
    191191 
    192                     if hasattr(fun, 'dep')
    193                         assert all(isfinite(fun.dep )), 'only numbers can be handled in fun dependencies for now' 
     192                    if hasattr(fun, 'dep') and fun.dep is not None
     193                        #assert all(isfinite(fun.dep )), 'only numbers can be handled in fun dependencies for now' 
    194194                        derivativeInd = fun.dep 
    195195                    else: 
  • trunk/openopt/scikits/openopt/Kernel/runProbSolver.py

    r1173 r1216  
    5858        elif hasattr(p, key): 
    5959            setattr(p, key, value) 
    60         else: p.warn('incorrect parameter for solve(): "' + str(key) + '" - will be ignored (this one has been not found in neither prob nor solver parameters)') 
     60        else: p.warn('incorrect parameter for prob.solve(): "' + str(key) + '" - will be ignored (this one has been not found in neither prob nor ' + p.solver.__name__ + ' solver parameters)') 
    6161 
    6262    p.iterValues = EmptyClass()