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

Fix/onedimensional sigma #499

Merged
merged 3 commits into from
Oct 13, 2022

Conversation

Moritz-Alexander-Kern
Copy link
Member

This PR addresses Issue #455 .

Changes

  • check dimensions of sigma, if dimension > 0 , raise typeError
  • handle unambiguous case ndim=1 , size = 1 with sigma = sigma[0]
  • added tests for both above cases

Test

The following code snippet should no longer throw an error

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)

Moritz-Alexander-Kern added 3 commits June 28, 2022 10:39
@Moritz-Alexander-Kern Moritz-Alexander-Kern added the bugfix Fix for an indentified bug. label Jun 30, 2022
@Moritz-Alexander-Kern Moritz-Alexander-Kern added this to the v0.11.2 milestone Jul 18, 2022
Copy link
Contributor

@Kleinjohann Kleinjohann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix, I can confirm that my use case that originally caused this error is covered by this.

@@ -142,6 +146,13 @@ def __init__(self, sigma, invert=False):
if not isinstance(sigma, pq.Quantity):
raise TypeError("'sigma' must be a quantity")

if sigma.ndim > 0:
# handle the one-dimensional case of size 1
if sigma.ndim == 1 & sigma.size == 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side remark:
This will also catch something like sigma = [[5]] * pq.s
Seems fine to me though, since a meaningful error is raised in that case now.

Copy link
Member

@mdenker mdenker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that in the long run -- besides this not being Python -- we may want to have a more standard way to check types, and in particular the case of 0, 1 and 2 dimensional quantities arrays.

@mdenker mdenker merged commit 5885fff into NeuralEnsemble:master Oct 13, 2022
@Moritz-Alexander-Kern Moritz-Alexander-Kern deleted the fix/onedimensional_sigma branch October 17, 2022 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix for an indentified bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in instantaneous rate when passing a 1-dimensional kernel sigma [Bug]
3 participants