From 8639302ba28784827c6a0a530002355d72a27500 Mon Sep 17 00:00:00 2001
From: Konstantinos Koutsilis <50744802+koutsilis1999@users.noreply.github.com>
Date: Tue, 22 Nov 2022 22:35:45 +0000
Subject: [PATCH] Cleanup (#2)
* final args and logger
* rm comments
* add author javadoc
* rename variables
* rm redundant constructor
* add logger
* bump version
---
README.md | 2 +-
pom.xml | 2 +-
src/main/java/com/kkoutsilis/App.java | 31 +++--
.../algorithms/ClusteringAlgorithm.java | 3 +
.../java/com/kkoutsilis/algorithms/HCNN.java | 123 +++++++++---------
.../helpers/ClustersAndOutliers.java | 4 +-
.../algorithms/helpers/CorePair.java | 9 +-
.../kkoutsilis/algorithms/helpers/MSP.java | 3 +
.../algorithms/helpers/PairSim.java | 9 +-
.../java/com/kkoutsilis/graphs/Graph.java | 9 +-
.../java/com/kkoutsilis/graphs/Vertex.java | 9 +-
.../quality_measures/QualityMeasure.java | 3 +
.../SilhouetteCoefficient.java | 3 +
.../com/kkoutsilis/sets/DisjointSets.java | 4 +-
src/main/java/com/kkoutsilis/sets/Node.java | 3 +
.../com/kkoutsilis/sets/Representative.java | 9 +-
.../com/kkoutsilis/utilities/CsvHandler.java | 11 +-
.../com/kkoutsilis/utilities/Distance.java | 8 +-
.../utilities/NearestNeighbour.java | 5 +-
19 files changed, 151 insertions(+), 99 deletions(-)
diff --git a/README.md b/README.md
index 5519c4b..13b9266 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ It requires 6 arguments in this order.
Example:
```bash
-$ java −jar SACT−1.0−SNAPSHOT.jar ./exp1.csv ./res.csv 3 1 1 2
+$ java −jar SACT−1.1−SNAPSHOT.jar ./exp1.csv ./res.csv 3 1 1 2
```
It will print the created clusters in the console as well as create a csv file with the clusters.
diff --git a/pom.xml b/pom.xml
index 3a751e2..db37b2b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.kkoutsilis
SACT
- 1.0-SNAPSHOT
+ 1.1-SNAPSHOT
SACT
diff --git a/src/main/java/com/kkoutsilis/App.java b/src/main/java/com/kkoutsilis/App.java
index 811ea19..fff8a08 100644
--- a/src/main/java/com/kkoutsilis/App.java
+++ b/src/main/java/com/kkoutsilis/App.java
@@ -1,5 +1,11 @@
package com.kkoutsilis;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import com.kkoutsilis.algorithms.ClusteringAlgorithm;
import com.kkoutsilis.algorithms.HCNN;
import com.kkoutsilis.graphs.Graph;
@@ -8,18 +14,18 @@
import com.kkoutsilis.utilities.CsvHandler;
import com.kkoutsilis.utilities.NearestNeighbour;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+/**
+ * @author kkoutsilis
+ */
public class App {
public static void main(String[] args) throws Exception {
- String inputFilePath = args[0];
- String outputFilePath = args[1];
- int k = Integer.parseInt(args[2]);
- int fistNearestNeighbourAlgorithm = Integer.parseInt(args[3]);
- int secondNearestNeighbourAlgorithm = Integer.parseInt(args[4]);
- int n = Integer.parseInt(args[5]);
+ final Logger logger = Logger.getLogger(App.class.getName());
+ final String inputFilePath = args[0];
+ final String outputFilePath = args[1];
+ final int k = Integer.parseInt(args[2]);
+ final int fistNearestNeighbourAlgorithm = Integer.parseInt(args[3]);
+ final int secondNearestNeighbourAlgorithm = Integer.parseInt(args[4]);
+ final int n = Integer.parseInt(args[5]);
long startTime = System.nanoTime();
@@ -70,9 +76,10 @@ public static void main(String[] args) throws Exception {
s.forEach(v -> System.out.print(v.getLabel() + " "));
System.out.println();
}
- System.out.println("Clustering execution time in milliseconds: " + elapsedTime / 1000000);
+ logger.log(Level.INFO,
+ () -> "Clustering execution time in milliseconds: " + elapsedTime / 1000000);
SilhouetteCoefficient quality = new SilhouetteCoefficient(result, graph);
- System.out.printf("Silhouette Coefficient: %.03f", quality.calculate());
+ logger.log(Level.INFO, () -> String.format("Silhouette Coefficient: %.03f", quality.calculate()));
}
}
diff --git a/src/main/java/com/kkoutsilis/algorithms/ClusteringAlgorithm.java b/src/main/java/com/kkoutsilis/algorithms/ClusteringAlgorithm.java
index cbd3244..8ef4085 100644
--- a/src/main/java/com/kkoutsilis/algorithms/ClusteringAlgorithm.java
+++ b/src/main/java/com/kkoutsilis/algorithms/ClusteringAlgorithm.java
@@ -5,6 +5,9 @@
import java.util.List;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public interface ClusteringAlgorithm {
List> fit() throws Exception;
}
diff --git a/src/main/java/com/kkoutsilis/algorithms/HCNN.java b/src/main/java/com/kkoutsilis/algorithms/HCNN.java
index 777205f..b7af10b 100644
--- a/src/main/java/com/kkoutsilis/algorithms/HCNN.java
+++ b/src/main/java/com/kkoutsilis/algorithms/HCNN.java
@@ -10,20 +10,23 @@
import com.kkoutsilis.utilities.Distance;
import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
-
+/**
+ * @author kkoutsilis
+ */
public class HCNN implements ClusteringAlgorithm {
private Graph graph;
private List indexes;
- private List G;
+ private List data;
private int n;
private Map> fistNnAlgorithm;
private Map> secondNnAlgorithm;
+ private final Logger logger = Logger.getLogger(HCNN.class.getName());
- public HCNN() {
- }
-
- public HCNN(Graph graph, int n, Map> fistNnAlgorithm, Map> secondNnAlgorithm) {
+ public HCNN(Graph graph, int n, Map> fistNnAlgorithm,
+ Map> secondNnAlgorithm) {
this.graph = graph;
this.n = n;
this.fistNnAlgorithm = fistNnAlgorithm;
@@ -32,76 +35,71 @@ public HCNN(Graph graph, int n, Map> fistNnAlgorithm, Map(this.graph.getVertices().keySet());
+ this.data = new ArrayList<>(this.graph.getVertices().keySet());
}
@Override
public List> fit() throws Exception {
+ this.logger.log(Level.INFO, "Fitting...");
ClustersAndOutliers clustersAndOutliers = this.initializeClustering();
- List> C = clustersAndOutliers.getClusters();
- Set D = clustersAndOutliers.getOutliers();
+ List> clusters = clustersAndOutliers.getClusters();
+ Set outliers = clustersAndOutliers.getOutliers();
- while (C.size() > this.n) {
- int L = C.size();
- // line 4
- float tmax = 0;
- for (int i = 0; i < L; i++) {
- for (int j = i + 1; j < L; j++) {
- float similarity = sim(C.get(i), C.get(j));
- if (tmax < similarity) {
- tmax = similarity;
+ while (clusters.size() > this.n) {
+ int l = clusters.size();
+ float tMax = 0;
+ for (int i = 0; i < l; i++) {
+ for (int j = i + 1; j < l; j++) {
+ float similarity = sim(clusters.get(i), clusters.get(j));
+ if (tMax < similarity) {
+ tMax = similarity;
}
}
}
- // line 5
- if (tmax == 0) {
+ if (tMax == 0) {
break;
}
- // line 7
Set msp = new LinkedHashSet<>();
- for (int i = 0; i < L; i++) {
- for (int j = i + 1; j < L; j++) {
- float similarity = sim(C.get(i), C.get(j));
- if (similarity == tmax) {
+ for (int i = 0; i < l; i++) {
+ for (int j = i + 1; j < l; j++) {
+ float similarity = sim(clusters.get(i), clusters.get(j));
+ if (similarity == tMax) {
msp.add(new MSP(i, j));
}
}
}
- // line 8-10
- DisjointSets DS = new DisjointSets();
- for (Set vertices : C) {
- DS.makeSet(vertices);
+ DisjointSets disjointSets = new DisjointSets();
+ for (Set vertices : clusters) {
+ disjointSets.makeSet(vertices);
}
- // line 11-12
for (MSP msp1 : msp) {
int i = msp1.getI();
int j = msp1.getJ();
- DS.union(C.get(i), C.get(j));
+ disjointSets.union(clusters.get(i), clusters.get(j));
}
- // line 13-16
- for (int i = 0; i < L; i++) {
- int index = DS.findSet(C.get(i));
- Set repr = DS.getRepresentative(index).getHead().getData();
- if (repr != C.get(i)) {
- repr.addAll(C.get(i));
- C.set(i, Collections.emptySet());
+ for (int i = 0; i < l; i++) {
+ int index = disjointSets.findSet(clusters.get(i));
+ Set repr = disjointSets.getRepresentative(index).getHead().getData();
+ if (repr != clusters.get(i)) {
+ repr.addAll(clusters.get(i));
+ clusters.set(i, Collections.emptySet());
}
}
- // line 17-20
- List> Ctemp = new ArrayList<>(C);
- C = new ArrayList<>();
- for (Set c : Ctemp) {
+ List> tempClusters = new ArrayList<>(clusters);
+ clusters = new ArrayList<>();
+ for (Set c : tempClusters) {
if (!c.isEmpty()) {
- C.add(c);
+ clusters.add(c);
}
}
}
- C = assignOutliers(C, D);
+ clusters = assignOutliers(clusters, outliers);
- return C;
+ return clusters;
}
private List> assignOutliers(List> clusters, Set outliers) {
+ this.logger.log(Level.INFO, "Assigning outliers...");
float[] label = new float[this.indexes.size() + 1];
Set loners = new HashSet<>();
for (int i = 0; i <= this.indexes.size(); i++) {
@@ -150,7 +148,7 @@ private List> assignOutliers(List> clusters, Set
}
private ClustersAndOutliers initializeClustering() {
- // initializing
+ this.logger.log(Level.INFO, "Initializing clusters...");
int nOfIndexes = this.indexes.size();
CorePair[] corePairs = new CorePair[nOfIndexes];
int[] label = new int[nOfIndexes];
@@ -162,8 +160,7 @@ private ClustersAndOutliers initializeClustering() {
Set outliers = new LinkedHashSet<>();
float[][] structSimZ = new float[nOfIndexes][nOfIndexes];
- // lines 2-7
- for (Vertex i : this.G) {
+ for (Vertex i : this.data) {
Set Q = this.fistNnAlgorithm.get(i);
Set tmp = new HashSet<>(this.fistNnAlgorithm.get(i));
for (Vertex j : tmp) {
@@ -174,12 +171,11 @@ private ClustersAndOutliers initializeClustering() {
}
}
- // line 8
List pairSims = new ArrayList<>();
for (int i = 0; i < nOfIndexes; i++) {
for (int j = i + 1; j < nOfIndexes; j++) {
- Vertex vI = this.G.get(i);
- Vertex vJ = this.G.get(j);
+ Vertex vI = this.data.get(i);
+ Vertex vJ = this.data.get(j);
float structSim = z(vI, vJ);
if (structSim > 0) {
pairSims.add(new PairSim(vI.getLabel(), vJ.getLabel(), structSim));
@@ -195,14 +191,14 @@ private ClustersAndOutliers initializeClustering() {
int j = pairSim.getJ() - 1;
if (label[i] == 0 && label[j] == 0) {
last += 1;
- label[i] = label[j] = last;// Not sure about that, line 14
+ label[i] = label[j] = last;
corePairs[last] = new CorePair(i, j);
- Vertex vI = this.G.get(i);
- Vertex vJ = this.G.get(j);
+ Vertex vI = this.data.get(i);
+ Vertex vJ = this.data.get(j);
Set union = new LinkedHashSet<>(fistNnAlgorithm.get(vI));
union.addAll(this.fistNnAlgorithm.get(vJ));
for (Vertex u : union) {
- int ui = this.G.indexOf(u); // wrong ??
+ int ui = this.data.indexOf(u);
if (label[ui] == 0) {
label[ui] = last;
}
@@ -211,14 +207,14 @@ private ClustersAndOutliers initializeClustering() {
int h = corePair.getI();
int k = corePair.getJ();
- Vertex vuI = this.G.get(ui);
+ Vertex vuI = this.data.get(ui);
float max = z(vuI, vI);
float temp = z(vuI, vJ);
if (max < temp) {
max = temp;
}
- Vertex vH = this.G.get(h);
- Vertex vK = this.G.get(k);
+ Vertex vH = this.data.get(h);
+ Vertex vK = this.data.get(k);
float min = z(vuI, vH);
temp = z(vuI, vK);
@@ -234,13 +230,12 @@ private ClustersAndOutliers initializeClustering() {
}
}
- // line 23-28
List> clusters = new ArrayList<>();
- for (int i : this.indexes) {
+ for (int i = 0; i <= this.indexes.size(); i++) {
clusters.add(new HashSet<>());
}
for (int i : this.indexes) {
- Vertex vI = this.G.get(i);
+ Vertex vI = this.data.get(i);
if (label[i] > 0) {
clusters.get(label[i]).add(vI);
}
@@ -248,7 +243,7 @@ private ClustersAndOutliers initializeClustering() {
outliers.add(vI);
}
}
- clusters.removeIf(Set::isEmpty); // Not the best but it works for now.
+ clusters.removeIf(Set::isEmpty); // Not the best but works for now.
return new ClustersAndOutliers(clusters, outliers);
}
@@ -292,6 +287,8 @@ private int link(Set clusterA, Set clusterB) {
}
private float sim(Set clusterA, Set clusterB) {
- return ((float) conn(clusterA, clusterB) / (float) (clusterA.size() * clusterB.size())) * ((float) link(clusterA, clusterB) / (float) clusterA.size()) * ((float) link(clusterB, clusterA) / (float) clusterB.size());
+ return ((float) conn(clusterA, clusterB) / (float) (clusterA.size() * clusterB.size()))
+ * ((float) link(clusterA, clusterB) / (float) clusterA.size())
+ * ((float) link(clusterB, clusterA) / (float) clusterB.size());
}
}
diff --git a/src/main/java/com/kkoutsilis/algorithms/helpers/ClustersAndOutliers.java b/src/main/java/com/kkoutsilis/algorithms/helpers/ClustersAndOutliers.java
index df2eac4..ebb2bde 100644
--- a/src/main/java/com/kkoutsilis/algorithms/helpers/ClustersAndOutliers.java
+++ b/src/main/java/com/kkoutsilis/algorithms/helpers/ClustersAndOutliers.java
@@ -1,11 +1,13 @@
package com.kkoutsilis.algorithms.helpers;
-
import com.kkoutsilis.graphs.Vertex;
import java.util.List;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public class ClustersAndOutliers {
private List> clusters;
private Set outliers;
diff --git a/src/main/java/com/kkoutsilis/algorithms/helpers/CorePair.java b/src/main/java/com/kkoutsilis/algorithms/helpers/CorePair.java
index 9a7dfae..a9af4eb 100644
--- a/src/main/java/com/kkoutsilis/algorithms/helpers/CorePair.java
+++ b/src/main/java/com/kkoutsilis/algorithms/helpers/CorePair.java
@@ -2,6 +2,9 @@
import java.util.Objects;
+/**
+ * @author kkoutsilis
+ */
public class CorePair {
private int i;
private int j;
@@ -38,8 +41,10 @@ public void setPair(int i, int j) {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof CorePair)) return false;
+ if (this == o)
+ return true;
+ if (!(o instanceof CorePair))
+ return false;
CorePair corePair = (CorePair) o;
return getI() == corePair.getI() && getJ() == corePair.getJ();
}
diff --git a/src/main/java/com/kkoutsilis/algorithms/helpers/MSP.java b/src/main/java/com/kkoutsilis/algorithms/helpers/MSP.java
index 3681a80..4c7b8aa 100644
--- a/src/main/java/com/kkoutsilis/algorithms/helpers/MSP.java
+++ b/src/main/java/com/kkoutsilis/algorithms/helpers/MSP.java
@@ -1,5 +1,8 @@
package com.kkoutsilis.algorithms.helpers;
+/**
+ * @author kkoutsilis
+ */
public class MSP {
private int i;
private int j;
diff --git a/src/main/java/com/kkoutsilis/algorithms/helpers/PairSim.java b/src/main/java/com/kkoutsilis/algorithms/helpers/PairSim.java
index cfd8517..4d0ae92 100644
--- a/src/main/java/com/kkoutsilis/algorithms/helpers/PairSim.java
+++ b/src/main/java/com/kkoutsilis/algorithms/helpers/PairSim.java
@@ -2,6 +2,9 @@
import java.util.Objects;
+/**
+ * @author kkoutsilis
+ */
public class PairSim {
private int i;
private int j;
@@ -48,8 +51,10 @@ public void setPairSim(int i, int j, float similarity) {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof PairSim)) return false;
+ if (this == o)
+ return true;
+ if (!(o instanceof PairSim))
+ return false;
PairSim pairSim = (PairSim) o;
return getI() == pairSim.getI() && getJ() == pairSim.getJ() && getSimilarity() == pairSim.getSimilarity();
}
diff --git a/src/main/java/com/kkoutsilis/graphs/Graph.java b/src/main/java/com/kkoutsilis/graphs/Graph.java
index a4e40f7..234c2a5 100644
--- a/src/main/java/com/kkoutsilis/graphs/Graph.java
+++ b/src/main/java/com/kkoutsilis/graphs/Graph.java
@@ -5,10 +5,12 @@
import java.util.Map;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public class Graph {
private final Map> vertices;
-
public Graph() {
this.vertices = new HashMap<>();
}
@@ -26,13 +28,14 @@ public void removeVertex(Vertex vertex) {
vertices.remove(vertex);
}
- public void addEdge(Vertex vertex1,Vertex vertex2) {
+ public void addEdge(Vertex vertex1, Vertex vertex2) {
vertices.get(vertex1).add(vertex2);
}
public void removeEdge(Vertex vertex1, Vertex vertex2) {
Set eV1 = vertices.get(vertex1);
- if (eV1 != null) eV1.remove(vertex2);
+ if (eV1 != null)
+ eV1.remove(vertex2);
}
diff --git a/src/main/java/com/kkoutsilis/graphs/Vertex.java b/src/main/java/com/kkoutsilis/graphs/Vertex.java
index 2452922..ec62323 100644
--- a/src/main/java/com/kkoutsilis/graphs/Vertex.java
+++ b/src/main/java/com/kkoutsilis/graphs/Vertex.java
@@ -2,6 +2,9 @@
import java.util.Objects;
+/**
+ * @author kkoutsilis
+ */
public class Vertex {
private int label;
private String schema;
@@ -47,8 +50,10 @@ public String toString() {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Vertex)) return false;
+ if (this == o)
+ return true;
+ if (!(o instanceof Vertex))
+ return false;
Vertex vertex = (Vertex) o;
return getLabel() == vertex.getLabel();
}
diff --git a/src/main/java/com/kkoutsilis/quality_measures/QualityMeasure.java b/src/main/java/com/kkoutsilis/quality_measures/QualityMeasure.java
index ea500fb..c41feb8 100644
--- a/src/main/java/com/kkoutsilis/quality_measures/QualityMeasure.java
+++ b/src/main/java/com/kkoutsilis/quality_measures/QualityMeasure.java
@@ -6,6 +6,9 @@
import java.util.List;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public abstract class QualityMeasure {
final List> clusteringResult;
final Graph graph;
diff --git a/src/main/java/com/kkoutsilis/quality_measures/SilhouetteCoefficient.java b/src/main/java/com/kkoutsilis/quality_measures/SilhouetteCoefficient.java
index 9c2ad1f..db136c6 100644
--- a/src/main/java/com/kkoutsilis/quality_measures/SilhouetteCoefficient.java
+++ b/src/main/java/com/kkoutsilis/quality_measures/SilhouetteCoefficient.java
@@ -9,6 +9,9 @@
import java.util.List;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public class SilhouetteCoefficient extends QualityMeasure {
public SilhouetteCoefficient(List> clusteringResult, Graph graph) {
diff --git a/src/main/java/com/kkoutsilis/sets/DisjointSets.java b/src/main/java/com/kkoutsilis/sets/DisjointSets.java
index e591a1d..a933d7c 100644
--- a/src/main/java/com/kkoutsilis/sets/DisjointSets.java
+++ b/src/main/java/com/kkoutsilis/sets/DisjointSets.java
@@ -1,12 +1,14 @@
package com.kkoutsilis.sets;
-
import com.kkoutsilis.graphs.Vertex;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public class DisjointSets {
private List sets;
diff --git a/src/main/java/com/kkoutsilis/sets/Node.java b/src/main/java/com/kkoutsilis/sets/Node.java
index cd8e1b9..df2789b 100644
--- a/src/main/java/com/kkoutsilis/sets/Node.java
+++ b/src/main/java/com/kkoutsilis/sets/Node.java
@@ -4,6 +4,9 @@
import java.util.Set;
+/**
+ * @author kkoutsilis
+ */
public class Node {
private Set data;
private Node next;
diff --git a/src/main/java/com/kkoutsilis/sets/Representative.java b/src/main/java/com/kkoutsilis/sets/Representative.java
index 4269477..9f55fce 100644
--- a/src/main/java/com/kkoutsilis/sets/Representative.java
+++ b/src/main/java/com/kkoutsilis/sets/Representative.java
@@ -1,12 +1,15 @@
package com.kkoutsilis.sets;
+/**
+ * @author kkoutsilis
+ */
public class Representative {
private Node head;
private Node tail;
- public Representative(){
- this.head=null;
- this.tail=null;
+ public Representative() {
+ this.head = null;
+ this.tail = null;
}
public Node getHead() {
diff --git a/src/main/java/com/kkoutsilis/utilities/CsvHandler.java b/src/main/java/com/kkoutsilis/utilities/CsvHandler.java
index c34f680..33aae08 100644
--- a/src/main/java/com/kkoutsilis/utilities/CsvHandler.java
+++ b/src/main/java/com/kkoutsilis/utilities/CsvHandler.java
@@ -12,6 +12,9 @@
import java.io.IOException;
import java.util.*;
+/**
+ * @author kkoutsilis
+ */
public final class CsvHandler {
private CsvHandler() {
throw new IllegalStateException("Utility class");
@@ -19,8 +22,7 @@ private CsvHandler() {
public static Map> parseCSV(String path) throws IllegalStateException {
Map> vertices = new HashMap<>();
- try (CSVReader reader = new CSVReaderBuilder(new FileReader(path)).withSkipLines(1) // skip the first line, header info
- .build()) {
+ try (CSVReader reader = new CSVReaderBuilder(new FileReader(path)).withSkipLines(1).build()) {
List r = reader.readAll();
for (String[] row : r) {
Vertex v1 = new Vertex(Integer.parseInt(row[2]), row[1], row[3]);
@@ -42,13 +44,14 @@ public static void dumpToCSV(String path, List> data) {
CSVWriter writer = new CSVWriter(outfile);
- String[] header = {"CLUSTER_ID", "SCHEMA", "NAME", "TYPE"};
+ String[] header = { "CLUSTER_ID", "SCHEMA", "NAME", "TYPE" };
writer.writeNext(header);
int clusterID = 0;
for (Set vertexSet : data) {
for (Vertex vertex : vertexSet) {
- String[] output = {Integer.toString(clusterID), vertex.getSchema(), Integer.toString(vertex.getLabel()), vertex.getType()};
+ String[] output = { Integer.toString(clusterID), vertex.getSchema(),
+ Integer.toString(vertex.getLabel()), vertex.getType() };
writer.writeNext(output);
}
clusterID++;
diff --git a/src/main/java/com/kkoutsilis/utilities/Distance.java b/src/main/java/com/kkoutsilis/utilities/Distance.java
index 8221464..bceee92 100644
--- a/src/main/java/com/kkoutsilis/utilities/Distance.java
+++ b/src/main/java/com/kkoutsilis/utilities/Distance.java
@@ -5,6 +5,10 @@
import java.util.*;
+/**
+ * @author kkoutsilis
+ * */
+
/**
* Dijkstra's algorithm
*/
@@ -14,13 +18,13 @@ private Distance() {
throw new IllegalStateException("Utility class");
}
-
public static int calculate(int source, int dest, Graph graph) {
int nOfVertices = graph.getVertices().size() + 1;
PriorityQueue minHeap;
minHeap = new PriorityQueue<>(Comparator.comparingInt(Vertex::getLabel));
- Vertex sourceVertex = graph.getVertices().keySet().stream().filter(v -> v.getLabel() == source).findFirst().orElse(null);
+ Vertex sourceVertex = graph.getVertices().keySet().stream().filter(v -> v.getLabel() == source).findFirst()
+ .orElse(null);
minHeap.add(sourceVertex);
List dist;
diff --git a/src/main/java/com/kkoutsilis/utilities/NearestNeighbour.java b/src/main/java/com/kkoutsilis/utilities/NearestNeighbour.java
index ece6311..9d0099c 100644
--- a/src/main/java/com/kkoutsilis/utilities/NearestNeighbour.java
+++ b/src/main/java/com/kkoutsilis/utilities/NearestNeighbour.java
@@ -5,13 +5,15 @@
import java.util.*;
+/**
+ * @author kkoutsilis
+ */
public final class NearestNeighbour {
private NearestNeighbour() {
throw new IllegalStateException("Utility class");
}
- // return the k nearest neighbours for each vertex of a graph
public static Map> knn(int k, Graph graph) {
Map> nearestNeighbours = new HashMap<>();
Set indexes = new LinkedHashSet<>(graph.getVertices().keySet());
@@ -36,7 +38,6 @@ public static Map> knn(int k, Graph graph) {
return nearestNeighbours;
}
- // reverse nearest neighbours of knn
public static Map> rknn(Map> knn) {
Map> reverseNearestNeighbours = new HashMap<>();
Set D = knn.keySet();