Changeset 1530
- Timestamp:
- 10/10/08 08:35:53 (2 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/BaseAlg.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/BaseProblem.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/Function.py (modified) (4 diffs)
- trunk/openopt/scikits/openopt/Kernel/Point.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/Residuals.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/ooIterPrint.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/ooVar.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/runProbSolver.py (modified) (4 diffs)
- trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseAlg.py
r1456 r1530 34 34 (and/or other fields) to p.iterValues 35 35 """ 36 xArg, fArg, rArg = True,True, True36 fArg, rArg = True, True 37 37 38 38 if len(args) == 1 and type(args[0]) != ndarray: # hence Point 39 39 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) 41 42 else: 42 43 if len(args)>0: p.xk = args[0] 43 44 elif kwargs.has_key('xk'): p.xk = kwargs['xk'] 44 el se: xArg = False45 elif not hasattr(p, 'xk'): p.err('iterfcn must get x value, if you see it inform oo developers') 45 46 46 47 if len(args)>1: p.fk = args[1] … … 52 53 else: rArg = False 53 54 55 p.rk, p.rtk, p.rik = p.getMaxResidual(p.xk, True) 56 54 57 #TODO: handle kwargs correctly! (decodeIterFcnArgs) 55 58 … … 59 62 60 63 p.iterValues.x.append(copy(p.xk)) 64 65 p.iterValues.rt.append(p.rtk) 66 p.iterValues.ri.append(p.rik) 61 67 62 68 if not fArg: trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r1522 r1530 115 115 self.noise = ProbDefaults['noise'] # TODO: move it to NinLinProblem class? 116 116 117 self.showFeas = False 117 118 118 119 # A * x <= b inequalities trunk/openopt/scikits/openopt/Kernel/Function.py
r1523 r1530 2 2 # created by Dmitrey 3 3 #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 4 from numpy import inf, asfarray, copy, all, any, empty, atleast_2d, zeros, dot, asarray, atleast_1d, empty, ones, ndarray, where, isfinite, array, nan, ix_ 5 5 from oologfcn import OpenOptException 6 6 from copy import deepcopy … … 42 42 item.x = self.x 43 43 r.append(item()) 44 self.inputTotalLength += item().size 44 45 elif isinstance(item, oovar): 45 46 r.append(self.x[item.dep]) 47 self.inputTotalLength += item.size 46 48 elif not callable(item): r.append(item) 47 49 else: r.append(item()) 48 self.inputTotalLength += r[-1].size 50 49 51 return tuple(r) 50 52 … … 147 149 inp = Input_[i] 148 150 149 150 151 assert asarray(inp).ndim <= 1 152 if isinstance(inp, oovar): 153 derivativeSelf[:, agregate_counter] = 1 154 agregate_counter += 1 151 155 if type(inp) in (ndarray, tuple, list): 152 156 # TODO: handle Python dict, mb Python class here … … 187 191 agregate_counter = 0 188 192 rr = zeros((self.inputTotalLength, len(x))) 193 #rr = zeros((self.inputTotalLength, self.outputTotalLength)) 194 has_oovar = False 189 195 for i, inp in enumerate(self.input): 190 196 # 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 197 230 else: 198 231 r = derivativeSelf trunk/openopt/scikits/openopt/Kernel/Point.py
r1504 r1530 1 1 # created by Dmitrey 2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where 2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where, asscalar 3 3 __docformat__ = "restructuredtext en" 4 4 empty_arr = array(()) … … 110 110 self._mr, self._mrName, self._mrInd= r, fname, ind 111 111 if retAll: 112 return copy(self._mr), self._mrName, copy(self._mrInd)113 else: return self._mr112 return asscalar(copy(self._mr)), self._mrName, asscalar(copy(self._mrInd)) 113 else: return asscalar(copy(self._mr)) 114 114 115 115 def dmr(self, retAll = False): trunk/openopt/scikits/openopt/Kernel/Residuals.py
r1108 r1530 42 42 else: 43 43 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) 46 46 r.lb = self.__getLbResiduals__(x) 47 47 r.ub = self.__getUbResiduals__(x) … … 64 64 residuals = self.__getResiduals__(x) 65 65 r, fname, ind = 0, None, None 66 for field in ('c', ' A', 'lb', 'ub'):66 for field in ('c', 'lin_ineq', 'lb', 'ub'): 67 67 fv = array(getattr(residuals, field)).flatten() 68 68 if fv not in ([], ()) and fv.size>0: … … 71 71 if r < val_max: 72 72 r, ind, fname = val_max, ind_max, field 73 for field in ('h', ' Aeq'):73 for field in ('h', 'lin_eq'): 74 74 fv = array(getattr(residuals, field)).flatten() 75 75 if fv not in ([], ()) and fv.size>0: trunk/openopt/scikits/openopt/Kernel/ooIterPrint.py
r1015 r1530 1 1 from string import rjust 2 2 from 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)} 3 textOutputDict = {\ 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 } 4 8 delimiter = ' ' 5 9 trunk/openopt/scikits/openopt/Kernel/ooVar.py
r1529 r1530 27 27 28 28 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 31 32 return r 32 33 … … 63 64 p.err('lower bound exceeds upper bound, solving impossible') 64 65 if not hasattr(self, 'v0'): 65 p.warn('got oovar w/o init value')66 #p.warn('got oovar w/o init value') 66 67 v0 = zeros(self.shape) 67 68 trunk/openopt/scikits/openopt/Kernel/runProbSolver.py
r1522 r1530 4 4 from setDefaultIterFuncs import stopcase, SMALL_DELTA_X, SMALL_DELTA_F 5 5 from ooCheck import ooCheck 6 #import copy6 import copy 7 7 import os, string 8 8 from ooMisc import isSolved, killThread … … 80 80 p.iterValues.f = [] # iter ObjFunc Values 81 81 p.iterValues.r = [] # iter MaxResidual 82 p.iterValues.rt = [] # iter MaxResidual Type: 'c', 'h', 'lb' etc 83 p.iterValues.ri = [] # iter MaxResidual Index 84 82 85 83 86 … … 149 152 150 153 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)): 152 156 assert p.data4TextOutput[-1] == 'log10(maxResidual)' 153 157 p.data4TextOutput = p.data4TextOutput[:-1] 158 159 if p.showFeas: p.data4TextOutput.append('isFeasible') 154 160 155 161 if not p.solver.__iterfcnConnected__: … … 247 253 if hasattr(p, fn): setattr(r, fn, getattr(p, fn)) 248 254 249 r.xf = copy (p.xf)255 r.xf = copy.deepcopy(p.xf) 250 256 r.rf = asscalar(asarray(p.rf)) 251 257 r.ff = asscalar(asarray(r.ff)) trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py
r1456 r1530 20 20 IS_MAX_FUN_EVALS_REACHED = -10 21 21 IS_ALL_VARS_FIXED = -11 22 FAILED_TO_OBTAIN_MOVE_DIRECTION = -13 22 23 USER_DEMAND_EXIT = -99 23 24
