-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathBigCLAM.java
More file actions
106 lines (84 loc) · 2.8 KB
/
Copy pathBigCLAM.java
File metadata and controls
106 lines (84 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ir.urmia.bigclam;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.ProgressTicket;
public class BigCLAM implements org.gephi.statistics.spi.Statistics, LongTask {
private StringBuilder reportSB = new StringBuilder();
private boolean cancel = false;
private int k = 3;
private int iterations = 100;
double[][] adjacencyMatrix;
Node[] nodes = null;
public void createAdjacencyMatrix(Graph g) {
adjacencyMatrix = new double[nodes.length][nodes.length];
for (int i = 0; i < nodes.length; i++) {
Node n1 = nodes[i];
for (int j = 0; j < nodes.length; j++) {
Node n2 = nodes[j];
adjacencyMatrix[i][j] = (g.getEdge(n1, n2) != null || g.getEdge(n2, n1) != null) ?
1 : 0;
}
}
reportSB.append("Adjacency Matrix:\n");
for (double[] row : adjacencyMatrix) {
reportSB.append("\n");
for (double element : row) {
reportSB.append(String.format("%d", (int) element));
reportSB.append(" ");
}
reportSB.delete(reportSB.length() - 3, reportSB.length());
}
}
@Override
public void execute(GraphModel gm) {
Graph g = gm.getGraphVisible();
g.readLock();
nodes = g.getNodes().toArray();
createAdjacencyMatrix(g);
int communitiesCount = k;
int iterationsCount = iterations;
double learningRate = 0.01;
double[][] F = Utils.bigclam(adjacencyMatrix, communitiesCount, iterationsCount, learningRate);
reportSB.append("\n\nF:\n\n");
for (int i = 0; i < F.length; i++) {
double[] row = F[i];
reportSB.append(nodes[i].getLabel());
reportSB.append("\t");
for (double element : row) {
reportSB.append(String.format("%2.2f", element));
reportSB.append(" | ");
}
reportSB.delete(reportSB.length() - 3, reportSB.length());
reportSB.append("\n");
}
g.readUnlock();
}
@Override
public String getReport() {
reportSB.insert(0, "<pre>");
reportSB.append("</pre>");
return reportSB.toString();
}
@Override
public boolean cancel() {
cancel = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket pt) {
}
public int getK() {
return k;
}
public int getIterations() {
return iterations;
}
public void setK(int k) {
this.k = k;
}
public void setIterations(int iterations) {
this.iterations = iterations;
}
}