-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rely on layout and clustering algorithms from networkanalysis-ts pack…
…age (#22) * Implement new network data structure * Implement new Leiden algorithm * Implement new VOS algorithm * Remove old algorithms and data structures * Add networkanalysis-ts package dependency
- Loading branch information
1 parent
31ed4f3
commit 8735e3d
Showing
15 changed files
with
91 additions
and
1,130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,56 @@ | ||
import Random from 'java-random'; | ||
import ClusteringTechnique from './ClusteringTechnique'; | ||
import { Clustering, LeidenAlgorithm } from 'networkanalysis-ts'; | ||
|
||
export const DEFAULT_RESOLUTION = 1.0; | ||
export const DEFAULT_MIN_CLUSTER_SIZE = 1; | ||
export const DEFAULT_MERGE_SMALL_CLUSTERS = true; | ||
export const DEFAULT_N_ITERATIONS = 10; | ||
export const DEFAULT_RANDOMNESS = 0.01; | ||
export const DEFAULT_N_RANDOM_STARTS = 10; | ||
export const DEFAULT_FIXED_SEED = 0; | ||
export const DEFAULT_USE_RANDOM_SEED = false; | ||
|
||
export class ClusteringCreator { | ||
constructor() { | ||
this.bestClustering = undefined; | ||
this.maxQualityFunction = -Infinity; | ||
} | ||
|
||
init(network, parameters, useLinLogModularityNormalization) { | ||
this.network = network; | ||
this.resolution = parameters.resolution; | ||
this.minClusterSize = parameters.minClusterSize; | ||
this.mergeSmallClusters = parameters.mergeSmallClusters; | ||
this.nIterations = parameters.nIterations; | ||
this.randomness = parameters.randomness; | ||
this.nRandomStarts = parameters.nRandomStarts; | ||
this.fixedSeed = parameters.fixedSeed; | ||
this.useRandomSeed = parameters.useRandomSeed; | ||
this.useLinLogModularityNormalization = useLinLogModularityNormalization; | ||
|
||
this.random = this.useRandomSeed ? new Random() : new Random(this.fixedSeed); | ||
|
||
let resolution2 = parameters.resolution; | ||
if (this.useLinLogModularityNormalization) { | ||
resolution2 /= (2 * this.network.getTotalEdgeWeight()); | ||
} | ||
this.clusteringAlgorithm = new LeidenAlgorithm(); | ||
this.clusteringAlgorithm.initializeBasedOnResolutionAndNIterationsAndRandomnessAndRandom(resolution2, this.nIterations, this.randomness, this.random); | ||
this.bestClustering = undefined; | ||
this.maxQualityFunction = -Infinity; | ||
this.maxQuality = -Infinity; | ||
this.randomStart = 0; | ||
} | ||
|
||
performRandomStart() { | ||
let { resolution } = this; | ||
if (this.useLinLogModularityNormalization) { | ||
resolution /= (2 * this.network.getTotalEdgeWeight()); | ||
} | ||
const clusteringTechnique = new ClusteringTechnique({ network: this.network, resolution }); | ||
clusteringTechnique.runIteratedSmartLocalMovingAlgorithm(this.nIterations, this.random); | ||
const qualityFunction = clusteringTechnique.calcQualityFunction(); | ||
if ((this.bestClustering === undefined) || (qualityFunction > this.maxQualityFunction)) { | ||
this.bestClustering = clusteringTechnique.getClustering(); | ||
this.maxQualityFunction = qualityFunction; | ||
const clustering = new Clustering({ nNodes: this.network.getNNodes() }); | ||
this.clusteringAlgorithm.improveClustering(this.network, clustering); | ||
const quality = this.clusteringAlgorithm.calcQuality(this.network, clustering); | ||
if ((this.bestClustering === undefined) || (quality > this.maxQuality)) { | ||
this.bestClustering = clustering; | ||
this.maxQuality = quality; | ||
} | ||
this.randomStart += 1; | ||
} | ||
|
||
performPostProcessing() { | ||
const { resolution, mergeSmallClusters, minClusterSize } = this; | ||
const clusteringTechnique = new ClusteringTechnique({ network: this.network, clustering: this.bestClustering, resolution }); | ||
if (mergeSmallClusters) { | ||
clusteringTechnique.removeSmallClustersBasedOnNNodes(minClusterSize); | ||
if (this.mergeSmallClusters) { | ||
this.clusteringAlgorithm.removeSmallClustersBasedOnNNodes(this.network, this.bestClustering, this.minClusterSize); | ||
} | ||
|
||
this.bestClustering = clusteringTechnique.getClustering(); | ||
this.bestClustering.orderClustersByNNodes(); | ||
} | ||
} |
Oops, something went wrong.