Exemple #1
0
 def test_projected_inverse(self):
     Y = cp.cspmatrix(self.symb) + self.A
     Am = Y.spmatrix(symmetric=True,reordered=False)
     cp.cholesky(Y)
     cp.projected_inverse(Y)
     Ym = Y.spmatrix(symmetric=True,reordered=False)
     self.assertAlmostEqual((Ym.V.T*(Am.V))[0], self.symb.n)
Exemple #2
0
 def test_projected_inverse(self):
     Y = cp.cspmatrix(self.symb) + self.A
     Am = Y.spmatrix(symmetric=True, reordered=False)
     cp.cholesky(Y)
     cp.projected_inverse(Y)
     Ym = Y.spmatrix(symmetric=True, reordered=False)
     self.assertAlmostEqual((Ym.V.T * (Am.V))[0], self.symb.n)
Exemple #3
0
 def test_completion_fu(self):
     L = cp.cspmatrix(self.symb) + self.A
     cp.cholesky(L)
     L2 = L.copy()
     cp.projected_inverse(L2)
     cp.completion(L2, factored_updates = True)
     diff = list((L.spmatrix()-L2.spmatrix()).V)
     self.assertAlmostEqualLists(diff, len(diff)*[0.0])
Exemple #4
0
 def test_completion_fu(self):
     L = cp.cspmatrix(self.symb) + self.A
     cp.cholesky(L)
     L2 = L.copy()
     cp.projected_inverse(L2)
     cp.completion(L2, factored_updates=True)
     diff = list((L.spmatrix() - L2.spmatrix()).V)
     self.assertAlmostEqualLists(diff, len(diff) * [0.0])
Exemple #5
0
 def test_hessian_fu(self):
     L = cp.cspmatrix(self.symb) + self.A
     cp.cholesky(L)
     Y = L.copy()
     cp.projected_inverse(Y)        
     U = cp.cspmatrix(self.symb) + 0.1*self.A
     cp.hessian(L, Y, U, adj = False, inv = False, factored_updates = True)
     cp.hessian(L, Y, U, adj = True, inv = False, factored_updates = True)
     cp.hessian(L, Y, U, adj = True, inv = True, factored_updates = True)
     cp.hessian(L, Y, U, adj = False, inv = True, factored_updates = True)
     diff = list((0.1*self.A-U.spmatrix(reordered=False,symmetric=False)).V)
     self.assertAlmostEqualLists(diff, len(diff)*[0.0])
Exemple #6
0
 def test_hessian_fu(self):
     L = cp.cspmatrix(self.symb) + self.A
     cp.cholesky(L)
     Y = L.copy()
     cp.projected_inverse(Y)
     U = cp.cspmatrix(self.symb) + 0.1 * self.A
     cp.hessian(L, Y, U, adj=False, inv=False, factored_updates=True)
     cp.hessian(L, Y, U, adj=True, inv=False, factored_updates=True)
     cp.hessian(L, Y, U, adj=True, inv=True, factored_updates=True)
     cp.hessian(L, Y, U, adj=False, inv=True, factored_updates=True)
     diff = list(
         (0.1 * self.A - U.spmatrix(reordered=False, symmetric=False)).V)
     self.assertAlmostEqualLists(diff, len(diff) * [0.0])
Exemple #7
0
print("Largest clique        : %i\n" % (symb.clique_number))

A = cspmatrix(symb)  # create new cspmatrix from symbolic factorization
A += As              # add spmatrix 'As' to cspmatrix 'A'; this ignores the upper triangular entries in As

print("Computing Cholesky factorization..")
L = A.copy()         # make a copy of A
cholesky(L)          # compute Cholesky factorization; overwrites L

print("Computing Cholesky product..")
At = L.copy()        # make a copy of L
llt(At)              # compute Cholesky product; overwrites At

print("Computing projected inverse..")
Y = L.copy()         # make a copy of L
projected_inverse(Y) # compute projected inverse; overwrites Y

print("Computing completion..")
Lc = Y.copy()        # make a copy of Y
completion(Lc, factored_updates = False) # compute completion; overwrites Lc

print("Computing completion with factored updates..")
Lc2 = Y.copy()       # make a copy of Y
completion(Lc2, factored_updates = True) # compute completion (with factored updates); overwrites Lc2

print("Applying Hessian factors..")
U = At.copy()
fupd = False
hessian(L, Y, U, adj = False, inv = False, factored_updates = fupd)
hessian(L, Y, U, adj = True, inv = False, factored_updates = fupd)
hessian(L, Y, U, adj = True, inv = True, factored_updates = fupd)