def seek(X, H2, ren=renormL2, beta = 0.001, alpha=0.1, cutoff = 1e-4, maxIter = 100000, recordStep=100): """If recordStep = 0, then there is no recording done. Undefined behavior if not integer.""" errors = [] i = 0 y = ren(X) while i < maxIter: #### First, the deep math. E = errorMat(y, H2) # Gradient. g = grad(E, H2) + alpha*repulsiveGrad(X) # Grad descent. y = y - beta*g # Renorm y = ren(y) #### Next the logistics; counters, etc. r = norm(E) if recordStep != 0 and i % recordStep == 0: print y print E print r print '#####' errors.append(r) if r < cutoff: break i += 1 #If we did not dip below the cutoff, we did not converge. if r > cutoff: print "Warning: Error greater than cutoff, did not converge." #Return vector, the clique it represents, and the error trace. return y, extractClique(np.fabs(np.sign(np.round(y, 4)))), errors
def biggestClique(y, G): """Returns the biggest clique from key y, by looking at that biggest k elements of y until it is no longer a clique.""" l = len(y) ind = np.argsort(y) rev = np.argsort(ind) R = [] for i in range(1, l): k = np.zeros(l) k[-i:] = 1 k = k[rev] r = extractClique(k) if verifyClique(r, G): R = r else: break return R
from NPL4 import * from graphReader import getGraph from cliqueProject import extractClique from cliqueProject import verifyClique G = np.array( [[0, 1, 1, 0, 0], [1, 0, 1, 0, 1], [1, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 0, 0]]) x, c, errors = solve(G, renormL2, 1e-2, 1e-4, 1000000, 0) G = getGraph() H2 = graphToH(G) x = np.ones(125) y, c2, errors2 = seek(x, H2, renormCube, 1e-2, 1e-8, 100000000, 1000) R = extractClique(np.outer(c2, c2)) print R print len(R) print verifyClique(R, G)