Example #1
0
	def compute_scores(self):
		A = self.get_adj()
		r = list(range(self.num_nodes))
		eigval = hf.scipy_eigsh(A)
		
		scores = np.zeros((self.num_nodes, self.num_nodes))
		for i in range(1,self.num_nodes):
			for j in range(i):
				if A[i,j] < 1:
					first = hf.partition(A,np.array([i,j]),np.array([i,j]))
					comp = hf.complement(r,[i,j])
					second = hf.partition(A,np.array([i,j]),comp) 
					temp = hf.partition(A, comp, comp)
					third = np.linalg.inv(hf.partition(A, comp, comp)-eigval*np.identity(self.num_nodes-2))
					fourth = hf.partition(A, comp,np.array([i,j]))
					#print(first.shape, second.shape, third.shape, fourth.shape)
					okay = second @ third @ fourth
					this = first-okay
					scores[i,j] = this[0,1]		
		return scores
def par(fname):
    rank = 0
    size = 20

    start = time.time()

    filename = 'data/' + fname + '.txt'
    G, to_predict, fullG = load_data(filename)

    directed = False
    k = len(to_predict)
    min_links = k
    score_tolerance = 1e-10
    score_inf = 1e18
    force_exact = False

    A = nx.adjacency_matrix(G)
    num_nodes = A.shape[0]
    node_list = G.nodes()
    degrees = np.sum(A, axis=1)
    M = A / degrees
    r = list(range(num_nodes))
    eigval = hf.scipy_eigsh(M)

    for i in range(num_nodes):
        for j in range(rank, num_nodes, size):
            if A[i, j] == 0 and i != j:
                first = hf.partition(M, np.array([i, j]), np.array([i, j]))
                comp = hf.complement(r, [i, j])
                second = hf.partition(M, np.array([i, j]), comp)
                temp = hf.partition(M, comp, comp)
                third = np.linalg.inv(
                    hf.partition(M, comp, comp) -
                    eigval * np.identity(num_nodes - 2))
                fourth = hf.partition(M, comp, np.array([i, j]))
                okay = second @ third @ fourth
                this = first - okay
                send = this[0, 1]

    return time.time() - start
Example #3
0
directed = False
k = len(to_predict)
min_links = k
score_tolerance = 1e-10
score_inf = 1e18
force_exact = False

start = time.time()

A = nx.adjacency_matrix(G)
num_nodes = A.shape[0]
node_list = G.nodes()
degrees = np.sum(A, axis=1)
M = A / degrees
r = list(range(num_nodes))
eigval = hf.scipy_eigsh(M)

scores = np.zeros((num_nodes, num_nodes))
for i in range(num_nodes):
    for j in range(num_nodes):
        if A[i, j] == 0 and i != j:
            first = hf.partition(M, np.array([i, j]), np.array([i, j]))
            comp = hf.complement(r, [i, j])
            second = hf.partition(M, np.array([i, j]), comp)
            temp = hf.partition(M, comp, comp)
            third = np.linalg.inv(
                hf.partition(M, comp, comp) -
                eigval * np.identity(num_nodes - 2))
            fourth = hf.partition(M, comp, np.array([i, j]))
            okay = second @ third @ fourth
            this = first - okay