Exemplo n.º 1
0
def dice_sim_matrix_po(X):
    sumX = pnp.sum(X, axis = 1)
    sumX = pnp.reshape(pnp.tile(sumX, len(X)), (len(X), len(X)))
    sumX = sumX + pnp.transpose(sumX)
    cmpX = pnp.zeros((len(X), len(X)))
    for i in range(len(X)):
        cmpX[i] = pnp.sum(X * pnp.reshape(pnp.tile(X[i], len(X)), (len(X), len(X[0]))), axis = 1)
    result = 2 * cmpX * myreciprocal(sumX * sumX, 0.0)
    result = sumX * result
    return result
Exemplo n.º 2
0
def R2(x, y):
    if (np.size(x) != np.size(y)):
        print('Warning: input vectors for R2 must be same length!')
        return -100.0
    else:
        avx = pnp.mean(x)
        avy = pnp.mean(y)
        num = pnp.sum((x - avx) * (y - avy))
        num = num * num
        denom = pnp.sum((x - avx) * (x - avx)) * pnp.sum((y - avy) * (y - avy))
        res = num * pp.reciprocal(denom)
        return res
Exemplo n.º 3
0
 def fdot(A, B):
     # flatten dot. Regard A and B as long vector
     A = pp.farr(A)
     B = pp.farr(B)
     A = A * (1.0/A.shape[0])
     B = B * (1.0/B.shape[0])
     return pnp.sum(A * B)
Exemplo n.º 4
0
def jaccard_sim_po(mat):
    intersect = pnp.dot(mat, pnp.transpose(mat))
    union = pnp.sum(mat, axis = 1)
    union = pnp.reshape(pnp.tile(union, len(mat)), (len(mat), len(mat)))
    union = union + pnp.transpose(union) - intersect + 0.0
    sim = intersect * myreciprocal(union,0.0)
    for i in range(sim.shape[0]):
        sim[i, i] = pp.sfixed(1.0)
    return sim
Exemplo n.º 5
0
def RWR_po(A, maxiter, restartProb):
    n = len(A)
    # normalize the adjacency matrix
    A = A + 0.0
    tmp_var = pnp.sum(A,axis=0)
    tmp_var = myreciprocal(tmp_var,0.0)
    tmp_var = pnp.tile(tmp_var,(A.shape[0],1))
    P = A * tmp_var
    # Personalized PageRank
    restart = pnp.eye(n) * restartProb
    Q = pnp.eye(n)
    for i in range(maxiter):
        Q = (1 - restartProb) * pnp.dot(P, Q) + restart
    return Q