def resistance_distance(self, other_kg, **kwargs):
        """ A NetComp operation returning the resistance distance between `self` and `other_kg`.
        See NetComp's docs for keyword arguments: https://github.com/peterewills/NetComp/blob/master/netcomp/distance/exact.py#L225

        :param other_kg: The other knowledge graph
        :type other_kg: :class:`.KnowledgeGraph`

        :return: The resistance distance of `self` and `other_kg`. If the kwarg `attributed` is True (default=False),
            then the vector distance per node is returned
        :rtype: float, :class:`numpy.array`
        """
        A, B = make_adjacency_matrices(self, other_kg)
        return nc.resistance_distance(A, B, **kwargs)
예제 #2
0
G = nx.grid_2d_graph(N, M)
deg_seq = [item[1] for item in G.degree_iter()]

####################################
## DEFINE IMPORTANT FUNCTIONS
####################################


def distance(dist_func, A, B):
    return dist_func(A, B)


lambda_adj = lambda A1, A2: nc.lambda_dist(A1, A2, kind="adjacency")
lambda_lap = lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian")
lambda_nlap = lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian_norm")
res_dist = lambda A1, A2: nc.resistance_distance(A1, A2, check_connected=False)

distances = [
    nc.edit_distance,
    res_dist,
    nc.deltacon0,
    nc.netsimile,
    lambda_adj,
    lambda_lap,
    lambda_nlap,
]
labels = [
    "Edit",
    "Resistance Dist.",
    "DeltaCon",
    "NetSimile",
    if n != m:
        raise ValueError("Input matrix must be square.")
    inds = list(range(n))
    random.shuffle(inds)
    A_shuff = A[np.ix_(inds, inds)]
    return A_shuff


def distance(dist_func, A, B):
    return dist_func(A, B)


lambda_adj = lambda A1, A2: nc.lambda_dist(A1, A2, kind="adjacency")
lambda_lap = lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian")
lambda_nlap = lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian_norm")
res_dist = lambda A1, A2: nc.resistance_distance(A1, A2, renormalized=True)

distances = [
    nc.edit_distance,
    res_dist,
    nc.deltacon0,
    nc.netsimile,
    lambda_adj,
    lambda_lap,
    lambda_nlap,
]
labels = [
    "Edit",
    "Resistance Dist. (Renormalized)",
    "DeltaCon",
    "NetSimile",
예제 #4
0
파일: test.py 프로젝트: nwlandry/NetComp
# A trivial example, for now

import netcomp as nc
import networkx as nx

# use networkx to build a sample graph
G0 = nx.complete_graph(10)
G1 = G0.copy()
G1.remove_edge(1, 0)
G2 = G0.copy()
G2.remove_node(0)
A, B, C = [nx.adjacency_matrix(G) for G in [G0, G1, G2]]

# matrix distances
nc.resistance_distance(A, B)
nc.edit_distance(A, B)
nc.deltacon0(A, B)
nc.vertex_edge_distance(A, B)
# spectral distances
nc.lambda_dist(A, C)
nc.lambda_dist(A, C, kind='adjacency', k=2)
nc.lambda_dist(A, C, kind='laplacian_norm')
# other distances
nc.resistance_distance(A, C, renormalized=True)
nc.netsimile(A, C)
# matrices w/o associated distances
nc.commute_matrix(A)
nc.conductance_matrix(A)