我需要在一个小图上计算模块化,我偶然发现了这个项目,它提供了一个计算 Newman 模块化分数的类。但是,该方法需要一个模块成员资格:
public static <V,E,M> double computeModularity (Graph<V,E> g,Transformer<V,M> moduleMembership)
所以我的问题是:有没有比这更好的方法来为我的节点分配成员资格?
// assuming I have a Graph<Person, String> thisNet
EdgeBetweennessClusterer<Person, String> edgeBetweennessClusterer = new EdgeBetweennessClusterer<>(1);
Set<Set<Person>> clusters = edgeBetweennessClusterer.transform(thisNet);
int membership = 0;
for (Set s : clusters) {
for (Iterator it = s.iterator(); it.hasNext();) {
Person inset = (Person) it.next();
inset.membership = membership;
}
membership++;
}
然后我将应用一个变压器,如:
Transformer<Person, Integer> componentMembership = new Transformer<Person, Integer>() {
@Override
public Integer transform(Person s) {
return s.membership;
}
};