From c5205cb8415a63a20b329b8b774119a671f472d2 Mon Sep 17 00:00:00 2001 From: Simon Gimmini Date: Wed, 7 Sep 2022 15:39:43 +1000 Subject: [PATCH 1/4] resolved deprecation warning --- demos/python/example1TeBinaryData.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/python/example1TeBinaryData.py b/demos/python/example1TeBinaryData.py index 78556ab3..a47f79c3 100755 --- a/demos/python/example1TeBinaryData.py +++ b/demos/python/example1TeBinaryData.py @@ -52,8 +52,8 @@ # Next, demonstrate how to do this with a numpy array teCalc.initialise() # Create the numpy arrays: -sourceNumpy = numpy.array(sourceArray, dtype=numpy.int) -destNumpy = numpy.array(destArray, dtype=numpy.int) +sourceNumpy = numpy.array(sourceArray, dtype=int) +destNumpy = numpy.array(destArray, dtype=int) # The above can be passed straight through to JIDT in python 2: # teCalc.addObservations(sourceNumpy, destNumpy) # But you need to do this in python 3: From bca1ff9f5446862379b2bb86e1384344379c14d2 Mon Sep 17 00:00:00 2001 From: Simon Gimmini Date: Wed, 7 Sep 2022 18:17:22 +1000 Subject: [PATCH 2/4] resolve TypeError for java Strings --- demos/python/example9TeKraskovAutoEmbedding.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/python/example9TeKraskovAutoEmbedding.py b/demos/python/example9TeKraskovAutoEmbedding.py index 6c0df669..ba91729d 100644 --- a/demos/python/example9TeKraskovAutoEmbedding.py +++ b/demos/python/example9TeKraskovAutoEmbedding.py @@ -33,7 +33,8 @@ if (not(os.path.isfile(jarLocation))): exit("infodynamics.jar not found (expected at " + os.path.abspath(jarLocation) + ") - are you running from demos/python?") # 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) +# see: https://jpype.readthedocs.io/en/latest/api.html#jpype.startJVM and https://stackoverflow.com/questions/64841426/duckling-int-argument-must-be-a-string-a-bytes-like-object-or-a-number-not +startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation, convertStrings=True) # Examine the heart-breath interaction that Schreiber originally looked at: datafile = '../data/SFI-heartRate_breathVol_bloodOx.txt' From d8d16cf24e52e60512ba7a7757b59e794bc908e0 Mon Sep 17 00:00:00 2001 From: Joseph Lizier Date: Thu, 8 Sep 2022 10:24:43 +1000 Subject: [PATCH 3/4] Removing changes to python example1 as these are already committed in my branch and about to be pushed ... --- demos/python/example1TeBinaryData.py | 66 ---------------------------- 1 file changed, 66 deletions(-) delete mode 100755 demos/python/example1TeBinaryData.py diff --git a/demos/python/example1TeBinaryData.py b/demos/python/example1TeBinaryData.py deleted file mode 100755 index a47f79c3..00000000 --- a/demos/python/example1TeBinaryData.py +++ /dev/null @@ -1,66 +0,0 @@ -## -## Java Information Dynamics Toolkit (JIDT) -## Copyright (C) 2012, Joseph T. Lizier -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program. If not, see . -## - -# = Example 1 - Transfer entropy on binary data = - -# Simple transfer entropy (TE) calculation on binary data using the discrete TE calculator: - -import jpype -import random -import numpy -import os - -# Change location of jar to match yours (we assume script is called from demos/python): -jarLocation = os.path.join(os.getcwd(), "..", "..", "infodynamics.jar"); -if (not(os.path.isfile(jarLocation))): - exit("infodynamics.jar not found (expected at " + os.path.abspath(jarLocation) + ") - are you running from demos/python?") -# Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space) -jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation) - -# Generate some random binary data. -sourceArray = [random.randint(0,1) for r in range(100)] -destArray = [0] + sourceArray[0:99] -sourceArray2 = [random.randint(0,1) for r in range(100)] - -# Create a TE calculator and run it: -teCalcClass = jpype.JPackage("infodynamics.measures.discrete").TransferEntropyCalculatorDiscrete -teCalc = teCalcClass(2,1) -teCalc.initialise() - -# First use simple arrays of ints, which we can directly pass in: -teCalc.addObservations(sourceArray, destArray) -print("For copied source, result should be close to 1 bit : %.4f" % teCalc.computeAverageLocalOfObservations()) -teCalc.initialise() -teCalc.addObservations(sourceArray2, destArray) -print("For random source, result should be close to 0 bits: %.4f" % teCalc.computeAverageLocalOfObservations()) - -# Next, demonstrate how to do this with a numpy array -teCalc.initialise() -# Create the numpy arrays: -sourceNumpy = numpy.array(sourceArray, dtype=int) -destNumpy = numpy.array(destArray, dtype=int) -# The above can be passed straight through to JIDT in python 2: -# teCalc.addObservations(sourceNumpy, destNumpy) -# But you need to do this in python 3: -sourceNumpyJArray = jpype.JArray(jpype.JInt, 1)(sourceNumpy.tolist()) -destNumpyJArray = jpype.JArray(jpype.JInt, 1)(destNumpy.tolist()) -teCalc.addObservations(sourceNumpyJArray, destNumpyJArray) -print("Using numpy array for copied source, result confirmed as: %.4f" % teCalc.computeAverageLocalOfObservations()) - -jpype.shutdownJVM() - From dca33da1d131d5a446697223f798743449b5c2b0 Mon Sep 17 00:00:00 2001 From: Simon Gimmini Date: Sun, 11 Sep 2022 09:35:58 +1000 Subject: [PATCH 4/4] restore deleted example code --- demos/python/example1TeBinaryData.py | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 demos/python/example1TeBinaryData.py diff --git a/demos/python/example1TeBinaryData.py b/demos/python/example1TeBinaryData.py new file mode 100644 index 00000000..a47f79c3 --- /dev/null +++ b/demos/python/example1TeBinaryData.py @@ -0,0 +1,66 @@ +## +## Java Information Dynamics Toolkit (JIDT) +## Copyright (C) 2012, Joseph T. Lizier +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . +## + +# = Example 1 - Transfer entropy on binary data = + +# Simple transfer entropy (TE) calculation on binary data using the discrete TE calculator: + +import jpype +import random +import numpy +import os + +# Change location of jar to match yours (we assume script is called from demos/python): +jarLocation = os.path.join(os.getcwd(), "..", "..", "infodynamics.jar"); +if (not(os.path.isfile(jarLocation))): + exit("infodynamics.jar not found (expected at " + os.path.abspath(jarLocation) + ") - are you running from demos/python?") +# Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space) +jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation) + +# Generate some random binary data. +sourceArray = [random.randint(0,1) for r in range(100)] +destArray = [0] + sourceArray[0:99] +sourceArray2 = [random.randint(0,1) for r in range(100)] + +# Create a TE calculator and run it: +teCalcClass = jpype.JPackage("infodynamics.measures.discrete").TransferEntropyCalculatorDiscrete +teCalc = teCalcClass(2,1) +teCalc.initialise() + +# First use simple arrays of ints, which we can directly pass in: +teCalc.addObservations(sourceArray, destArray) +print("For copied source, result should be close to 1 bit : %.4f" % teCalc.computeAverageLocalOfObservations()) +teCalc.initialise() +teCalc.addObservations(sourceArray2, destArray) +print("For random source, result should be close to 0 bits: %.4f" % teCalc.computeAverageLocalOfObservations()) + +# Next, demonstrate how to do this with a numpy array +teCalc.initialise() +# Create the numpy arrays: +sourceNumpy = numpy.array(sourceArray, dtype=int) +destNumpy = numpy.array(destArray, dtype=int) +# The above can be passed straight through to JIDT in python 2: +# teCalc.addObservations(sourceNumpy, destNumpy) +# But you need to do this in python 3: +sourceNumpyJArray = jpype.JArray(jpype.JInt, 1)(sourceNumpy.tolist()) +destNumpyJArray = jpype.JArray(jpype.JInt, 1)(destNumpy.tolist()) +teCalc.addObservations(sourceNumpyJArray, destNumpyJArray) +print("Using numpy array for copied source, result confirmed as: %.4f" % teCalc.computeAverageLocalOfObservations()) + +jpype.shutdownJVM() +