Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in instantaneous rate when passing a 1-dimensional kernel sigma [Bug] #455

Closed
Kleinjohann opened this issue Feb 21, 2022 · 1 comment · Fixed by #499
Closed

Error in instantaneous rate when passing a 1-dimensional kernel sigma [Bug] #455

Kleinjohann opened this issue Feb 21, 2022 · 1 comment · Fixed by #499
Labels
bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@Kleinjohann
Copy link
Contributor

Describe the bug
When passing a more than 0-dimensional sigma in the generation of a kernel and using said kernel to calculate the instantaneous firing rate an error is raised somewhere in fftconvolve.

To Reproduce

import neo
import elephant
import quantities as pq

st = neo.SpikeTrain([1]*pq.s, t_stop=2*pq.s)
kernel = elephant.kernels.GaussianKernel(sigma=[20]*pq.ms)

rate = elephant.statistics.instantaneous_rate(st,
                                              sampling_period=1*pq.ms,
                                              kernel=kernel)

returns

Traceback (most recent call last):
  File "reproduce_sigma_error.py", line 9, in <module>
    rate = elephant.statistics.instantaneous_rate(st,
  File "/home/kleinjohann/software/elephant/elephant/utils.py", line 79, in wrapper
    return func(*args, **kwargs)
  File "/home/kleinjohann/software/elephant/elephant/statistics.py", line 868, in instantaneous_rate
    rate = scipy.signal.fftconvolve(time_vectors,
  File "/home/kleinjohann/software/miniconda3/envs/elephant/lib/python3.8/site-packages/scipy/signal/signaltools.py", line 525, in fftconvolve
    raise ValueError("in1 and in2 should have the same dimensionality")
ValueError: in1 and in2 should have the same dimensionality

I tracked this down to

t_arr = np.linspace(-cutoff_sigma + median, stop=cutoff_sigma + median,

where t_arr gains an extra dimension since cutoff_sigma keeps the extra dimension of sigma.

Expected behavior
Either a more helpful error should be raised which tells me to fix the dimensionality of sigma, or different dimensionalities should be accounted for internally and no error should be raised.

Environment

  • OS: Linux
  • How I installed elephant: from source
  • Python version: 3.8.1
  • neo python package version: 0.9.0
  • elephant version: d0d3920
  • scipy version: 1.5.4
@Moritz-Alexander-Kern Moritz-Alexander-Kern added the bug Indicates an unexpected problem or unintended behavior label Feb 23, 2022
@Moritz-Alexander-Kern
Copy link
Member

Moritz-Alexander-Kern commented Feb 23, 2022

Thanks for reporting this.
I get the same error.

We will look into this, currently elephant.statistics.instantaneous_rate is undergoing changes with PR #453 in relation to #374.

@Moritz-Alexander-Kern Moritz-Alexander-Kern added this to the v0.12.0 milestone Apr 14, 2022
@Moritz-Alexander-Kern Moritz-Alexander-Kern linked a pull request Jun 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants