public class Clustering
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Each node belongs to exactly one cluster.
Modifier and Type | Field and Description |
---|---|
protected int[] |
clusters
Cluster of each node.
|
protected int |
nClusters
Number of clusters.
|
protected int |
nNodes
Number of nodes.
|
Constructor and Description |
---|
Clustering(int nNodes)
Constructs a singleton clustering for a specified number of nodes.
|
Clustering(int[] clusters)
Constructs a clustering using a specified cluster for each node.
|
Modifier and Type | Method and Description |
---|---|
double |
calcNormalizedMutualInformation(Clustering clustering)
Calculates the normalized mutual information relative to another
clustering.
|
double |
calcVariationOfInformation(Clustering clustering)
Calculates the variation of information relative to another clustering.
|
Clustering |
clone()
Clones the clustering.
|
int |
getCluster(int node)
Returns the cluster of a node.
|
boolean[] |
getClusterIsNotEmpty()
Returns whether the cluster is empty or not for each cluster.
|
int[] |
getClusters()
Returns the cluster of each node.
|
double[] |
getClusterWeights(double[] nodeWeights)
Determine the total node weight of all nodes per cluster.
|
double[] |
getClusterWeights(Network network)
Determine the total node weight of all nodes per cluster.
|
int |
getNClusters()
Returns the number of clusters.
|
int |
getNNodes()
Returns the number of nodes.
|
int[] |
getNNodesPerCluster()
Returns the number of nodes per cluster.
|
int |
getNNonEmptyClusters()
Returns the number of non-empty clusters.
|
int[][] |
getNodesPerCluster()
Returns a list of nodes per cluster.
|
void |
initSingletonClusters()
Initializes a singleton clustering.
|
static Clustering |
load(java.lang.String filename)
Loads a clustering from a file.
|
void |
mergeClusters(Clustering clustering)
Merges the clusters based on a clustering of the clusters.
|
void |
orderClustersByNNodes()
Orders the clusters in decreasing order of their number of nodes.
|
void |
orderClustersByWeight(double[] nodeWeights)
Orders the clusters in decreasing order of their total node weight.
|
void |
removeEmptyClusters()
Removes empty clusters.
|
void |
removeEmptyClustersLargerThan(int minimumCluster)
Removes empty clusters and relabels clusters to follow consecutive
numbering only for clusters larger than the specified minimum number of
clusters.
|
void |
save(java.lang.String filename)
Saves the clustering in a file.
|
void |
setCluster(int node,
int cluster)
Assigns a node to a cluster.
|
protected int nNodes
protected int nClusters
protected int[] clusters
public Clustering(int nNodes)
nNodes
- Number of nodespublic Clustering(int[] clusters)
clusters
- Cluster of each nodepublic static Clustering load(java.lang.String filename) throws java.lang.ClassNotFoundException, java.io.IOException
filename
- File from which a clustering is loadedjava.lang.ClassNotFoundException
- Class not foundjava.io.IOException
- Could not read the filesave(String filename)
public Clustering clone()
clone
in class java.lang.Object
public void save(java.lang.String filename) throws java.io.IOException
filename
- File in which the clustering is savedjava.io.IOException
- Could not write to the fileload(String filename)
public int getNNodes()
public int getNClusters()
public boolean[] getClusterIsNotEmpty()
public int getNNonEmptyClusters()
getClusterIsNotEmpty()
public int[] getClusters()
public int getCluster(int node)
node
- Nodepublic int[] getNNodesPerCluster()
public int[][] getNodesPerCluster()
public void setCluster(int node, int cluster)
node
- Nodecluster
- Clusterpublic void initSingletonClusters()
Each node i
is assigned to a cluster i
.
public void removeEmptyClusters()
Clusters are relabeled to follow a strictly consecutive numbering 0, ..., nClusters - 1
.
public void removeEmptyClustersLargerThan(int minimumCluster)
Each empty cluster larger that minimumCluster
is reassigned to
the lowest available cluster, in the order of the existing clusters. For
example, if minimumCluster = 5
and cluster 2 and 7 are empty,
then cluster 8 is relabeled to 7 (and 9 to 8, etc...), but clusters 0-4
remain as they are.
minimumCluster
- Minimum cluster to start relabeling frompublic double[] getClusterWeights(Network network)
network
- Network with node weightsgetClusterWeights(double[] nodeWeight)
public double[] getClusterWeights(double[] nodeWeights)
nodeWeights
- Array of node weightspublic void orderClustersByNNodes()
public void orderClustersByWeight(double[] nodeWeights)
The total node weight of a cluster equals the sum of the weights of the nodes belonging to the cluster.
nodeWeights
- Node weightsorderClustersByNNodes()
public void mergeClusters(Clustering clustering)
clustering
- Clustering of the clusterspublic double calcNormalizedMutualInformation(Clustering clustering)
clustering
- Other clusteringpublic double calcVariationOfInformation(Clustering clustering)
clustering
- Other clustering