pwollstadt / IDTxl

The Information Dynamics Toolkit xl (IDTxl) is a comprehensive software package for efficient inference of networks and their node dynamics from multivariate time series data using information theory.
http://pwollstadt.github.io/IDTxl/
GNU General Public License v3.0
249 stars 76 forks source link

analyse_single_target() returns "no attribute error" #52

Closed thosvarley closed 4 years ago

thosvarley commented 4 years ago

I am trying to run the single target analyzer and it keeps throwing the same Java error. Here is the code taken directly from the documentation:

data = Data();
data.generate_mute_data(100, 5);
settings = {
     'cmi_estimator':  'JidtKraskovCMI',
     'n_perm_max_stat': 200,
     'n_perm_min_stat': 200,
     'n_perm_omnibus': 500,
     'n_perm_max_seq': 500,
     'max_lag_sources': 5,
     'min_lag_sources': 2
     };
target = 0;
sources = [1, 2, 3];
network_analysis = MultivariateTE();
results = network_analysis.analyse_single_target(settings,data, target, sources)

And it returns:

 File "<ipython-input-31-e66db774bb1f>", line 15, in <module>
    results = network_analysis.analyse_single_target(settings,data, target, sources)

  File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/multivariate_te.py", line 270, in analyse_single_target
    self._initialise(settings, data, sources, target)

  File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/network_inference.py", line 371, in _initialise
    self._set_cmi_estimator()

  File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/network_analysis.py", line 209, in _set_cmi_estimator
    self._cmi_estimator = EstimatorClass(self.settings)

  File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/estimators_jidt.py", line 418, in __init__
    jp.JPackage('infodynamics.measures.continuous.kraskov').

AttributeError: Java package 'infodynamics.measures.continuous.kraskov' has no attribute 'ConditionalMutualInfoCalculatorMultiVariateKraskov1'

If I try other estimators, it's the same thing (just with the name of the estimator changed.

jlizier commented 4 years ago

Hi Thomas,

This is a strange one, I haven't seen an AttributeError from the jpype bridge to JIDT before. The jpype documentation says that an AttributeError is raised where the class cannot be found. If you've run the pip install for IDTxl (as per the installation instructions), it shouldn't be that. (Incidentally, if I refer to the wrong jar file, or class or package at my end, I get a TypeError, which is different again).

Let's start simpler, and see if we get get Python to call JIDT on your platform directly (outside of IDTxl). Instead of using the jar embedded with IDTxl, can you grab a distribution of JIDT (e.g. latest zip file distribution), run the AutoAnalyser to generate any example (as outlined here)? Once you've generated some code, run the Python code that was generated as directed in the section "Running the generated code files" -- and let me know if that generates an error

--joe

mwibral commented 4 years ago

Dear Thomas,

which jpype package did you install? In the past there has been some confusion about jpype versus jpype1 (the latter is what you need).

Best,

Michael

On 12.10.20 00:01, Thomas Varley wrote:

I am trying to run the single target analyzer and it keeps throwing the same Java error. Here is the code taken directly from the documentation:

|data = Data(); data.generate_mute_data(100, 5); settings = { 'cmi_estimator': 'JidtKraskovCMI', 'n_perm_max_stat': 200, 'n_perm_min_stat': 200, 'n_perm_omnibus': 500, 'n_perm_max_seq': 500, 'max_lag_sources': 5, 'min_lag_sources': 2 }; target = 0; sources = [1, 2, 3]; network_analysis = MultivariateTE(); results = network_analysis.analyse_single_target(settings,data, target, sources) |

And it returns:

|File "", line 15, in results = network_analysis.analyse_single_target(settings,data, target, sources) File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/multivariate_te.py", line 270, in analyse_single_target self._initialise(settings, data, sources, target) File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/network_inference.py", line 371, in _initialise self._set_cmi_estimator() File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/network_analysis.py", line 209, in _set_cmi_estimator self._cmi_estimator = EstimatorClass(self.settings) File "/home/thosvarley/miniconda3/lib/python3.8/site-packages/idtxl/estimators_jidt.py", line 418, in init jp.JPackage('infodynamics.measures.continuous.kraskov'). AttributeError: Java package 'infodynamics.measures.continuous.kraskov' has no attribute 'ConditionalMutualInfoCalculatorMultiVariateKraskov1' |

If I try other estimators, it's the same thing (just with the name of the estimator changed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pwollstadt/IDTxl/issues/52, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFJQGWNSOJIM3SZDZAVOJLSKITLPANCNFSM4SMBTG2A.

thosvarley commented 4 years ago

@jlizier Here's what came out of the JIDT AutoAnalyzer:

from jpype import *
import sys
import numpy
# Our python data file readers are a bit of a hack, python users will do better on this:
sys.path.append("/home/thosvarley/Downloads/jidt/demos/python")
import readFloatsFile

# Add JIDT jar library to the path
jarLocation = "/home/thosvarley/Downloads/jidt/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)

# 0. Load/prepare the data:
dataRaw = readFloatsFile.readFloatsFile("/home/thosvarley/Downloads/jidt/demos/data/10ColsGaussianSelfDependence2Steps.txt")
# As numpy array:
data = numpy.array(dataRaw)
source = data[:,0]
destination = data[:,1]

# 1. Construct the calculator:
calcClass = JPackage("infodynamics.measures.continuous.kraskov").TransferEntropyCalculatorKraskov
calc = calcClass()
# 2. Set any properties to non-default values:
# No properties were set to non-default values
# 3. Initialise the calculator for (re-)use:
calc.initialise()
# 4. Supply the sample data:
calc.setObservations(source, destination)
# 5. Compute the estimate:
result = calc.computeAverageLocalOfObservations()

print("TE_Kraskov (KSG)(col_0 -> col_1) = %.4f nats" %
    (result))

And it returns:

TE_Kraskov (KSG)(col_0 -> col_1) = 0.0118 nats

@mwibral - I've got jpype1.

jpype1 in ./miniconda3/lib/python3.8/site-packages (1.0.2)

All the best ~Thomas

jlizier commented 4 years ago

Thanks Thomas - ok, it looks like jpype1 is working fine then, so we can eliminate that. (To confirm first though, the return line TE_Kraskov (KSG)(col_0 -> col_1) = 0.0118 nats is what's being output when you run that code yourself in python, right, it's not from the AutoAnalyser console? Am just checking as it's rather unusual for the jpype1 bridge to work in JIDT but not IDTxl; I was asking for this test hoping to just get closer to the error ...)

thosvarley commented 4 years ago

@jlizier yes, the TE_Kraskov line is what happens when I run the JIDT output in Spyder (not the Autoanalyzer).

thosvarley commented 4 years ago

This appears to have mysteriously resolved itself with a clean install and is currently running on my workstation. Thanks to Joe and Michael for talking the time to talk me though it. Leaving open in case someone else runs into this problem, as I'm not entirely sure what original went wrong or why it's fixed.

jlizier commented 4 years ago

Great, thanks Thomas. I'm going to close it since it's no longer possible to reproduce. My gut feeling was still that it was a Java path issue in running Spyder from a different location to what was expected; we can check if it comes up again. Others will still be able to match to this and we can reopen if required.