networkanalysis

repository·master·Indexed 41 days ago

https://github.com/cwtsleiden/networkanalysis

A Java package providing algorithms and data structures for undirected network analysis. It features the RunNetworkClustering tool for community detection using Leiden and Louvain algorithms, and the RunNetworkLayout tool for generating layouts using the gradient descent VOS technique. Version 1.3.0 requires Java 8 or higher.

Tokens
3.2K
Snippets
9
Records
9
Agent score
50%

What's inside networkanalysis

  1. Install networkanalysis via Maven or Gradle

    master

    You can include the networkanalysis package in your Java project using Maven or Gradle. The package requires Java 8 or higher.

    ### Maven
    ```xml
    <dependency>
        <groupId>nl.cwts</groupId>
        <artifactId>networkanalysis</artifactId>
        <version>1.3.0</version>
    </dependency>

    Gradle

    implementation group: 'nl.cwts', name: 'networkanalysis', version: '1.3.0'
  2. Compile the networkanalysis source code

    master

    To compile the source code, you need a Java Development Kit (JDK) version 8 or higher installed. While having Gradle installed is optional because the repository includes the Gradle Wrapper, you must use the wrapper to build the project.

    Output Locations:

    • Compiled .class files: build/classes
    • Compiled .jar file: build/libs
    • Compiled javadoc files: build/docs
    # On Windows
    gradlew build
    
    # On Linux and MacOS
    ./gradlew build
  3. Example: Clustering and Layout Workflow

    master

    This example demonstrates how to take an edge list, identify clusters using the Leiden algorithm, and then generate a VOS layout for those nodes.

    1. Prepare network.txt (tab-separated edge list):
    0	1
    1	2
    2	0
    2	3
    3	5
    5	4
    4	3
    1. Run Clustering (using resolution 0.2 and outputting to clusters.txt):
    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkClustering -r 0.2 -o clusters.txt network.txt
    1. Run Layout (using default VOS parameters and outputting to layout.txt):
    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkLayout -o layout.txt network.txt
    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkClustering -r 0.2 -o clusters.txt network.txt
    
    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkLayout -o layout.txt network.txt
  4. Run the RunNetworkLayout tool

    master

    After compiling the source code, you can execute the RunNetworkLayout tool using the generated JAR file. Replace <version> with the actual version number found in the build/libs directory.

    java -cp build/libs/networkanalysis-<version>.jar nl.cwts.networkanalysis.run.RunNetworkLayout
  5. Run the RunNetworkClustering tool

    master

    After compiling the source code, you can execute the RunNetworkClustering tool using the generated JAR file. Replace <version> with the actual version number found in the build/libs directory.

    java -cp build/libs/networkanalysis-<version>.jar nl.cwts.networkanalysis.run.RunNetworkClustering
  6. Reference: RunNetworkClustering options

    master

    Options for the RunNetworkClustering CLI tool:

    -q --quality-function {CPM|Modularity} (default: CPM)
        Quality function to be optimized. Either the CPM (constant Potts model) or
        the modularity quality function can be used.
    -n --normalization {none|AssociationStrength|Fractionalization} (Default: none)
        Method for normalizing edge weights in the CPM quality function.
    -r --resolution <resolution> (default: 1.0)
        Resolution parameter of the quality function.
    -m --min.cluster.size <min. cluster size> (default: 1)
        Minimum number of nodes per cluster.
    -a --algorithm {Leiden|Louvain} (default: Leiden)
        Algorithm for optimizing the quality function. Either the Leiden or the
        Louvain algorithm can be used.
    -s --random-starts <random starts> (default: 1)
        Number of random starts of the algorithm.
    -i --iterations <iterations> (default: 10)
        Number of iterations of the algorithm.
    --randomness <randomness> (default: 0.01)
        Randomness parameter of the Leiden algorithm.
    --seed <seed> (default: random)
        Seed of the random number generator.
    -w --weighted-edges
        Indicates that the edge list file has a third column containing edge
        weights.
    --sorted-edge-list
        Indicates that the edge list file is sorted. The file should be sorted based
        on the nodes in the first column, followed by the nodes in the second
        column. Each edge should be included in both directions in the file.
    --input-clustering <filename> (default: singleton clustering)
        Read the initial clustering from the specified file. The file is expected to
        contain two tab-separated columns (without a header line), first a column of
        nodes and then a column of clusters. Nodes and clusters are both represented
        by zero-index integer numbers. If no file is specified, a singleton
        clustering (in which each node has its own cluster) is used as the initial
        clustering.
    -o --output-clustering <filename> (default: standard output)
        Write the final clustering to the specified file. If no file is specified,
        the standard output is used.
  7. Reference: RunNetworkLayout options

    master

    Options for the RunNetworkLayout CLI tool:

    -q --quality-function {VOS|LinLog} (default: VOS)
        Quality function to be optimized. Either the VOS (visualization of
        similarities) or the LinLog quality function can be used.
    -n --normalization {none|AssociationStrength|Fractionalization} (Default: none)
        Method for normalizing edge weights in the VOS quality function.
    -a --attraction <attraction> (Default: 2)
        Attraction parameter of the VOS quality function.
    -r --repulsion <repulsion> (Default: 1)
        Repulsion parameter of the VOS quality function.
    -s --random-starts <random starts> (default: 1)
        Number of random starts of the gradient descent algorithm.
    -i --max-iterations <max. iterations> (default: 1000)
        Maximum number of iterations of the gradient descent algorithm.
    --initial-step-size <initial step size> (default: 1.0)
        Initial step size of the gradient descent algorithm.
    --min-step-size <min. step size> (default: 0.001)
        Minimum step size of the gradient descent algorithm.
    --step-size-reduction <step size reduction> (default: 0.75)
        Step size reduction of the gradient descent algorithm.
    --required-quality-value-improvements <required quality value improvements>
            (default: 5)
        Required number of quality value improvements of the gradient descent
        algorithm.
    --seed <seed> (default: random)
        Seed of the random number generator.
    -w --weighted-edges
        Indicates that the edge list file has a third column containing edge
        weights.
    --sorted-edge-list
        Indicates that the edge list file is sorted. The file should be sorted based
        on the nodes in the first column, followed by the nodes in the second
        column. Each edge should be included in both directions in the file.
    --input-layout <filename> (default: random layout)
        Read the initial layout from the specified file. The file is expected to
        contain three tab-separated columns (without a header line), first a column
        of nodes, then a column of x coordinates, and finally a column of
        y coordinates. Nodes are represented by zero-index integer numbers. If no
        file is specified, a random layout (in which each node is positioned at
        random coordinates) is used as the initial layout.
    -o --output-layout <filename> (default: standard output)
        Write the final layout to the specified file. If no file is specified,
        the standard output is used.
  8. Run network layout with RunNetworkLayout

    master

    The RunNetworkLayout command-line tool determines a layout for an undirected network using the gradient descent VOS layout algorithm.

    Input Format: A tab-separated edge list (without a header). Nodes must be represented by zero-indexed integers. Each edge should appear only once unless using --sorted-edge-list.

    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkLayout [options] <filename>
  9. Run network clustering with RunNetworkClustering

    master

    The RunNetworkClustering command-line tool identifies clusters (communities) in an undirected network using either the Leiden or Louvain algorithm.

    Input Format: A tab-separated edge list (without a header). Nodes must be represented by zero-indexed integers. Each edge should appear only once unless using --sorted-edge-list.

    java -cp networkanalysis-1.3.0.jar nl.cwts.networkanalysis.run.RunNetworkClustering [options] <filename>