コード例 #1
0
 def objFunc(self, x):
     if isinstance(self.C, ndarray):
         return norm(dot(self.C, x) - self.d, inf)
     else:
         # TODO: omit code clone in FD ooFun.py, function _D
         t1 = self.C_as_csc
         t2 = csr_matrix(x)
         if t2.shape[0] != t1.shape[1]:
             assert t2.shape[1] == t1.shape[1], 'incorrect shape in OpenOpt SLE, inform developers about the bug'
             t2 = t2.T
         rr =  t1._mul_sparse_matrix(t2)            
         return norm(rr.toarray().flatten() - self.d, inf)
コード例 #2
0
ファイル: SLE.py プロジェクト: AlbertHolmes/openopt
 def objFunc(self, x):
     if isinstance(self.C, ndarray):
         return norm(dot(self.C, x) - self.d, inf)
     else:
         # TODO: omit code clone in FD ooFun.py, function _D
         t1 = self.C_as_csc
         t2 = scipy.sparse.csr_matrix(x)
         if t2.shape[0] != t1.shape[1]:
             if t2.shape[1] == t1.shape[1]:
                 t2 = t2.T
             else:
                 raise FuncDesignerException('incorrect shape in FuncDesigner function _D(), inform developers about the bug')
         rr =  t1._mul_sparse_matrix(t2)            
         return norm(rr.toarray().flatten() - self.d, inf)
コード例 #3
0
ファイル: SLE.py プロジェクト: wqlsky/openopt
 def objFunc(self, x):
     if isinstance(self.C, ndarray):
         return norm(dot(self.C, x) - self.d, inf)
     else:
         # TODO: omit code clone in FD ooFun.py, function _D
         t1 = self.C_as_csc
         t2 = scipy.sparse.csr_matrix(x)
         if t2.shape[0] != t1.shape[1]:
             if t2.shape[1] == t1.shape[1]:
                 t2 = t2.T
             else:
                 raise FuncDesignerException(
                     'incorrect shape in FuncDesigner function _D(), inform developers about the bug'
                 )
         rr = t1._mul_sparse_matrix(t2)
         return norm(rr.toarray().flatten() - self.d, inf)
コード例 #4
0
ファイル: LLAVP.py プロジェクト: PythonCharmers/OOSuite
 def objFunc(self, x):
     r = norm(dot(self.C, x) - self.d, 1)
     if not self.damp is None:
         r += self.damp * norm(x-self.X, 1)
     #if any(isfinite(self.f)): r += dot(self.f, x)
     return r
コード例 #5
0
ファイル: LUNP.py プロジェクト: AlbertHolmes/openopt
    def objFunc(self, x):
        r = norm(dot(self.C, x) - self.d, inf)
#        if not self.damp is None:
#            r += self.damp * norm(x-self.X)**2 / 2.0
#        if any(isfinite(self.f)): r += dot(self.f, x)
        return r
コード例 #6
0
 def objFunc(self, x):
     r = norm(dot(self.C, x) - self.d, 1)
     if not self.damp is None:
         r += self.damp * norm(x - self.X, 1)
     #if any(isfinite(self.f)): r += dot(self.f, x)
     return r
コード例 #7
0
 def objFuncMultiple2Single(self, fv):
     return norm(atleast_1d(asfarray(fv)), inf)
コード例 #8
0
ファイル: LLSP.py プロジェクト: PythonCharmers/OOSuite
 def objFunc(self, x):
     r = norm(self.matMultVec(self.C, x) - self.d) ** 2  /  2.0
     if self.damp is not None:
         r += self.damp * norm(x-self.X)**2 / 2.0
     if self.f is not None: r += dot(self.f, x)
     return r
コード例 #9
0
ファイル: LCP.py プロジェクト: AlbertHolmes/openopt
 def objFunc(self, x):
     return norm(dot(self.M, x[x.size/2:]) +self.q - x[:x.size/2], inf)
