std::string beta_transition::fire(MLNetworkSharedPtr& mnet, const NodeSharedPtr& node, long time) { std::string current_status = mnet->actor_features()->getString(node->actor->id,_S_current); if (current_status==status) { for (NodeSharedPtr n: mnet->neighbors(node,IN)) { if (mnet->actor_features()->getString(n->actor->id,_S_current)==neighbor_status && test(beta)) { return new_status; } } } return ""; }
property_matrix<ActorSharedPtr,LayerSharedPtr,double> actor_degree_property_matrix(const MLNetworkSharedPtr& mnet, edge_mode mode) { property_matrix<ActorSharedPtr,LayerSharedPtr,double> P(mnet->get_actors()->size(),mnet->get_layers()->size(),0); for (ActorSharedPtr actor: *mnet->get_actors()) { for (LayerSharedPtr layer: *mnet->get_layers()) { NodeSharedPtr node = mnet->get_node(actor,layer); if (!node) P.set_na(actor,layer); else P.set(actor,layer,mnet->neighbors(node,mode)->size()); } } return P; }
double relevance(const MLNetworkSharedPtr& mnet, const ActorSharedPtr& actor, const LayerSharedPtr& layer, edge_mode mode) { set<actor_id> neighbors_on_selected_layers; set<actor_id> all_neighbors; for (NodeSharedPtr node: *mnet->get_nodes(actor)) { for (NodeSharedPtr neighbor: *mnet->neighbors(node, mode)) { all_neighbors.insert(neighbor->actor->id); if (layer == neighbor->layer) neighbors_on_selected_layers.insert(neighbor->actor->id); } } if (all_neighbors.size()==0) return 0; // by definition else return (double)neighbors_on_selected_layers.size()/all_neighbors.size(); }
// 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; }
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)); }
double xrelevance(const MLNetworkSharedPtr& mnet, const ActorSharedPtr& actor, const std::unordered_set<LayerSharedPtr>& layers, edge_mode mode) { set<actor_id> neighbors_on_selected_layers; set<actor_id> neighbors_on_other_layers; set<actor_id> all_neighbors; for (NodeSharedPtr node: *mnet->get_nodes(actor)) { for (NodeSharedPtr neighbor: *mnet->neighbors(node, mode)) { all_neighbors.insert(neighbor->actor->id); if (layers.count(neighbor->layer)>0) neighbors_on_selected_layers.insert(neighbor->actor->id); else neighbors_on_other_layers.insert(neighbor->actor->id); } } if (all_neighbors.size()==0) return 0; // by definition else { for (actor_id actor: neighbors_on_other_layers) neighbors_on_selected_layers.erase(actor); return (double)neighbors_on_selected_layers.size()/all_neighbors.size(); } }