Skip to content
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f70c9cd
Added schemas Folder with __init__.py
JanNolten Nov 7, 2025
e007679
Added field_validator.py to group repeated validation
JanNolten Nov 7, 2025
ccac5cc
Added field_serializer.py to group repeated serialization
JanNolten Nov 7, 2025
11c2a35
added function_validator.py to validate elephant functions
JanNolten Nov 7, 2025
46ff38b
Added Pydantic Models for statistics
JanNolten Nov 7, 2025
5fb18dc
Added Pydantic Models for spike_train_correlation
JanNolten Nov 7, 2025
d5324bf
Added Pydantic Models for spike_train_synchrony
JanNolten Nov 7, 2025
c99b6c0
Original arguments are passed into the function
JanNolten Nov 7, 2025
cb533cc
Added pytest.ini to .gitignore
JanNolten Nov 7, 2025
71b7dc0
Added tests and option to skip validation
JanNolten Nov 7, 2025
7f4f5ef
Transfering Bug fixes
JanNolten Nov 7, 2025
b282cc3
Transfering Bug fixes
JanNolten Nov 7, 2025
9c3402a
Transfering Bug fixes
JanNolten Nov 7, 2025
ac00866
Implemented validation for statistics
JanNolten Nov 7, 2025
a95f9f8
Implemented validation for spike_train_correlation
JanNolten Nov 7, 2025
69745c2
Implemented validation for spike_train_synchrony
JanNolten Nov 7, 2025
460e9cd
Allowed some ValueErrors to also be TypeErrors
JanNolten Nov 7, 2025
bf9b837
Merge branch 'NeuralEnsemble:master' into feature/partial
JanNolten Nov 7, 2025
fac02e1
Removed ; at end of lines
JanNolten Nov 10, 2025
4fdd64a
Added Pydantic to requirements
JanNolten Nov 10, 2025
b5f0ff7
Merge branch 'NeuralEnsemble:master' into feature/partial
JanNolten Nov 11, 2025
7d933a4
Removed Self from typing, because it only works in python>=3.11.0
JanNolten Nov 11, 2025
932f1d4
Added ability to disable validation globally
JanNolten Nov 11, 2025
1f58b12
Allow t_start to be negative because it should be able to be used tha…
JanNolten Nov 11, 2025
6f2b7d3
Allowed all t_start and t_stop to be negative, becuase they could be …
JanNolten Nov 18, 2025
c46228d
Removed the option to skip validation with the extra kwargs not_valid…
JanNolten Nov 24, 2025
ae94ee6
Simplified test to make them more understandable
JanNolten Nov 24, 2025
ca247c0
Make test stricter by checking for the exact Error Type. Also Fixed Bugs
JanNolten Nov 24, 2025
91df787
Forgot to remove a print statement
JanNolten Nov 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions elephant/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
from elephant.utils import deprecated_alias, check_neo_consistency, \
is_time_quantity, round_binning_errors

from elephant.schemas.function_validator import validate_with
from elephant.schemas.schema_statistics import *;

# do not import unicode_literals
# (quantities rescale does not work with unicodes)

Expand All @@ -102,9 +105,12 @@
"optimal_kernel_bandwidth"
]

cv = scipy.stats.variation
@validate_with(PydanticCv)
def cv(*args, **kwargs):
return scipy.stats.variation(*args, **kwargs)
Copy link
Author

@JanNolten JanNolten Nov 20, 2025

Choose a reason for hiding this comment

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

This is the simplest way I found, to use a decorator for cv, but maybe it could be done without changing the previous code.



@validate_with(PydanticIsi)
def isi(spiketrain, axis=-1):
"""
Return an array containing the inter-spike intervals of the spike train.
Expand Down Expand Up @@ -155,7 +161,7 @@ def isi(spiketrain, axis=-1):

return intervals


@validate_with(PydanticMeanFiringRate)
def mean_firing_rate(spiketrain, t_start=None, t_stop=None, axis=None):
"""
Return the firing rate of the spike train.
Expand Down Expand Up @@ -270,6 +276,7 @@ def mean_firing_rate(spiketrain, t_start=None, t_stop=None, axis=None):
return rates


@validate_with(PydanticFanofactor)
def fanofactor(spiketrains, warn_tolerance=0.1 * pq.ms):
r"""
Evaluates the empirical Fano factor F of the spike counts of
Expand Down Expand Up @@ -373,6 +380,7 @@ def __variation_check(v, with_nan):
return None


@validate_with(PydanticCv2)
@deprecated_alias(v='time_intervals')
def cv2(time_intervals, with_nan=False):
r"""
Expand Down Expand Up @@ -441,6 +449,7 @@ def cv2(time_intervals, with_nan=False):
return 2. * np.mean(np.abs(cv_i))


@validate_with(PydanticLv)
@deprecated_alias(v='time_intervals')
def lv(time_intervals, with_nan=False):
r"""
Expand Down Expand Up @@ -508,6 +517,7 @@ def lv(time_intervals, with_nan=False):
return 3. * np.mean(np.power(cv_i, 2))


@validate_with(PydanticLvr)
def lvr(time_intervals, R=5*pq.ms, with_nan=False):
r"""
Calculate the measure of revised local variation LvR for a sequence of time
Expand Down Expand Up @@ -600,6 +610,7 @@ def lvr(time_intervals, R=5*pq.ms, with_nan=False):
return lvr


@validate_with(PydanticInstantaneousRate)
@deprecated_alias(spiketrain='spiketrains')
def instantaneous_rate(spiketrains, sampling_period, kernel='auto',
cutoff=5.0, t_start=None, t_stop=None, trim=False,
Expand Down Expand Up @@ -1061,6 +1072,7 @@ def optimal_kernel(st):
return rate


@validate_with(PydanticTimeHistogram)
@deprecated_alias(binsize='bin_size')
def time_histogram(spiketrains, bin_size, t_start=None, t_stop=None,
output='counts', binary=False):
Expand Down Expand Up @@ -1204,6 +1216,7 @@ def _rate() -> pq.Quantity:
normalization=output)


@validate_with(PydanticComplexityPdf)
@deprecated_alias(binsize='bin_size')
def complexity_pdf(spiketrains, bin_size):
"""
Expand Down Expand Up @@ -1418,6 +1431,7 @@ class Complexity(object):

"""

@validate_with(PydanticComplexityInit)
def __init__(self, spiketrains,
sampling_rate=None,
bin_size=None,
Expand Down Expand Up @@ -1716,6 +1730,7 @@ def cost_function(x, N, w, dt):
return C, yh


@validate_with(PydanticOptimalKernelBandwidth)
@deprecated_alias(tin='times', w='bandwidth')
def optimal_kernel_bandwidth(spiketimes, times=None, bandwidth=None,
bootstrap=False):
Expand Down