Changeset 1530

Show
Ignore:
Timestamp:
10/10/08 08:35:53 (2 months ago)
Author:
dmitrey.kroshko
Message:

some changes

Files:

Legend:

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

    r1456 r1530  
    3434        (and/or other fields) to p.iterValues 
    3535        """ 
    36         xArg,  fArg,  rArg = True, True,  True 
     36        fArg,  rArg = True,  True 
    3737 
    3838        if len(args) == 1 and type(args[0]) != ndarray: # hence Point 
    3939            point = args[0] 
    40             p.xk, p.fk, p.rk = point.x, point.f(), point.mr() 
     40            p.xk, p.fk = point.x, point.f() 
     41            p.rk, p.rtk, p.rik = point.mr(True) 
    4142        else: 
    4243            if len(args)>0: p.xk = args[0] 
    4344            elif kwargs.has_key('xk'): p.xk = kwargs['xk'] 
    44             else: xArg = False 
     45            elif not hasattr(p, 'xk'): p.err('iterfcn must get x value, if you see it inform oo developers') 
    4546 
    4647            if len(args)>1: p.fk = args[1] 
     
    5253            else: rArg = False 
    5354 
     55            p.rk, p.rtk, p.rik = p.getMaxResidual(p.xk, True) 
     56 
    5457        #TODO: handle kwargs correctly! (decodeIterFcnArgs) 
    5558 
     
    5962 
    6063        p.iterValues.x.append(copy(p.xk)) 
     64 
     65        p.iterValues.rt.append(p.rtk) 
     66        p.iterValues.ri.append(p.rik) 
    6167 
    6268        if not fArg: 
  • trunk/openopt/scikits/openopt/Kernel/BaseProblem.py

    r1522 r1530  
    115115        self.noise = ProbDefaults['noise'] # TODO: move it to NinLinProblem class? 
    116116 
     117        self.showFeas = False 
    117118 
    118119        # A * x <= b inequalities 
  • trunk/openopt/scikits/openopt/Kernel/Function.py

    r1523 r1530  
    22# created by Dmitrey 
    33#from numpy import copy, isnan, array, argmax, abs, zeros 
    4 from numpy import inf, asfarray, copy, all, any, empty, atleast_2d, zeros, dot, asarray, atleast_1d, empty, ones, ndarray, where, isfinite, array 
     4from numpy import inf, asfarray, copy, all, any, empty, atleast_2d, zeros, dot, asarray, atleast_1d, empty, ones, ndarray, where, isfinite, array, nan, ix_ 
    55from oologfcn import OpenOptException 
    66from copy import deepcopy 
     
    4242                item.x = self.x 
    4343                r.append(item()) 
     44                self.inputTotalLength += item().size 
    4445            elif isinstance(item, oovar): 
    4546                r.append(self.x[item.dep]) 
     47                self.inputTotalLength += item.size 
    4648            elif not callable(item): r.append(item) 
    4749            else:  r.append(item()) 
    48             self.inputTotalLength += r[-1].size 
     50 
    4951        return tuple(r) 
    5052 
     
    147149                inp = Input_[i] 
    148150 
    149  
    150151                assert asarray(inp).ndim <= 1 
     152                if isinstance(inp, oovar): 
     153                    derivativeSelf[:, agregate_counter] = 1 
     154                    agregate_counter += 1 
    151155                if type(inp) in (ndarray, tuple, list): 
    152156                    # TODO: handle Python dict, mb Python class here 
     
    187191                agregate_counter = 0 
    188192                rr = zeros((self.inputTotalLength, len(x))) 
     193                #rr = zeros((self.inputTotalLength, self.outputTotalLength)) 
     194                has_oovar = False 
    189195                for i, inp in enumerate(self.input): 
    190196                    # get derivatives of i-th input 
    191                     tmp = atleast_2d(inp.D(x)) 
    192                     rr[agregate_counter:agregate_counter+tmp.shape[0]] = tmp 
    193                     agregate_counter += tmp.shape[0] 
    194                 if derivativeSelf.shape[0] == 1 and rr.shape[0] == 1: 
    195                     derivativeSelf = derivativeSelf.T 
    196                 r = dot(derivativeSelf, rr) 
     197                    if isinstance(inp, oovar): 
     198                        has_oovar = True 
     199                        #rr[agregate_counter:agregate_counter + inp.size] = nan 
     200                        agregate_counter += inp.size 
     201                    else: 
     202                        tmp = atleast_2d(inp.D(x)) 
     203                        rr[agregate_counter:agregate_counter+tmp.shape[0]] = tmp 
     204                        agregate_counter += tmp.shape[0] 
     205 
     206                if derivativeSelf.size == 1: 
     207                    r = derivativeSelf * rr 
     208                #elif derivativeSelf.ndim > 1: 
     209 
     210                elif derivativeSelf.shape[0] == 1 and rr.shape[0] == 1: 
     211                    r = dot(derivativeSelf.T, rr) 
     212                    #r = dot(derivativeSelf.flatten(), rr.flatten()) 
     213
     214#                elif derivativeSelf.ndim>1: 
     215#                    pass 
     216                    #derivativeSelf = derivativeSelf.T 
     217                else: 
     218                    r = dot(derivativeSelf, rr) 
     219 
     220                if has_oovar: 
     221                    agregate_counter = 0 
     222                    derivativeSelf = atleast_2d(derivativeSelf) 
     223                    for i, inp in enumerate(self.input): 
     224                        if isinstance(inp, oovar): 
     225                            r[agregate_counter, inp.dep] = derivativeSelf[agregate_counter, inp.dep] 
     226                            agregate_counter += inp.size 
     227                        else: 
     228                            agregate_counter += inp.__getInput__().size() 
     229 
    197230            else: 
    198231                r = derivativeSelf 
  • trunk/openopt/scikits/openopt/Kernel/Point.py

    r1504 r1530  
    11# created by Dmitrey 
    2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where 
     2from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where, asscalar 
    33__docformat__ = "restructuredtext en" 
    44empty_arr = array(()) 
     
    110110            self._mr, self._mrName,  self._mrInd= r, fname, ind 
    111111        if retAll: 
    112             return copy(self._mr), self._mrName, copy(self._mrInd
    113         else: return self._mr 
     112            return asscalar(copy(self._mr)), self._mrName, asscalar(copy(self._mrInd)
     113        else: return asscalar(copy(self._mr)) 
    114114 
    115115    def dmr(self, retAll = False): 
  • trunk/openopt/scikits/openopt/Kernel/Residuals.py

    r1108 r1530  
    4242        else: 
    4343            r.c = r.h = 0 
    44         r.A = self.__get_AX_Less_B_Residuals__(x) 
    45         r.Aeq= self.__get_AeqX_eq_Beq_Residuals__(x) 
     44        r.lin_ineq = self.__get_AX_Less_B_Residuals__(x) 
     45        r.lin_eq= self.__get_AeqX_eq_Beq_Residuals__(x) 
    4646        r.lb = self.__getLbResiduals__(x) 
    4747        r.ub = self.__getUbResiduals__(x) 
     
    6464        residuals = self.__getResiduals__(x) 
    6565        r, fname, ind = 0, None, None 
    66         for field in ('c',  'A', 'lb', 'ub'): 
     66        for field in ('c',  'lin_ineq', 'lb', 'ub'): 
    6767            fv = array(getattr(residuals, field)).flatten() 
    6868            if fv not in ([], ()) and fv.size>0: 
     
    7171                if r < val_max: 
    7272                    r, ind, fname = val_max, ind_max, field 
    73         for field in ('h', 'Aeq'): 
     73        for field in ('h', 'lin_eq'): 
    7474            fv = array(getattr(residuals, field)).flatten() 
    7575            if fv not in ([], ()) and fv.size>0: 
  • trunk/openopt/scikits/openopt/Kernel/ooIterPrint.py

    r1015 r1530  
    11from string import rjust 
    22from numpy import atleast_1d, asfarray, log10 
    3 textOutputDict = {'objFunVal': lambda p: '%0.3e' % p.iterValues.f[-1], 'log10(maxResidual)': lambda p: '%0.2f' % log10(p.iterValues.r[-1]+1e-100)} 
     3textOutputDict = {\ 
     4'objFunVal': lambda p: '%0.3e' % p.iterValues.f[-1], \ 
     5'log10(maxResidual)': lambda p: '%0.2f' % log10(p.iterValues.r[-1]+1e-100), \ 
     6'isFeasible': lambda p: ('+' if p.rk<p.contol else '-') 
     7
    48delimiter = '   ' 
    59 
  • trunk/openopt/scikits/openopt/Kernel/ooVar.py

    r1529 r1530  
    2727 
    2828    def D(self, x): 
    29         r = zeros(x.size) 
    30         r[self.dep] = 1 
     29        r = zeros((self.size, x.size)) 
     30        for i in range(self.size): 
     31            r[i, self.dep[i]] = 1 
    3132        return r 
    3233 
     
    6364            p.err('lower bound exceeds upper bound, solving impossible') 
    6465        if not hasattr(self, 'v0'): 
    65             p.warn('got oovar w/o init value') 
     66            #p.warn('got oovar w/o init value') 
    6667            v0 = zeros(self.shape) 
    6768 
  • trunk/openopt/scikits/openopt/Kernel/runProbSolver.py

    r1522 r1530  
    44from setDefaultIterFuncs import stopcase,  SMALL_DELTA_X,  SMALL_DELTA_F 
    55from ooCheck import ooCheck 
    6 #import copy 
     6import copy 
    77import os, string 
    88from ooMisc import isSolved, killThread 
     
    8080    p.iterValues.f = [] # iter ObjFunc Values 
    8181    p.iterValues.r = [] # iter MaxResidual 
     82    p.iterValues.rt = [] # iter MaxResidual Type: 'c', 'h', 'lb' etc 
     83    p.iterValues.ri = [] # iter MaxResidual Index 
     84 
    8285 
    8386 
     
    149152 
    150153    p.isUC = p.__isUnconstrained__() 
    151     if p.solver.__isIterPointAlwaysFeasible__(p): 
     154    if p.solver.__isIterPointAlwaysFeasible__ is True or \ 
     155    (not p.solver.__isIterPointAlwaysFeasible__ is False and p.solver.__isIterPointAlwaysFeasible__(p)): 
    152156        assert p.data4TextOutput[-1] == 'log10(maxResidual)' 
    153157        p.data4TextOutput = p.data4TextOutput[:-1] 
     158 
     159    if p.showFeas: p.data4TextOutput.append('isFeasible') 
    154160 
    155161    if not p.solver.__iterfcnConnected__: 
     
    247253        if hasattr(p, fn):  setattr(r, fn, getattr(p, fn)) 
    248254 
    249     r.xf = copy(p.xf) 
     255    r.xf = copy.deepcopy(p.xf) 
    250256    r.rf = asscalar(asarray(p.rf)) 
    251257    r.ff = asscalar(asarray(r.ff)) 
  • trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py

    r1456 r1530  
    2020IS_MAX_FUN_EVALS_REACHED = -10 
    2121IS_ALL_VARS_FIXED = -11 
     22FAILED_TO_OBTAIN_MOVE_DIRECTION = -13 
    2223USER_DEMAND_EXIT = -99 
    2324