def initial_dist_sim_pairs_with_netcomp(self, gs1, gs2):
        if logging_enabled == True:
            print(
                "- Entered dist_sim_calculator::DistSimCalculator::initial_dist_sim_pairs_with_netcomp Public Method"
            )

        m = len(gs1)
        n = len(gs2)
        print("m: ", m, ", n: ", n)

        dist_mat = np.zeros((m, n))
        for i in range(m):
            for j in range(n):
                g1 = gs1[i]
                g2 = gs2[j]
                adj1, adj2 = [nx.adjacency_matrix(G) for G in [g1, g2]]

                # print("nx.info(g1): ", nx.info(g1))
                # print("nx.info(g2): ", nx.info(g2))

                gid1 = g1.graph['gid']
                gid2 = g2.graph['gid']
                pair = (gid1, gid2)

                # d = nc.lambda_dist(adj1,adj2,kind='laplacian',k=10)
                d = nc.lambda_dist(adj1, adj2, kind='adjacency', k=10)

                self.gidpair_ds_map[pair] = d
                print('Adding entry ({}, {}) to dist map'.format(pair, d))

        save(self.sfn, self.gidpair_ds_map)
        print('Saved to {}'.format(self.sfn))
    def lambda_dist(self, other_kg, **kwargs):
        """ A NetComp operation returning the lambda distance between `self` and `other_kg`.
        This operation is very complicated and is better described by NetComp's docs: https://github.com/peterewills/NetComp/blob/master/netcomp/distance/exact.py#L123

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

        :return: The lambda distance between `self` and `other_kg`
        :rtype: float
        """
        A, B = make_adjacency_matrices(self, other_kg)
        return nc.lambda_dist(A, B, **kwargs)
Esempio n. 3
0
def return_lambdas(k):
    return [
        lambda A1, A2: nc.lambda_dist(A1, A2, kind="adjacency", k=k),
        lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian", k=k),
        lambda A1, A2: nc.lambda_dist(A1, A2, kind="laplacian_norm", k=k),
    ]
Esempio n. 4
0
N = 100
M = 10\

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",
num_cores = multiprocessing.cpu_count()
# size of ensemble
ensemble_len = 500
threshold = 0.5
ones = True


####################################
## 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')


lambda_adj_5 = lambda A1,A2: nc.lambda_dist(A1,A2,kind='adjacency')
lambda_lap_5 = lambda A1,A2: nc.lambda_dist(A1,A2,kind='laplacian')
lambda_nlap_5 = 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,lambda_adj_5,lambda_lap_5,
             lambda_nlap_5]
labels = ['Edit','Resistance Dist.','DeltaCon','NetSimile',
          'Lambda (Adjacency)','Lambda (Laplacian)',
Esempio n. 6
0
# 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)