igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] how to increment reciprocity


From: Simone Gabbriellini
Subject: Re: [igraph] how to increment reciprocity
Date: Wed, 28 Jan 2009 11:41:42 +0100

At the beginning of the cycle the reciprocity of the graph is .88 and
at the end the reciprocity falls to .50...

the fact is that there are some "beginners" (node with low experience)
when I start. Those node are isolates... I want to evolve the network
in order to link those nodes, mantaining the reciprocity level more or
less at .80 (which is what I have empirically)

my logic is that beginners node links to master node (high
experience), and master node reciprocate beginners, because of the
fact that this often happens online (just like now...:)

but something happens somewhere and the reciprocity level falls down to .50

This is all the code:

        # build links
        def make_link(self):
                random.shuffle(self.agentset)
                for node in self.agentset:
                        # those node won't make a single post in the simulated 
period
                        if g.vs[node]['postProbability'] == 0:
                                eids = g.adjacent(node, type="ALL")
                                g.delete_edges(eids)
                                self.agentset.remove(node)
                        # if they are going to make a post
                        if random.random() < 
self.SNA.network.vs[node]['postProbability']:
                                numberNovice = 10
                                numberMaster = 80
                                nei_vertex = g.neighbors(node, type="in")
                                # if it's not isolated
                                if len(nei_vertex) > 0:
                                        # if it's a beginner:
                                        if g.vs[node]["experience"] <= 
numberNovice:
                                                selectedNodeId = 
self.pickupGT(numberMaster, self.agentset)
                                                self.do_link(node, 
selectedNodeId)
                                        # if it's a master:
                                        if 
self.SNA.network.vs[node]["experience"] >= numberMaster:
                                                # reciprocate beginner
                                                selectedNodeId = 
self.pickupLT(numberNovice, self.agentset)
                                                self.do_link(node, 
selectedNodeId)
                                        # if node is more than a beginner but 
less than a master
                                        if (g.vs[node]["experience"] >= 
numberNovice) and
(g.vs[node]["experience"] <= numberMaster):
                                                # reciprocates one of its 
neighbors
                                                selectedNodeId = 
self.pickupEQ(nei_vertex)
                                                self.do_link(node, 
selectedNodeId)
                                # if it's isolated looks for a master to link 
with
                                else:
                                        selectedNodeId = 
self.pickupGT(numberMaster, self.agentset)
                                        self.do_link(node, selectedNodeId)

                        print "Done with node ", node
                # update experience after one "day" in the model life
                self.weight_dict = dict(zip(self.SNA.network.get_edgelist(),
self.SNA.network.es["weight"]))
                self.findExperience()

        #
        def pickupGT(self, numberMaster, agentset):
                selectedNodeId = random.sample(agentset, 1)[0]
                if g.vs[selectedNodeId]["experience"] >= numberMaster:
                        return selectedNodeId
                else:
                        return self.pickupGT(numberMaster, agentset)

        #
        def pickupLT(self, numberNovice, agentset):
                selectedNodeId = random.sample(agentset, 1)[0]
                if g.vs[selectedNodeId]["experience"] <= numberNovice:
                        return selectedNodeId
                else:
                        return self.pickupGT(numberNovice, agentset)

        #
        def pickupEQ(self, nei_vertex):
                selectedNodeId = random.sample(nei_vertex, 1)[0]
                return selectedNodeId
                
        #
        def do_link(self, node, selectedNodeId):
                try:
                        eid = g.get_eid(node, selectedNodeId)                   
                except:
                        max_edge_id = self.SNA.network.ecount()
                        g.add_edges((node, selectedNodeId))
                        g.es[max_edge_id]["color"] = "orange"
                        g.es[max_edge_id]["weight"] = 1
                else:
                        g.es[eid]["weight"] += 1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]