curquht
03-11-2008, 05:38 PM
This question is for anyone who is an experienced Splus programmer. I am a masters student in statistics and I am having a coding problem.
Suppose that N nodes can each be in one of K groups, and that g[1:N] is a vector which contains the group memberships.
example with n=20 nodes and k=4 groups:
3 1 4 2 4 4 1 2 4 4 2 3 3 1 2 3 3 3 1 2
so node 1 belongs to group 3, node 2 to group 1, node 3 to group 4 and so on...
For a given index I calculate what is called a modularity score (this isn't really important for you to understand). The goal is to achieve the highest possible modularity score for this index (modularity is a value between 0 and 1). If I get a low value, I need to make a change to the index by changing the group membership of a group of nodes. So for example changing the group membership of all nodes in group 1 to one of the other groups. This is where I'm having trouble coding.
To illustrate what I need the code to do, I will continue on with the above example:
suppose the modularity score for the above index is .2113, but I know that a higer score can be achieved. I would first like to change the group membership of all the nodes in group 1 to group 2, calculate the modularity for this "new" index and save the value in a vector. I then change the group membership of the nodes in group 1 to that of group 3 and calculate the "new" index's modularity score and save that in the same vector. Once I have done this with all of the existing groups, I will take the index that gave the highest modularity score.
so to re-iterate, if there are 4 groups i need the loop to change the group memberships in the following ways:
1 -> 2 calculate and save modularity score
1 -> 3 ''
1 -> 4 ''
2 -> 3 ''
2 -> 4 ''
3 -> 4 ''
if this is the vector of modularity scores c(mod1, mod2, mod3, mod4, mod5, mod6), then we go with the index that gave the highest mod score.
**Note that if I've already calculated the modularity score for 1 -> 2 that I do not need the modularity score for 2 -> 1.
I know that this is not the best pseudo-code to go by, but if someone has any ideas of how I can code this, it would be a huge help.
Thanks so much!
curquht
Suppose that N nodes can each be in one of K groups, and that g[1:N] is a vector which contains the group memberships.
example with n=20 nodes and k=4 groups:
3 1 4 2 4 4 1 2 4 4 2 3 3 1 2 3 3 3 1 2
so node 1 belongs to group 3, node 2 to group 1, node 3 to group 4 and so on...
For a given index I calculate what is called a modularity score (this isn't really important for you to understand). The goal is to achieve the highest possible modularity score for this index (modularity is a value between 0 and 1). If I get a low value, I need to make a change to the index by changing the group membership of a group of nodes. So for example changing the group membership of all nodes in group 1 to one of the other groups. This is where I'm having trouble coding.
To illustrate what I need the code to do, I will continue on with the above example:
suppose the modularity score for the above index is .2113, but I know that a higer score can be achieved. I would first like to change the group membership of all the nodes in group 1 to group 2, calculate the modularity for this "new" index and save the value in a vector. I then change the group membership of the nodes in group 1 to that of group 3 and calculate the "new" index's modularity score and save that in the same vector. Once I have done this with all of the existing groups, I will take the index that gave the highest modularity score.
so to re-iterate, if there are 4 groups i need the loop to change the group memberships in the following ways:
1 -> 2 calculate and save modularity score
1 -> 3 ''
1 -> 4 ''
2 -> 3 ''
2 -> 4 ''
3 -> 4 ''
if this is the vector of modularity scores c(mod1, mod2, mod3, mod4, mod5, mod6), then we go with the index that gave the highest mod score.
**Note that if I've already calculated the modularity score for 1 -> 2 that I do not need the modularity score for 2 -> 1.
I know that this is not the best pseudo-code to go by, but if someone has any ideas of how I can code this, it would be a huge help.
Thanks so much!
curquht