def test_dist2prox_prox2dist(): """ Test Utils: Prox2Dist & Dist2Prox """ assert np.isclose(dist2prox(prox2dist(P)) , P).all()
from distanceclosure.dijkstra import Dijkstra from distanceclosure.utils import prox2dist import numpy as np import networkx as nx # # Test # # Numpy P = np.array([ [1.,.9,.1,0.], [.9,1.,.8,0.], [.1,.8,1.,.6], [0.,0.,.6,1.], ], dtype=float) D = prox2dist(P) # # Edgelist # edgelist_luis = { ('s','b'):.9, ('s','c'):.1, ('b','c'):.8, ('c','d'):.6, } edgelist_james = { ('s','a'):8, ('s','c'):6, ('s','d'):5, ('a','d'):2, ('a','e'):1,
def test_dist2prox(): """ Test Utils: Dist2Prox """ assert np.isclose(prox2dist(P), D_true).all()
} """ edgelist = { ('s','b'):.9, ('s','c'):.1, ('b','c'):.8, ('c','d'):.6, } """ matrix = np.array([ [1.,.9,.1,0.], [.9,1.,.8,0.], [.1,.8,1.,.6], [0.,0.,.6,1.], ], dtype=float) matrix = prox2dist(matrix) sparse = csr_matrix(matrix) source = 2 # NX #G = nx.from_edgelist(edgelist) G = nx.from_numpy_matrix(matrix) #nx.set_edge_attributes(G, 'weight', edgelist) nx_lenghts = nx.single_source_dijkstra_path_length(G, source=source, weight='weight') nx_paths = nx.single_source_dijkstra_path(G, source=source, weight='weight') d = Dijkstra(verbose=True) #d.from_edgelist(edgelist, directed=False) #d.from_numpy_matrix(matrix, directed=False) d.from_sparse_matrix(sparse, directed=False)