### Initialize JVM and Load Data Source: https://github.com/jlizier/jidt/wiki/PythonExamples This snippet shows how to start the Java Virtual Machine (JVM) with specified arguments and load physiological data from a file using a custom readFloatsFile module. It then converts the data into a NumPy array and extracts specific time-series for breath rate and heart rate. ```jython # Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation) # Examine the heart-breath interaction that Schreiber originally looked at: datafile = '../data/SFI-heartRate_breathVol_bloodOx.txt' data = readFloatsFile.readFloatsFile(datafile) # As numpy array: A = numpy.array(data) # Select data points 2350:3550, pulling out the relevant columns: breathRate = A[2350:3551,1]; heartRate = A[2350:3551,0]; ``` -------------------------------- ### Clojure Demos for JIDT Source: https://github.com/jlizier/jidt/wiki/_Sidebar Includes example Clojure code demonstrating how to interact with the JIDT library. This allows Clojure developers to incorporate JIDT's functionalities into their Lisp-based applications. ```clojure ;; Placeholder for Clojure demo code using JIDT ;; (require '[jidt]) ;; (def data [...]) ; Load or generate data ;; (def result (jidt/analyze data)) ``` -------------------------------- ### Python Demos for JIDT Source: https://github.com/jlizier/jidt/wiki/_Sidebar Provides example code demonstrating the use of JIDT within a Python environment. This allows Python developers to leverage JIDT's capabilities for information-theoretic analysis. ```python # Placeholder for Python demo code using JIDT # import jidt # data = [...] # Load or generate data # result = jidt.analyze(data) ``` -------------------------------- ### Configure JIDT Clojure Project Dependencies Source: https://github.com/jlizier/jidt/wiki/Clojure_Examples This snippet shows the project.clj file configuration for a Clojure project using the JIDT toolkit. It specifies the necessary dependencies, including Clojure itself and the JIDT library from Clojars. ```clojure (defproject me.lizier/jidt-clojure-samples "1.0-SNAPSHOT" :description "Java Information Dynamics Toolkit (JIDT) clojure samples" :url "https://code.google.com/p/information-dynamics-toolkit/" :license { :name "GNU GPL v3" :url "http://www.gnu.org/licenses/gpl.html" :distribution :repo } :dependencies [[org.clojure/clojure "1.6.0"] [me.lizier/jidt "LATEST"] ]) ``` -------------------------------- ### R Demos for JIDT Source: https://github.com/jlizier/jidt/wiki/_Sidebar Contains example R scripts showcasing how to integrate and use the JIDT library. This enables R users to perform complex information-theoretic calculations within their statistical environment. ```r # Placeholder for R demo code using JIDT # library(jidt) # data <- ... # Load or generate data # result <- jidt.analyze(data) ``` -------------------------------- ### Handle Unimplemented Feature in Julia Source: https://github.com/jlizier/jidt/wiki/JuliaExamples This is a placeholder in the Julia example that indicates a current limitation. It prints a message and exits, noting that support for multidimensional arrays in JavaCall is required to proceed. ```julia @printf("We're stuck at this point until support for multidimensional arrays is included in JavaCall"); exit(); ``` -------------------------------- ### Julia Demos for JIDT Source: https://github.com/jlizier/jidt/wiki/_Sidebar Features example code for utilizing JIDT within the Julia programming language. This facilitates the use of JIDT's advanced analysis tools for researchers and developers working in the Julia ecosystem. ```julia # Placeholder for Julia demo code using JIDT # using JIDT # data = [...] # Load or generate data # result = JIDT.analyze(data) ``` -------------------------------- ### Dynamic Dispatch for Mutual Information Calculator (Julia) Source: https://github.com/jlizier/jidt/wiki/JuliaExamples Demonstrates dynamic dispatch in Julia using JavaCall to interact with the Infodynamics Java library's common interfaces for mutual information calculators. This example allows plugging in different concrete implementations (kernel, Kraskov, linear-Gaussian) by dynamically supplying the class name. Note: Multidimensional array passing between Julia and Java is not yet fully supported. ```julia # Import the JavaCall package: using JavaCall; # Change location of jar to match yours: jarLocation = "../../infodynamics.jar"; # Start the JVM supplying classpath and heap size # (increase memory here if you get crashes due to not enough space) JavaCall.init(["-Djava.class.path=$(jarLocation)", "-Xmx128M"]); #--------------------- # 1. Properties for the calculation (these are dynamically changeable, you could # load them in from another properties file): # The name of the data file (relative to this directory) datafile = "../data/4ColsPairedNoisyDependence-1.txt"; ``` -------------------------------- ### Creating and Using Java Class Instances with JPype Source: https://github.com/jlizier/jidt/wiki/UseInPython This example illustrates how to create an instance of a Java class from Python using JPype. It involves referencing a Java package, obtaining a reference to a specific class within that package, instantiating the class, and then calling its methods. ```python from jpype import * # Assuming JVM has been started and jarLocation is set # ... startJVM(...) ... # Create a reference to the Java package and class teCalcClass = JPackage("infodynamics.measures.discrete").TransferEntropyCalculatorDiscrete # Create an instance of the Java class with specified arguments teCalc = teCalcClass(2, 1) # Use a method of the Java object teCalc.initialise() # ... more interactions ... # Remember to shutdown the JVM if this is the end of your script # ... shutdownJVM() ... ``` -------------------------------- ### Java Late Binding Mutual Information Calculator Source: https://github.com/jlizier/jidt/wiki/SimpleJavaExamples Demonstrates dynamic loading and use of a MutualInfoCalculatorMultiVariate implementation. Reads configuration from a properties file and data from a file, then computes univariate and multivariate mutual information. ```java // Requires the following imports before the class definition: // import infodynamics.measures.continuous.MutualInfoCalculatorMultiVariate; // import infodynamics.utils.ArrayFileReader; // import infodynamics.utils.MatrixUtils; // import infodynamics.utils.ParsedProperties; /** * @param args One command line argument taken, specifying location of * the properties file. This should be example6LateBindingMutualInfo.props * in the demos/java directory. */ public static void main(String[] args) throws Exception { // 0. Preliminaries (reading in the dynamic properties and the data): // a. Read in the properties file defined as the first // command line argument: ParsedProperties props = new ParsedProperties(args[0]); // b. Read in the data file, whose filename is defined in the // property "datafile" in our properties file: ArrayFileReader afr = new ArrayFileReader(props.getStringProperty("datafile")); double[][] data = afr.getDouble2DMatrix(); // c. Pull out the columns from the data set which // correspond to the univariate and joint variables we will work with: // First the univariate series to compute standard MI between: int univariateSeries1Column = props.getIntProperty("univariateSeries1Column"); int univariateSeries2Column = props.getIntProperty("univariateSeries2Column"); double[] univariateSeries1 = MatrixUtils.selectColumn(data, univariateSeries1Column); double[] univariateSeries2 = MatrixUtils.selectColumn(data, univariateSeries2Column); // Next the multivariate series to compute joint or multivariate MI between: int[] jointVariable1Columns = props.getIntArrayProperty("jointVariable1Columns"); int[] jointVariable2Columns = props.getIntArrayProperty("jointVariable2Columns"); double[][] jointVariable1 = MatrixUtils.selectColumns(data, jointVariable1Columns); double[][] jointVariable2 = MatrixUtils.selectColumns(data, jointVariable2Columns); // 1. Create a reference for our calculator as // an object implementing the interface type: MutualInfoCalculatorMultiVariate miCalc; // 2. Define the name of the class to be instantiated here: String implementingClass = props.getStringProperty("implementingClass"); // 3. Dynamically instantiate an object of the given class: // Part 1: Class.forName(implementingClass) grabs a reference to // the class named by implementingClass. // Part 2: .newInstance() creates an object instance of that class. // Part 3: (MutualInfoCalculatorMultiVariate) casts the return // object into an instance of our generic interface type. miCalc = (MutualInfoCalculatorMultiVariate) Class.forName(implementingClass).newInstance(); // 4. Start using our MI calculator, paying attention to only // call common methods defined in the interface type, not methods // only defined in a given implementation class. // a. Initialise the calculator for a univariate calculation: miCalc.initialise(1, 1); // b. Supply the observations to compute the PDFs from: miCalc.setObservations(univariateSeries1, univariateSeries2); // c. Make the MI calculation: double miUnivariateValue = miCalc.computeAverageLocalOfObservations(); // 5. Continue onto a multivariate calculation, still only // calling common methods defined in the interface type. // a. Initialise the calculator for a multivariate calculation // to use the required number of dimensions for each variable: miCalc.initialise(jointVariable1Columns.length, jointVariable2Columns.length); // b. Supply the observations to compute the PDFs from: miCalc.setObservations(jointVariable1, jointVariable2); // c. Make the MI calculation: double miJointValue = miCalc.computeAverageLocalOfObservations(); System.out.printf("MI calculator %s computed the univariate MI(%d;%d) as %.5f " + " and joint MI as %.5f\n", implementingClass, univariateSeries1Column, univariateSeries2Column, miUnivariateValue, miJointValue); } ``` -------------------------------- ### Starting and Shutting Down the JVM with JPype Source: https://github.com/jlizier/jidt/wiki/UseInPython This code demonstrates the fundamental steps to initiate and terminate the Java Virtual Machine (JVM) using JPype in Python. It includes importing necessary JPype modules, specifying the JVM path, and setting the Java class path to include external JAR files. ```python from jpype import * # Define the location of your Java JAR file jarLocation = "path/to/your/jidt.jar" # Start the JVM with the default path and specify the class path startJVM(getDefaultJVMPath(), "-Djava.class.path=" + jarLocation) # Your Java interactions would go here... # Shutdown the JVM when done shutdownJVM() ``` -------------------------------- ### Install JavaCall Package in Julia Source: https://github.com/jlizier/jidt/wiki/UseInJulia This command installs the JavaCall package, which is a prerequisite for using Java objects and code within a Julia session. It needs to be run from within a Julia environment. ```julia Pkg.add("JavaCall") ``` -------------------------------- ### Calculate Transfer Entropy on Multidimensional Binary Data (Clojure) Source: https://github.com/jlizier/jidt/wiki/Clojure_Examples Performs transfer entropy calculation on multidimensional binary data using JIDT's discrete calculator. This example illustrates how to handle multidimensional arrays when interfacing Clojure with Java. ```clojure ; Import relevant classes: (import infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete) (let ; Create many columns in a multidimensional array (2 rows by 100 columns), ; where the next time step (row 2) copies the value of the column on the left ; from the previous time step (row 1): [row1 (int-array (take 100 (repeatedly #(rand-int 2)))) row2 (int-array (cons (aget row1 99) (butlast row1))) ; shifts row1 by 1 twoDTimeSeriesClojure (into-array (map int-array [row1 row2])) ; Create TE calculator teCalc (TransferEntropyCalculatorDiscrete. 2 1) ] ; Initialise the TE calculator and run it: (.initialise teCalc) ; Add observations of transfer across one cell to the right per time step: (.addObservations teCalc twoDTimeSeriesClojure 1) (println "The result should be close to 1 bit here, since we are executing copy operations of what is effectively a random bit to each cell here:" (.computeAverageLocalOfObservations teCalc)) ) ``` -------------------------------- ### Transfer Entropy on Multidimensional Binary Data (Python/JPype) Source: https://github.com/jlizier/jidt/wiki/PythonExamples Demonstrates transfer entropy (TE) calculation on multidimensional binary data using the discrete TE calculator. This example is crucial for Python JPype users, showing how to manage multidimensional arrays between Python and Java. Requires JPype and infodynamics.jar. ```python from jpype import * import random # Change location of jar to match yours: jarLocation = "../../infodynamics.jar" # Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation) # Create many columns in a multidimensional array, e.g. for fully random values: ``` -------------------------------- ### Transfer Entropy on Multidimensional Binary Data using R and rJava Source: https://github.com/jlizier/jidt/wiki/R_Examples Calculates transfer entropy on multidimensional binary data. This example demonstrates handling multidimensional R arrays by converting them to Java arrays using `.jarray`. It requires rJava and infodynamics.jar. The output is the computed transfer entropy. ```r # Load the rJava library and start the JVM library("rJava") .jinit() # Change location of jar to match yours: # IMPORTANT -- If using the default below, make sure you have set the working directory # in R (e.g. with setwd()) to the location of this file (i.e. demos/r) !! .jaddClassPath("../../infodynamics.jar") # Create many columns in a multidimensional array (2 rows by 100 columns), # where the next time step (row 2) copies the value of the column on the left # from the previous time step (row 1): twoDTimeSeriesRtime1 <- sample(0:1, 100, replace=TRUE) twoDTimeSeriesRtime2 <- c(twoDTimeSeriesRtime1[100], twoDTimeSeriesRtime1[1:99]) twoDTimeSeriesR <- rbind(twoDTimeSeriesRtime1, twoDTimeSeriesRtime2) # Create a TE calculator and run it: teCalc<-.jnew("infodynamics/measures/discrete/TransferEntropyCalculatorDiscrete", 2L, 1L) .jcall(teCalc,"V","initialise") # V for void return value # Add observations of transfer across one cell to the right per time step: twoDTimeSeriesJava <- .jarray(twoDTimeSeriesR, "[I", dispatch=TRUE) .jcall(teCalc,"V","addObservations", twoDTimeSeriesJava, 1L) result2D <- .jcall(teCalc,"D","computeAverageLocalOfObservations") catalog("The result should be close to 1 bit here, since we are executing copy operations of what is effectively a random bit to each cell here: ", result2D, "\n") ``` -------------------------------- ### Calculate TE on Multidimensional Binary Data (Octave) Source: https://github.com/jlizier/jidt/wiki/OctaveMatlabExamples Demonstrates calculating Transfer Entropy (TE) on multidimensional binary data using Octave. It specifically addresses the conversion of multidimensional Octave arrays to Java, which is necessary for passing them to the Infodynamics library. The example uses a simple copying operation to create correlated data. ```matlab javaaddpath('../../infodynamics.jar'); % Create many columns in a multidimensional array, % where the next time step (row 2) copies the value of the column on the left % from the previous time step (row 1): twoDTimeSeriesOctave = (rand(1, 100)>0.5)*1; twoDTimeSeriesOctave(2, :) = [twoDTimeSeriesOctave(1,100), twoDTimeSeriesOctave(1, 1:99)]; % Things get a little tricky if we want to pass 2D arrays into Java. % Unlike native Octave 1D arrays in Example 1, % native Octave 2D+ arrays do not seem to get directly converted to java arrays, % so we use the supplied scripts to make the conversion (via org.octave.Matrix class in octave) % Matlab handles the conversion automatically, so in Matlab this script just returns % the array that was passed in. twoDTimeSeriesJavaInt = octaveToJavaIntMatrix(twoDTimeSeriesOctave); % Create a TE calculator and run it: teCalc=javaObject('infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete', 2, 1); teCalc.initialise(); % Add observations of transfer across one cell to the right per time step: teCalc.addObservations(twoDTimeSeriesJavaInt, 1); fprintf('The result should be close to 1 bit here, since we are executing copy operations of what is effectively a random bit to each cell here: '); result2D = teCalc.computeAverageLocalOfObservations() ``` -------------------------------- ### Load rJava and Initialize JVM Source: https://github.com/jlizier/jidt/wiki/R_Examples Loads the rJava library and initializes the Java Virtual Machine (JVM). This is a prerequisite for using Java classes within R. Ensure the 'infodynamics.jar' is accessible by setting the working directory or using .jaddClassPath. ```r library("rJava") .jinit() .jaddClassPath("../../infodynamics.jar") ``` -------------------------------- ### Ensemble Transfer Entropy on Continuous Data (Kraskov Estimators) in Python Source: https://github.com/jlizier/jidt/wiki/PythonExamples This Python example calculates Transfer Entropy (TE) for continuous data using Kraskov estimators and an ensemble method. It involves generating correlated time series, adding them as observations to a TE calculator, and then computing both the average local TE and individual local TEs for each trial. ```python from jpype import * import random import math # Change location of jar to match yours: jarLocation = "../../infodynamics.jar" # Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation) # Generate some random normalised data. numObservations = 1000 covariance=0.4 numTrials=10 kHistoryLength=1 # Create a TE calculator and run it: teCalcClass = JPackage("infodynamics.measures.continuous.kraskov").TransferEntropyCalculatorKraskov teCalc = teCalcClass() teCalc.setProperty("k", "4") # Use Kraskov parameter K=4 for 4 nearest points teCalc.initialise(kHistoryLength) # Use target history length of kHistoryLength (Schreiber k) teCalc.startAddObservations() for trial in range(0,numTrials): # Create a new trial, with destArray correlated to # previous value of sourceArray: sourceArray = [random.normalvariate(0,1) for r in range(numObservations)] destArray = [0] + [sum(pair) for pair in zip([covariance*y for y in sourceArray[0:numObservations-1]], \ [(1-covariance)*y for y in [random.normalvariate(0,1) for r in range(numObservations-1)]] ) ] # Add observations for this trial: print("Adding samples from trial %d ..." % trial) teCalc.addObservations(JArray(JDouble, 1)(sourceArray), JArray(JDouble, 1)(destArray)) # We've finished adding trials: print("Finished adding trials") teCalc.finaliseAddObservations() # Compute the result: print("Computing TE ...") result = teCalc.computeAverageLocalOfObservations() # Note that the calculation is a random variable (because the generated # data is a set of random variables) - the result will be of the order # of what we expect, but not exactly equal to it; in fact, there will # be some variance around it (smaller than example 4 since we have more samples). print("TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians " % \ (result, math.log(1.0/(1-math.pow(covariance,2))))) # And here's how to pull the local TEs out corresponding to each input time # series under the ensemble method (i.e. for multiple trials). localTEs=teCalc.computeLocalOfPreviousObservations() localValuesPerTrial = teCalc.getSeparateNumObservations() # Need to convert to int for indices later startIndex = 0 for localValuesInThisTrial in localValuesPerTrial: endIndex = startIndex + localValuesInThisTrial - 1 print("Local TEs for trial %d go from array index %d to %d" % (trial, startIndex, endIndex)) print(" corresponding to time points %d:%d (indexed from 0) of that trial" % (kHistoryLength, numObservations-1)) # Access the local TEs for this trial as: localTEForThisTrial = localTEs[startIndex:endIndex] # Now update the startIndex before we go to the next trial startIndex = endIndex + 1 # And make a sanity check that we've looked at all of the local values here: print("We've looked at %d local values in total, matching the number of samples we have (%d)" % (startIndex, teCalc.getNumObservations())) ``` -------------------------------- ### Multivariate Binary Data Transfer Entropy - MATLAB/Octave Source: https://github.com/jlizier/jidt/wiki/OctaveMatlabExamples Performs multivariate transfer entropy calculation on binary data using a discrete TE calculator. This example requires the infodynamics.jar and uses utility functions to combine source and destination observations before computation. It demonstrates TE calculation with a deterministic source and a random source, highlighting the impact of finite observation length. ```matlab javaaddpath('../../infodynamics.jar'); numObservations = 100; sourceArray=(rand(numObservations,2)>0.5)*1; sourceArray2=(rand(numObservations,2)>0.5)*1; destArray = [0, 0; sourceArray(1:numObservations-1, 1), xor(sourceArray(1:numObservations-1, 1), sourceArray(1:numObservations-1, 2))]; teCalc=javaObject('infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete', 4, 1); teCalc.initialise(); mUtils= javaObject('infodynamics.utils.MatrixUtils'); teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaDoubleMatrix(sourceArray), 2), ... mUtils.computeCombinedValues(octaveToJavaDoubleMatrix(destArray), 2)); fprintf('For source which the 2 bits are determined from, result should be close to 2 bits : '); result = teCalc.computeAverageLocalOfObservations() teCalc.initialise(); teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaDoubleMatrix(sourceArray2), 2), ... mUtils.computeCombinedValues(octaveToJavaDoubleMatrix(destArray), 2)); fprintf('For random source, result should be close to 0 bits in theory: '); result2 = teCalc.computeAverageLocalOfObservations() fprintf('\nThe result for random source is inflated towards 0.3 due to finite observation length (%d). One can verify that the answer is consistent with that from a random source by checking: teCalc.computeSignificance(1000); ans.pValue\n', teCalc.getNumObservations()); ``` -------------------------------- ### Calculate TE on Continuous Data using Kernel Estimators (Octave) Source: https://github.com/jlizier/jidt/wiki/OctaveMatlabExamples Illustrates the calculation of Transfer Entropy (TE) on continuous-valued data using the kernel-estimator TE calculator in Octave. This example generates correlated and uncorrelated Gaussian data and demonstrates how to use the calculator with history length and kernel width parameters. It also shows how to compute the null distribution to understand potential biases. ```matlab javaaddpath('../../infodynamics.jar'); % Generate some random normalised data. numObservations = 1000; covariance=0.4; sourceArray=randn(numObservations, 1); destArray = [0; covariance*sourceArray(1:numObservations-1) + (1-covariance)*randn(numObservations - 1, 1)]; sourceArray2=randn(numObservations, 1); % Uncorrelated source % Create a TE calculator and run it: teCalc=javaObject('infodynamics.measures.continuous.kernel.TransferEntropyCalculatorKernel'); teCalc.setProperty('NORMALISE', 'true'); % Normalise the individual variables teCalc.initialise(1, 0.5); % Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units teCalc.setObservations(sourceArray, destArray); % For copied source, should give something close to 1 bit: result = teCalc.computeAverageLocalOfObservations(); fprintf('TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards\n', ... result, log(1/(1-covariance^2))/log(2)); teCalc.initialise(); % Initialise leaving the parameters the same teCalc.setObservations(sourceArray2, destArray); % For random source, it should give something close to 0 bits result2 = teCalc.computeAverageLocalOfObservations(); fprintf('TE result %.4f bits; expected to be close to 0 bits for uncorrelated Gaussians but will be biased upwards\n', ... result2); % We can get insight into the bias by examining the null distribution: nullDist = teCalc.computeSignificance(100); fprintf(['Null distribution for unrelated source and destination ', ... '(i.e. the bias) has mean %.4f and standard deviation %.4f\n'], ... nullDist.getMeanOfDistribution(), nullDist.getStdOfDistribution()); ``` -------------------------------- ### Instantiate and Initialize Mutual Information Calculator in Julia Source: https://github.com/jlizier/jidt/wiki/JuliaExamples This Julia code dynamically instantiates a mutual information calculator class based on a provided string and initializes it with the number of dimensions for each variable. It uses `eval(:(@jimport $implementingClass))` for dynamic class loading and `jcall` for method invocation. ```julia miCalcClass = eval(:(@jimport $implementingClass)); miCalc = miCalcClass(()); jcall(miCalc, "initialise", Void, (jint,jint), length(variable1Columns), length(variable2Columns)); ``` -------------------------------- ### Calculate Transfer Entropy on Binary Data (Clojure) Source: https://github.com/jlizier/jidt/wiki/Clojure_Examples Calculates transfer entropy on simple binary data using JIDT's discrete transfer entropy calculator. It demonstrates generating random binary data, creating a TE calculator, and computing the average local observations. ```clojure ; Import relevant classes: (import infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete) (let ; Generate some random binary data. [sourceArray (int-array (take 100 (repeatedly #(rand-int 2)))) destArray (int-array (cons 0 (butlast sourceArray))) ; shifts sourceArray by 1 sourceArray2 (int-array (take 100 (repeatedly #(rand-int 2)))) ; Create TE calculator teCalc (TransferEntropyCalculatorDiscrete. 2 1) ] ; Initialise the TE calculator and run it: (.initialise teCalc) (.addObservations teCalc sourceArray destArray) (println "For copied source, result should be close to 1 bit : " (.computeAverageLocalOfObservations teCalc)) (.initialise teCalc) (.addObservations teCalc sourceArray2 destArray) (println "For random source, result should be close to 0 bits : " (.computeAverageLocalOfObservations teCalc)) ) ``` -------------------------------- ### Configure Multiple Data Files in MATLAB Source: https://github.com/jlizier/jidt/wiki/Flocking Demonstrates how to specify multiple data files using a cell array in the `properties.files` variable within a MATLAB script. This is useful when an analysis involves several data sources. ```matlab properties.files = {'positions1%s.txt', 'positions2%s.txt', 'positions3%s.txt', 'positions4%s.txt', 'positions5%s.txt'}; ``` -------------------------------- ### Calculate Transfer Entropy on Binary Data with Java Source: https://github.com/jlizier/jidt/wiki/SimpleJavaExamples Demonstrates calculating transfer entropy (TE) on binary data using the discrete TE calculator. It requires imports for `RandomGenerator` and `TransferEntropyCalculatorDiscrete`. The input is arrays of binary integers, and the output is the computed TE in bits. ```java // Requires the following imports before the class definition: // import infodynamics.utils.RandomGenerator; // import infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete; int arrayLengths = 100; RandomGenerator rg = new RandomGenerator(); // Generate some random binary data: int[] sourceArray = rg.generateRandomInts(arrayLengths, 2); int[] destArray = new int[arrayLengths]; destArray[0] = 0; System.arraycopy(sourceArray, 0, destArray, 1, arrayLengths - 1); int[] sourceArray2 = rg.generateRandomInts(arrayLengths, 2); // Create a TE calculator and run it: TransferEntropyCalculatorDiscrete teCalc= new TransferEntropyCalculatorDiscrete(2, 1); teCalc.initialise(); teCalc.addObservations(sourceArray, destArray); double result = teCalc.computeAverageLocalOfObservations(); System.out.printf("For copied source, result should be close to 1 bit : %.3f bits\n", result); teCalc.initialise(); teCalc.addObservations(sourceArray2, destArray); double result2 = teCalc.computeAverageLocalOfObservations(); System.out.printf("For random source, result should be close to 0 bits: %.3f bits\n", result2); ``` -------------------------------- ### Load Data and Extract Variables in Julia Source: https://github.com/jlizier/jidt/wiki/JuliaExamples This section of the Julia code demonstrates loading data from a file and extracting specific columns corresponding to the defined variables. It uses the `readdlm` function for data loading and array slicing for column extraction. ```julia data = readdlm(datafile, ' ', '\n') variable1 = data[:, variable1Columns]; variable2 = data[:, variable2Columns]; ```