コード例 #10
0
    def sum_of_all_active_constraints_gradient(self):
        if not hasattr(self, '_sum_of_all_active_constraints_gradient'):
            p = self.p
            contol = p.contol
            x = self.x
            direction = self.all_lin_gradient()
            if p.solver.__name__ == 'ralg':
                new = 1
            elif p.solver.__name__ == 'gsubg':
                new = 0
            else:
                p.err('unhandled case in Point._getDirection')
                
            if p.userProvided.c:
                th = 0.0
                #th = contol / 2.0
                C = p.c(x)
                Ind = C>th
                ind = where(Ind)[0]
                activeC = asarray(C[Ind])# asarray and Ind for PyPy compatibility
                if len(ind) > 0:
                    tmp = p.dc(x, ind)

                    if new:
                        if tmp.ndim == 1 or min(tmp.shape) == 1:
                            if hasattr(tmp, 'toarray'): 
                                tmp = tmp.toarray()#.flatten()
                            if activeC.size == prod(tmp.shape):
                                activeC = activeC.reshape(tmp.shape)
                            tmp *= (activeC-th*(1.0-1e-15))/norm(tmp)
                        else:
                            if hasattr(tmp, 'toarray'):
                                tmp = tmp.toarray()
                            tmp *= ((activeC - th*(1.0-1e-15))/sqrt((tmp**2).sum(1))).reshape(-1, 1)
                            
                    if tmp.ndim > 1:
                        tmp = tmp.sum(0)
                    direction += (tmp.A if type(tmp) != ndarray else tmp).flatten()
            

            if p.userProvided.h:
                #th = 0.0
                th = contol / 2.0
                H = p.h(x)
                Ind1 = H>th
                ind1 = where(Ind1)[0]
                H1 = asarray(H[Ind1])# asarray and Ind1 for PyPy compatibility
                if len(ind1) > 0:
                    tmp = p.dh(x, ind1)
                    
                    if new:
                        if tmp.ndim == 1 or min(tmp.shape) == 1:
                            if hasattr(tmp, 'toarray'): 
                                tmp = tmp.toarray()#.flatten()
                            if H1.size == prod(tmp.shape):
                                H1 = H1.reshape(tmp.shape)
                            tmp *= (H1-th*(1.0-1e-15))/norm(tmp)
                        else:
                            if hasattr(tmp, 'toarray'):
                                tmp = tmp.toarray()
                            tmp *= ((H1 - th*(1.0-1e-15))/sqrt((tmp**2).sum(1))).reshape(-1, 1)
                    
                    if tmp.ndim > 1: 
                        tmp = tmp.sum(0)
                    direction += (tmp.A if isspmatrix(tmp) or hasattr(tmp, 'toarray') else tmp).flatten()
                ind2 = where(H<-th)[0]
                H2 = H[ind2]
                if len(ind2) > 0:
                    tmp = p.dh(x, ind2)
                    if new:
                        if tmp.ndim == 1 or min(tmp.shape) == 1:
                            if hasattr(tmp, 'toarray'): 
                                tmp = tmp.toarray()#.flatten()
                            if H2.size == prod(tmp.shape):
                                H2 = H2.reshape(tmp.shape)                                    
                            tmp *= (-H2-th*(1.0-1e-15))/norm(tmp)
                        else:
                            if hasattr(tmp, 'toarray'):
                                tmp = tmp.toarray()
                            tmp *= ((-H2 - th*(1.0-1e-15))/sqrt((tmp**2).sum(1))).reshape(-1, 1)
                    
                    if tmp.ndim > 1: 
                        tmp = tmp.sum(0)
                    direction -= (tmp.A if type(tmp) != ndarray else tmp).flatten()
            self._sum_of_all_active_constraints_gradient = direction
        return Copy(self._sum_of_all_active_constraints_gradient)
コード例 #11
0
 def objFunc(self, x):
     return norm(dot(self.M, x[x.size / 2:]) + self.q - x[:x.size / 2], inf)
コード例 #12
0
 def objFunc(self, x):
     r = norm(self.matMultVec(self.C, x) - self.d)**2 / 2.0
     if self.damp is not None:
         r += self.damp * norm(x - self.X)**2 / 2.0
     if self.f is not None: r += dot(self.f, x)
     return r
コード例 #13
0
ファイル: NLSP.py プロジェクト: AlbertHolmes/openopt
 def objFuncMultiple2Single(self, fv):
     return norm(atleast_1d(asfarray(fv)), inf)
コード例 #14
0
ファイル: LUNP.py プロジェクト: javafx2010/OOSuite
 def objFunc(self, x):
     r = norm(dot(self.C, x) - self.d, inf)
     #        if not self.damp is None:
     #            r += self.damp * norm(x-self.X)**2 / 2.0
     #        if any(isfinite(self.f)): r += dot(self.f, x)
     return r