jakobrunge / tigramite

Tigramite is a python package for causal inference with a focus on time series data. The Tigramite documentation is at
https://jakobrunge.github.io/tigramite/
GNU General Public License v3.0
1.32k stars 276 forks source link

AttributeError: 'range' object has no attribute 'size' #38

Closed shaypal5 closed 5 years ago

shaypal5 commented 5 years ago

Hey again! :)

I'm getting an AttributeError: 'range' object has no attribute 'size' error thrown when running run_pcmci. The error is thrown from one of the functions in independence_tests.py when it calls Scipy's curve_fit function.

I'm attaching the full log below, which includes the parameters with which the PCMCI object was initialized, and the ones with which run_pcmci was called. I'll add a data example soon.

Thank you again, Shay

##
## Running Tigramite PC algorithm
##

Parameters:
selected_variables = [5, 6, 7, 8, 9, 10, 11, 12]
independence test = cmi_knn
tau_min = 1
tau_max = 24
pc_alpha = 0.1
max_conds_dim = None
max_combinations = 1

Warning: Link specified in selected links that is outside the scope of the selected variables

## Variable i0

Iterating through pc_alpha = [0.1]:

# pc_alpha = 0.1 (1/1):

Testing condition sets of dimension 0:

    Link (c0 -1) --> i0 (1/312):
Traceback (most recent call last):
  File "/usr/local/bin/poseidon", line 11, in <module>
    load_entry_point('poseidon', 'console_scripts', 'poseidon')()
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/poseidon-app/poseidon_package/scripts/poseidon_cli.py", line 51, in infer_causality
    timestep_len_in_seconds=tsteplen,
  File "/poseidon-app/poseidon_package/poseidon/core.py", line 124, in run_poseidon
    timestep_in_sec=timestep_len_in_seconds,
  File "/poseidon-app/poseidon_package/poseidon/infer_causality.py", line 261, in infer_causality
    results = pcmci.run_pcmci(tau_max=max_lag, pc_alpha=alpha)
  File "/poseidon-app/tigramite/tigramite/pcmci.py", line 1567, in run_pcmci
    max_combinations=max_combinations)
  File "/poseidon-app/tigramite/tigramite/pcmci.py", line 896, in run_pc_stable
    max_combinations=max_combinations)
  File "/poseidon-app/tigramite/tigramite/pcmci.py", line 602, in _run_pc_stable_single
    tau_max=tau_max)
  File "/poseidon-app/tigramite/tigramite/independence_tests.py", line 335, in run_test
    pval = self.get_significance(val, array, xyz, T, dim)
  File "/poseidon-app/tigramite/tigramite/independence_tests.py", line 453, in get_significance
    value=val)
  File "/poseidon-app/tigramite/tigramite/independence_tests.py", line 2175, in get_shuffle_significance
    verbosity=self.verbosity)
  File "/poseidon-app/tigramite/tigramite/independence_tests.py", line 813, in _get_shuffle_dist
    mode='significance')
  File "/poseidon-app/tigramite/tigramite/independence_tests.py", line 754, in _get_block_length
    popt, _ = optimize.curve_fit(func, range(0, max_lag+1), hilbert)
  File "/usr/local/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 718, in curve_fit
    if xdata.size == 0:
AttributeError: 'range' object has no attribute 'size'
shaypal5 commented 5 years ago

Hey,

Here's the example input that is provided to the dataframe parameter of the PCMCI constructor (as a tigramite DataFrame object), for which runnning run_pcmci brings about the above error.

tigramite_issue_38_input_example.csv.zip

Thank you again, Shay

shaypal5 commented 5 years ago

For ease of issue reproducibility, I'm also attaching here a minimal script the reproduces the problem. If run in the same folder where the above tigramite_issue_38_input_example.csv file is unpacked, it produces the exact same error .

(updated example on June 12th, 2019)

example_issue_38.py.zip

shaypal5 commented 5 years ago

This should be solved by PR #39 . :) I hope this gets merged.

jakobrunge commented 5 years ago

Thanks!!!