示例#1
0
def plotEmbedComparison(G, e1, e2):
    e1.embed(G)
    e2.embed(G)
    x1 = e1.get_scaled(2)
    x2 = e2.get_scaled(2)
    
    x2p = Embed.procrustes(x1, x2)
    
    #block = nx.get_node_attributes(G, 'block').values()
    
    #plot.subplot(121);
    plot.scatter(x1[:,0],x1[:,1],c='r')
    #plot.subplot(122);
    plot.scatter(x2p[:,0],x2p[:,1],c='b')
示例#2
0
def get_rdpg_sim_res(rdpg, embed, k):
    rdpg.generate_adjacency()
    Xhat = Embed.procrustes(rdpg.X, embed.embed(rdpg.Adj).get_scaled())
    #Y =  rdpg.block_assignment
    knn = KNeighborsClassifier(k)
    loo = cross_validation.LeaveOneOut(rdpg.n_nodes)
    
    X = rdpg.X
    Y = (X[:,0]>X[:,1]).astype(float)
    Xhat = Embed.procrustes(X,embed.embed(rdpg.Adj).get_scaled(),scale=False, center=False)
    
    
    result = np.zeros(1, dtype=[('X',np.float32),('Xhat',np.float32),
        ('gstarX',np.float32),('gstarXhat',np.float32),('sqerr',np.float32),('n',np.int)])
    
    result['X'] = 1-np.mean(cross_validation.cross_val_score(knn, X,Y, cv=loo))
    result['Xhat'] = 1-np.mean(cross_validation.cross_val_score(knn, Xhat,Y, cv=loo))
    result['gstarX'] = 1-np.mean(np.equal(X[:,0]>X[:,1],Y))
    result['gstarXhat'] = 1-np.mean(np.equal(Xhat[:,0]>Xhat[:,1],Y))
    result['sqerr'] = np.linalg.norm(X-Xhat,'fro')
    
    result['n'] = rdpg.n_nodes
    
    return result