Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigCLAM plugin for Gephi #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 102 additions & 188 deletions README.md

Large diffs are not rendered by default.

Binary file added Resources/BigCLAMConfig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/BigCLAMResult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/BigCLAM_Result_Probabilities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modules/BigCLAM/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

79 changes: 79 additions & 0 deletions modules/BigCLAM/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>gephi-plugin-parent</artifactId>
<groupId>org.gephi</groupId>
<version>0.10.0</version>
</parent>

<groupId>ir.urmia</groupId>
<artifactId>bigclam</artifactId>
<version>1.0.0</version>
<packaging>nbm</packaging>

<name>Big CLAM Plugin for Gephi</name>

<dependencies>
<!-- Insert dependencies here -->
<dependency>
<groupId>org.gephi</groupId>
<artifactId>gephi-toolkit</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>RELEASE160</version>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>utils-longtask</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>graph-api</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>statistics-api</artifactId>
<version>0.10.0</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<licenseName>Apache 2.0</licenseName>
<author>Mir Saman Tajbakhsh, Ebrahim Shami</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://mstajbakhsh.ir</authorUrl>
<sourceCodeUrl>https://github.com/mirsamantajbakhsh/BigCLAM.git</sourceCodeUrl>
<publicPackages>
<!-- Insert public packages -->
</publicPackages>
</configuration>
</plugin>
</plugins>
</build>

<!-- Snapshot Repositories (only needed if developing against a SNAPSHOT version) -->
<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>


106 changes: 106 additions & 0 deletions modules/BigCLAM/src/main/java/ir/urmia/bigclam/BigCLAM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}

}
26 changes: 26 additions & 0 deletions modules/BigCLAM/src/main/java/ir/urmia/bigclam/Builder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

package ir.urmia.bigclam;

import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = StatisticsBuilder.class)
public class Builder implements StatisticsBuilder {

@Override
public String getName() {
return "BigCLAM";
}

@Override
public Statistics getStatistics() {
return new BigCLAM();
}

@Override
public Class<? extends Statistics> getStatisticsClass() {
return BigCLAM.class;
}

}
67 changes: 67 additions & 0 deletions modules/BigCLAM/src/main/java/ir/urmia/bigclam/Panel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

package ir.urmia.bigclam;

import javax.swing.*;
import java.awt.*;


public class Panel extends JPanel {

private JTextField iterationsValue;
private JTextField kValue;
public Panel() {
JPanel panel = this;
panel.setPreferredSize(new Dimension(300, 100));

JLabel labelK = new JLabel("Number of communities:");
JLabel labelIterations = new JLabel("Number of iterations:");
kValue = new JTextField();
iterationsValue = new JTextField();

labelK.setAlignmentX(0.0f);
kValue.setAlignmentX(0.0f);
labelIterations.setAlignmentX(0.0f);
iterationsValue.setAlignmentX(0.0f);

this.add(labelK);
this.add(kValue);
this.add(labelIterations);
this.add(iterationsValue);

BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS);
panel.setLayout(layout);

panel.add(labelK);
panel.add(kValue);
panel.add(labelIterations);
panel.add(iterationsValue);
}

public int getK() {
int i = 0;
try {
i = Integer.valueOf(kValue.getText());
} catch (Exception ex) {
return 0;
}
return i;
}

public void setK(int k) {
this.kValue.setText(String.valueOf(k));
}

public void setIterations(int i) {
this.iterationsValue.setText(String.valueOf(i));
}

public int getIterations() {
int i = 0;
try {
i = Integer.valueOf(iterationsValue.getText());
} catch (Exception ex) {
return 0;
}
return i;
}
}
69 changes: 69 additions & 0 deletions modules/BigCLAM/src/main/java/ir/urmia/bigclam/UI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

package ir.urmia.bigclam;

import javax.swing.JPanel;

import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsUI;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = StatisticsUI.class)
public class UI implements StatisticsUI {
private Panel panel;
private BigCLAM myMetric;

@Override
public JPanel getSettingsPanel() {
panel = new Panel();
return panel;
}

@Override
public void setup(Statistics ststcs) {
this.myMetric = (BigCLAM) ststcs;
if (panel != null) {
panel.setK(myMetric.getK());
panel.setIterations(myMetric.getIterations());
}
}

@Override
public void unsetup() {
if (panel != null) {
myMetric.setK(panel.getK());
myMetric.setIterations(panel.getIterations());
}
panel = null;
}

@Override
public Class<? extends Statistics> getStatisticsClass() {
return BigCLAM.class;
}

@Override
public String getValue() {
return null;
}

@Override
public String getDisplayName() {
return "BigCLAM";
}

@Override
public String getShortDescription() {
return "BigCLAM Algorithm";
}

@Override
public String getCategory() {
return CATEGORY_NETWORK_OVERVIEW;
}

@Override
public int getPosition() {
return 800;
}

}
Loading