Changeset 427

Show
Ignore:
Timestamp:
02/06/10 13:31:51 (1 month ago)
Author:
dmitrey
Message:

some changes for sparse LLSPs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PythonPackages/OpenOpt/openopt/kernel/FDmisc.py

    r383 r427  
    188 188     # TODO: replave p.x0 in RunProbSolver finish   
    189 189     p._x0, p.x0 = p.x0, vector_x0  
      190      
      191     def linearOOFunsToMatrices(oofuns): 
      192         # oofuns should be linear 
      193         C, d = [], [] 
      194         Z = self._vector2point(zeros(p.n)) 
      195         for elem in oofuns: 
      196             if elem.isConstraint: 
      197                 lin_oofun = elem.oofun 
      198             else: 
      199                 lin_oofun = elem 
      200             if not lin_oofun.is_linear: 
      201                 raise OpenOptException("this function hasn't been intended to work with nonlinear FuncDesigner oofuns") 
      202             C.append(self._pointDerivative2array(lin_oofun._D(Z, **self._D_kwargs), asSparse = 'auto')) 
      203             d.append(-lin_oofun(Z)) 
      204              
      205         if any(isspmatrix([elem for elem in C])): 
      206             Vstack = scipy.sparse.vstack 
      207         else: 
      208             Vstack = vstack # i.e. numpy.vstack 
      209         #raise 0 
      210         C, d = Vstack(C), hstack(d).flatten() 
      211         raise 0 
      212         return C, d     
      213     p._linearOOFunsToMatrices = linearOOFunsToMatrices 
    190 214      
    191 215      
  • PythonPackages/OpenOpt/openopt/kernel/LLSP.py

    r422 r427  
    32 32  
    33 33     def objFunc(self, x): 
    34           r = norm(dot(self.C, x) - self.d) ** 2  /  2.0 
      34         r = norm(self.matMultVec(self.C, x) - self.d) ** 2  /  2.0 
    35 35         if self.damp is not None: 
    36 36             r += self.damp * norm(x-self.X)**2 / 2.0 
     
    57 57         MatrixProblem.__prepare__(self) 
    58 58         if self.isFDmodel: 
    59               C, d = [], [] 
    60               Z = self._vector2point(zeros(self.n)) 
    61               for lin_oofun in self.C: 
    62                   C.append(self._pointDerivative2array(lin_oofun._D(Z, **self._D_kwargs))) 
    63                   d.append(-lin_oofun(Z)) 
    64               self.C, self.d = vstack(C), vstack(d).flatten() 
      59             self.C, self.d = p._linearOOFunsToMatrices(self.C) 
      60 #            C, d = [], [] 
      61 #            Z = self._vector2point(zeros(self.n)) 
      62 #            for lin_oofun in self.C: 
      63 #                C.append(self._pointDerivative2array(lin_oofun._D(Z, **self._D_kwargs))) 
      64 #                d.append(-lin_oofun(Z)) 
      65 #            self.C, self.d = vstack(C), vstack(d).flatten() 
    65 66         if not self.damp is None and (not hasattr(self, 'X') or not any(isfinite(self.X))): 
    66 67             self.X = zeros(self.n) 
  • PythonPackages/OpenOpt/openopt/kernel/baseProblem.py

    r405 r427  
    10 10 from iterPrint import ooTextOutput 
    11 11 from ooMisc import setNonLinFuncsNumber, assignScript 
    12   from nonOptMisc import isspmatrix, scipyInstalled, scipyAbsentMsg 
      12 from nonOptMisc import isspmatrix, scipyInstalled, scipyAbsentMsg, csr_matrix 
    13 13 from copy import copy as Copy 
    14 14 try: 
     
    31 31     def __init__(self): 
    32 32         pass 
      33     def matMultVec(self, x, y): 
      34         return dot(x, y) if not isspmatrix(x) else x._mul_sparse_matrix(csr_matrix(y.reshape((y.size, 1)))).A.flatten()  
    33 35     def matmult(self, x, y): 
    34 36         return dot(x, y) 
  • PythonPackages/OpenOpt/openopt/kernel/nonOptMisc.py

    r379 r427  
    10 10     scipyInstalled = True 
    11 11     scipyAbsentMsg = '' 
    12       from scipy.sparse import isspmatrix 
      12     from scipy.sparse import isspmatrix, csr_matrix 
    13 13     from scipy.sparse import bmat as Bmat 
    14 14     from scipy.sparse import hstack as Hstack, vstack as Vstack, find as Find 
     
    16 16 except: 
    17 17     scipyInstalled = False 
      18     csr_matrix = None 
    18 19     scipyAbsentMsg = 'Probably scipy installation could speed up running the code involved' 
    19 20     isspmatrix = lambda *args,  **kwargs:  False