Java Information Dynamics Toolkit (JIDT)

repository·master·Indexed 43 days ago

https://github.com/jlizier/jidt

An open-source Java toolkit for calculating information-theoretic measures to analyze complex systems. It supports transfer entropy, mutual information, active information storage, and entropy for both discrete and continuous-valued data. JIDT includes various estimators such as KSG, box-kernel, and linear-Gaussian, and is accessible via Java, a GUI (AutoAnalyser), or integrations with Matlab, Octave, Python, R, Julia, and Clojure.

Tokens
30.4K
Snippets
84
Records
96
Agent score
53%

What's inside JIDT

  1. Overview of JIDT

    master

    The Java Information Dynamics Toolkit (JIDT) is an open-source Java implementation of information-theoretic measures used to study distributed computation in complex systems. It focuses on measuring information storage, transfer, and modification.

    Core Capabilities:

    • Measures: Implements Transfer Entropy (TE), Mutual Information (MI), and Active Information Storage (AIS).
    • Variable Types: Supports both discrete and continuous-valued variables.
    • Estimators: Includes various estimation methods such as Kraskov-Stögbauer-Grassberger (KSG) estimators, kernel estimation, and linear-Gaussian estimators.
    • Cross-Language Support: While implemented in Java, it is designed to be usable within Matlab, Octave, Python, R, Julia, and Clojure.
  2. Overview of Java Information Dynamics Toolkit (JIDT)

    master

    JIDT is an open-source Java implementation of information-theoretic measures used to study distributed computation in complex systems, specifically focusing on information storage, transfer, and modification.

    Key features include:

    • Supported Measures: Transfer entropy, mutual information (and conditional variants), active information storage, and entropy.
    • Data Types: Support for both discrete and continuous-valued data.
    • Estimators: Various estimation methods such as Kraskov-Stögbauer-Grassberger (KSG) estimators, box-kernel estimation, and linear-Gaussian.
    • Multi-language Support: While implemented in Java, it can be used within Matlab, Octave, Python, R, Julia, and Clojure.
    • Analysis Tools: Includes a GUI application called AutoAnalyser for point-and-click analysis and code template generation.
  3. Overview of CUB collective primitives

    master

    CUB provides reusable software components for various layers of the CUDA programming model:

    • Device-wide primitives: Includes Sort, prefix scan, reduction, histogram, etc. Compatible with CUDA dynamic parallelism.
    • Block-wide "collective" primitives: Includes I/O, sort, prefix scan, reduction, histogram, etc. Compatible with arbitrary thread block sizes and types.
    • Warp-wide "collective" primitives: Includes warp-wide prefix scan, reduction, etc. These are safe and architecture-specific.
    • Thread and resource utilities: Includes PTX intrinsics, device reflection, texture-caching iterators, and caching memory allocators.
  4. How to use Block-wide collective primitives

    master

    Block-wide primitives like cub::BlockRadixSort, cub::BlockLoad, and cub::BlockStore are used within CUDA kernels to perform collective operations across a thread block.

    Specialization

    These classes must be specialized by providing:

    1. The data type being processed.
    2. The number of threads per block.
    3. The number of keys/items per thread.
    4. (Implicitly) The targeted compilation architecture.

    Memory Management

    Once specialized, these classes expose an opaque TempStorage member type. To manage memory efficiently, thread blocks should use a union of these TempStorage types to statically allocate the required shared memory. This ensures that the total shared memory allocated is only as large as the largest required buffer among the used primitives.

    Data Access Patterns

    cub::BlockLoad and cub::BlockStore are designed to provide coalesced access to device memory. They use a striped access pattern (consecutive threads accessing consecutive items) and then transpose the keys into a blocked arrangement across threads.

    #include <cub/cub.cuh>
     
    // Block-sorting CUDA kernel
    __global__ void BlockSortKernel(int *d_in, int *d_out)
    {
         using namespace cub;
    
         // Specialize BlockRadixSort, BlockLoad, and BlockStore for 128 threads 
         // owning 16 integer items each
         typedef BlockRadixSort<int, 128, 16>                     BlockRadixSort;
         typedef BlockLoad<int, 128, 16, BLOCK_LOAD_TRANSPOSE>   BlockLoad;
         typedef BlockStore<int, 128, 16, BLOCK_STORE_TRANSPOSE> BlockStore;
     
         // Allocate shared memory using a union of TempStorage types
         __shared__ union {
             typename BlockRadixSort::TempStorage  sort;
             typename BlockLoad::TempStorage       load; 
             typename BlockStore::TempStorage      store; 
         } temp_storage; 
    
         int block_offset = blockIdx.x * (128 * 16);
    
         // 1. Load data from device memory to thread-local arrays
         int thread_keys[16];
         BlockLoad(temp_storage.load).Load(d_in + block_offset, thread_keys);
         __syncthreads();
    
         // 2. Collectively sort the keys within the block
         BlockRadixSort(temp_storage.sort).Sort(thread_keys);
         __syncthreads();
    
         // 3. Store the sorted segment back to device memory
         BlockStore(temp_storage.store).Store(d_out + block_offset, thread_keys);
    }
  5. Get started with JIDT

    master

    You can install and start using JIDT via two primary methods:

    1. Quick Start (Source)

    Clone the repository and build it using the provided Ant scripts:

    git clone <repository_url>
    # Build using Ant (refer to AntScripts documentation for details)

    Download the latest full distribution (e.g., v1.6.1) which is suitable for all platforms. This distribution includes:

    • Demos: Simple Java demos and Cellular Automata (CA) demos.
    • GUI App: The AutoAnalyser for automatic analysis and code generation.
    • Documentation: Javadocs, tutorials, and the foundational paper (arXiv:1408.3270).

    Once installed, you can use the Java tools directly or integrate them into other environments like Python, Matlab, or R using the provided language-specific examples.

    git clone <repository_url>
  6. Explore JIDT usage demos by language

    master

    JIDT provides several demonstration sets to show how to use the toolkit in different environments. You can find these in the demos/ directory:

    DirectoryLanguage/Environment
    demos/javaJava (Basic examples)
    demos/pythonPython
    demos/octaveOctave or Matlab
    demos/rR
    demos/juliaJulia
    demos/clojureClojure

    For Java users, basic examples can be run from the shell scripts provided in the demos/java directory.

  7. Prepare your Python environment for JIDT notebooks

    master

    To use functions defined in previous notebooks or external scripts, you have three main options:

    1. Using the ipynb library: Install it via pip3 install ipynb. You can then import functions directly from notebooks using the syntax from ipynb.fs.full.NotebookName import function_name. Note that this executes the entire notebook upon import.
    2. Using a dedicated script (Recommended): Save your functions in a Python script (e.g., simpleinfotheory.py) and import them using standard Python import statements. This is the preferred long-term solution for managing information theory functions.
    3. Directly editing scripts: Manually paste your functions into a local .py file to maintain a library of reusable code.
    pip3 install ipynb
    # Option 1: Import from a notebook
    from ipynb.fs.full.Module_1_notebook import entropy
    
    # Option 2: Import from a local script (Recommended)
    from simpleinfotheory import entropy
  8. Use AutoAnalyser GUI for automated calculations

    master

    The demos/AutoAnalyser tool is a Graphical User Interface (GUI) that allows you to compute information-theoretic measures on a chosen dataset.

    Key Features:

    • Computes measures using the JIDT toolkit.
    • Code Generation: Automatically generates implementation code in Java, Python, and Matlab to show you how to replicate the specific calculation you performed in the GUI.
  9. Access JIDT Documentation and Tutorials

    master

    JIDT provides several ways to learn how to use the toolkit:

    • Research Paper: The foundational paper, InfoDynamicsToolkit.pdf, is located in the top-level directory.
    • Tutorials: Detailed background on information-theoretic measures and estimators is available in the tutorial folder (e.g., JIDT-TutorialSlides.pdf).
    • Javadocs: Full API documentation is included in the javadocs folder of the distribution. If you have a git clone, you can generate them using ant javadocs.
    • Project Wiki: Comprehensive information and guides are hosted on the GitHub wiki: https://github.com/jlizier/jidt/wiki.
  10. Analyze Scissors-Paper-Rock data using Matlab

    master

    To perform the Scissors-Paper-Rock analysis, use the Matlab live script ScissorsPaperRockAnalysis.mlx. This script acts as a guide and orchestrates several supporting scripts to process player names, game data, and information-theoretic measures.

    Core Analysis Scripts

    • listPlayers.m: Extracts player names from the dataset.
    • loadGamesForPlayer.m: Retrieves game data for a specific player.
    • translateMove.m and translateResult.m: Converts encoded moves and results into human-readable text strings.
    • computeEntropyForPlayer.m, computeConditionalEntropyForPlayer.m, and computeMutualInformationForPlayer.m: Calculate information-theoretic measures for an individual player.
    • computeEntropyForAllPlayers.m, computeConditionalEntropyForAllPlayers.m, and computeMutualInformationForAllPlayers.m: Calculate information-theoretic measures for the entire player pool.

    Manual Setup for External Analysis

    If you wish to analyze the data outside of the provided live script, run setup.m first. This script initializes the necessary system paths required for the analysis scripts to function correctly.

    % To initialize paths for analysis outside the live script:
    setup;
  11. Set up Scissors-Paper-Rock data analysis environment

    master

    To perform the Scissors-Paper-Rock analysis, you need to install pandas and re, and ensure you have the sprutils utility and your custom information theory scripts (e.g., simpleinfotheory.py) available in your Python path.

    1. Download Data: Obtain the Scissors-Paper-Rock dataset and unzip it.
    2. Configure Paths: Use sprutils.setDataPath() to point to your data files and sys.path.append() to include your information theory scripts.
    3. Dependencies: The analysis requires numpy, scipy, and matplotlib.
    import sprutils
    import numpy as np
    from scipy import stats
    import matplotlib.pyplot as plt
    import sys
    
    # Set path for where your Scissors-Paper-Rock data files are stored
    sprutils.setDataPath("../ScissorsPaperRock-SampleData")
    
    # Set the path for your information theory scripts
    sys.path.append('../../Module01-Entropy/PythonSimpleFunctions/completed/')
    import simpleinfotheory
  12. Install JIDT

    master

    JIDT is distributed as a JAR file. To use it, download a distribution and place the JAR in a relevant location in your file structure.

    Prerequisites:

    • Java: You must have a Java Runtime Environment (JRE) installed.
    • Building from source: If you wish to build the project yourself using the build.xml script, you need Apache Ant.
    • Running Tests: To run the JUnit test cases, you need JUnit.