Esempio n. 1
0
double cc(const MLNetworkSharedPtr& mnet, const NodeSharedPtr& node) {
	int num_edges = 0;
    NodeListSharedPtr neigh = mnet->neighbors(node,INOUT);
    int num_neigh = neigh->size();
    if (num_neigh<=1) return 0.0;
    
	for (NodeSharedPtr n1: *neigh) {
		for (NodeSharedPtr n2: *neigh) {
            if (n1>=n2) continue;
            if (mnet->get_edge(n1,n2))
				num_edges++;
		}
	}
	return num_edges*2.0/(num_neigh*(num_neigh-1));
}
Esempio n. 2
0
// only works for multiplex networks (no inter-layer edges)
property_matrix<triad,LayerSharedPtr,bool> triangle_existence_property_matrix(const MLNetworkSharedPtr& mnet) {
	long n = mnet->get_actors()->size();
	property_matrix<triad,LayerSharedPtr,bool> P(n*(n-1)*(n-2)/6,mnet->get_layers()->size(),false);
	for (LayerSharedPtr layer: *mnet->get_layers()) {
		hash_set<NodeSharedPtr> processed1;
		for (NodeSharedPtr n1: *mnet->get_nodes(layer)) {
			processed1.insert(n1);
			hash_set<NodeSharedPtr> processed2;
			for (NodeSharedPtr n2: *mnet->neighbors(n1,INOUT)) {
				if (processed1.count(n2)>0) continue;
				processed2.insert(n2);
				for (NodeSharedPtr n3: *mnet->neighbors(n2,INOUT)) {
					if (processed1.count(n3)>0) continue;
					if (processed2.count(n3)>0) continue;
					if (mnet->get_edge(n3,n1)) {
						triad t(n1->actor,n2->actor,n3->actor);
						P.set(t,layer,true);
					}
				}
			}
		}
	}
	return P;
}