资源简介
社区发现算法Louvain,运算速度非常快,只需要计算相邻结点社区变换Q的变换。贪婪优化
代码片段和文件信息
package 社区发现1;
import java.io.*;
import java.util.*;
public class DataSet {
double weight[][];
linkedList neighborlist[];
double totalEdgeWeights = 0;
int nodecount;
double nodeweight[];
DataSet(String filename) throws IOException
{
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line = reader.readLine();
nodecount = Integer.parseInt(line); //读文件,文件第一行为节点的数量
weight = new double[nodecount][nodecount];
neighborlist = new linkedList[nodecount];
for(int i=0 ;i < nodecount;i++)
neighborlist[i] = new linkedList();
nodeweight = new double[nodecount];
for(int i=0;i nodeweight[i] = 0;
while((line = reader.readLine())!=null)
{
String args[] =line.split(“\t“);
int node1 =Integer.parseInt(args[0]);
int node2 = Integer.parseInt(args[1]);
if(node1 != node2)
{
neighborlist[node1].add(node2);
neighborlist[node2].add(node1);
}
if(args.length > 2)
{
double we =Double.parseDouble(args[2]);
weight[node1][node2] = we;
weight[node2][node1] = we;
totalEdgeWeights += we;
nodeweight[node1] += we;
if(node2 != node1)
nodeweight[node2] += we;
}
else
{
weight[node1][node2] = 1;
weight[node2][node1] = 1;
totalEdgeWeights += 1;
nodeweight[node1] += 1;
if(node2 != node1)
nodeweight[node2] += 1;
}
}
reader.close();
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-18 15:48 Louvain\
文件 2002 2018-12-14 21:53 Louvain\DataSet.java
文件 3755 2019-01-16 10:48 Louvain\Main.java
文件 16719 2019-01-07 22:01 Louvain\NetWork.java
评论
共有 条评论