def spy(P,i=None,file=None,scale=None): """Generates sparsity plot using Pylab""" if type(P) is spmatrix: V = chompack.symmetrize(chompack.tril(P)) n = V.size[0] else: if not P._A: raise AttributeError, "SDP data missing" n = +P.n; if i == None: V = chompack.symmetrize(P.V) elif i>=0 and i<=P.m and P._A: r = P._A.CCS[1][P._A.CCS[0][i]:P._A.CCS[0][i+1]] if type(r) is int: I = [r%n]; J = [r/n] else: I,J = misc.ind2sub(n,r) V = chompack.symmetrize(spmatrix(0.,I,J,(n,n))) else: raise ValueError, "index out of range" from math import floor msize = max(1,int(floor(100./n))) if file==None: pylab.ion() else: pylab.ioff() f = pylab.figure(figsize=(6,6)); f.clf() if scale is None: scale = 1.0 I = V.I*scale+1; J = (n-V.J)*scale p = pylab.plot(I,J, 's', linewidth = 1, hold = 'False') pylab.setp(p, markersize = msize, markerfacecolor = 'k') g = pylab.gca() pylab.axis([0.5,n*scale+0.5,0.5,n*scale+0.5]) g.set_aspect('equal') locs,labels = pylab.yticks() locs = locs[locs<=n*scale]; locs = locs[locs>=1] pylab.yticks(locs[::-1]-(locs[-1]-n*scale-1)-locs[0], [str(int(loc)) for loc in locs]) if file: pylab.savefig(file)
def get_A(self,i=None): """Returns A if i is None, otherwise returns Ai as spmatrix""" if i==None and self._A: return self._A elif i>=0 and i<=self.m and self._A: r = self._A.CCS[1][self._A.CCS[0][i]:self._A.CCS[0][i+1]] v = self._A.CCS[2][self._A.CCS[0][i]:self._A.CCS[0][i+1]] if isinstance(v,float): I = [r/self.n]; J = [r%self.n] else: I,J = misc.ind2sub(self.n,r) return spmatrix(v,I,J,(self.n,self.n)) elif self._A: raise ValueError("index is out of range") else: raise AttributeError("SDP object has not been initialized")
def get_A(self, i=None): """Returns A if i is None, otherwise returns Ai as spmatrix""" if i == None and self._A: return self._A elif i >= 0 and i <= self.m and self._A: r = self._A.CCS[1][self._A.CCS[0][i]:self._A.CCS[0][i + 1]] v = self._A.CCS[2][self._A.CCS[0][i]:self._A.CCS[0][i + 1]] if isinstance(v, float): I = [r / self.n] J = [r % self.n] else: I, J = misc.ind2sub(self.n, r) return spmatrix(v, I, J, (self.n, self.n)) elif self._A: raise ValueError, "index is out of range" else: raise AttributeError, "SDP object has not been initialized"
def V(self): """Sparsity pattern (CVXOPT spmatrix)""" I,J = misc.ind2sub(self.n,self.I) return spmatrix(0.,I,J,(self.n,self.n))
def V(self): """Sparsity pattern (CVXOPT spmatrix)""" I, J = misc.ind2sub(self.n, self.I) return spmatrix(0., I, J, (self.n, self.n))