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

[ENH] Integrate trials object with Fano factor #645

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4011266
add handling for trial object
Moritz-Alexander-Kern Oct 22, 2024
218a653
add tests
Moritz-Alexander-Kern Oct 22, 2024
ed5ca52
Merge branch 'master' into enh/trials_fano_factor
Moritz-Alexander-Kern Nov 14, 2024
29694fa
add tests for trial object pooling trials or spiketrains
Moritz-Alexander-Kern Nov 14, 2024
1711f43
add parameters pool_trials, pool_spiketrains
Moritz-Alexander-Kern Nov 14, 2024
7b0ccf9
add type check for pool parameters
Moritz-Alexander-Kern Nov 14, 2024
1925bf3
refactor type annotations
Moritz-Alexander-Kern Nov 14, 2024
3c1eb5d
add to docstring
Moritz-Alexander-Kern Nov 14, 2024
6bb2fc3
add user warning and did refactoring of function
Moritz-Alexander-Kern Nov 14, 2024
69a4d24
remove pool trials parameter
Moritz-Alexander-Kern Dec 10, 2024
5b1cf75
add paramter ignored for spiketrainslist to docstring
Moritz-Alexander-Kern Dec 10, 2024
303f363
remove user warning to manually check duration for numpy arrays
Moritz-Alexander-Kern Dec 10, 2024
e9e6778
remove pool_trials arg
Moritz-Alexander-Kern Dec 10, 2024
663b1c8
remove pool_trials from fano-factor
Moritz-Alexander-Kern Jan 13, 2025
381ae35
remove test for type error
Moritz-Alexander-Kern Jan 13, 2025
58e202b
Merge branch 'master' into enh/trials_fano_factor
Moritz-Alexander-Kern Jan 13, 2025
b75355a
fix docstring for return value
Moritz-Alexander-Kern Jan 13, 2025
fce4427
add test for results to fano factor
Moritz-Alexander-Kern Jan 14, 2025
f776d04
Merge branch 'master' into enh/trials_fano_factor
Moritz-Alexander-Kern Jan 14, 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
Prev Previous commit
Next Next commit
add tests for trial object pooling trials or spiketrains
  • Loading branch information
Moritz-Alexander-Kern committed Nov 14, 2024
commit 29694faab2c4d6a8dc1d4fb3244fc77d6b1ebc7b
53 changes: 33 additions & 20 deletions elephant/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,28 @@ def test_mean_firing_rate_with_plain_array_and_units_start_stop_typeerror(


class FanoFactorTestCase(unittest.TestCase):
def setUp(self):
@classmethod
def setUpClass(cls):
np.random.seed(100)
num_st = 300
self.test_spiketrains = []
self.test_array = []
self.test_quantity = []
self.test_list = []
self.sp_counts = np.zeros(num_st)
cls.test_spiketrains = []
cls.test_array = []
cls.test_quantity = []
cls.test_list = []
cls.sp_counts = np.zeros(num_st)
for i in range(num_st):
r = np.random.rand(np.random.randint(20) + 1)
st = neo.core.SpikeTrain(r * pq.ms,
t_start=0.0 * pq.ms,
t_stop=20.0 * pq.ms)
self.test_spiketrains.append(st)
self.test_array.append(r)
self.test_quantity.append(r * pq.ms)
self.test_list.append(list(r))
cls.test_spiketrains.append(st)
cls.test_array.append(r)
cls.test_quantity.append(r * pq.ms)
cls.test_list.append(list(r))
# for cross-validation
self.sp_counts[i] = len(st)
cls.sp_counts[i] = len(st)

self.test_trials = TrialsFromLists([self.test_spiketrains, self.test_spiketrains])
cls.test_trials = TrialsFromLists([cls.test_spiketrains, cls.test_spiketrains])

def test_fanofactor_spiketrains(self):
# Test with list of spiketrains
Expand Down Expand Up @@ -353,14 +354,26 @@ def test_fanofactor_wrong_type(self):
self.assertRaises(TypeError, statistics.fanofactor, [st1],
warn_tolerance=1e-4)

def test_fanofactor_trials(self):
# Test with Trial object
self.assertEqual(
np.var(self.sp_counts) / np.mean(self.sp_counts),
statistics.fanofactor(self.test_trials)[0])
self.assertEqual(
np.var(self.sp_counts) / np.mean(self.sp_counts),
statistics.fanofactor(self.test_trials)[1])
def test_fanofactor_trials_pool_spiketrains(self):
results = statistics.fanofactor(self.test_trials, pool_spike_trains=True)
self.assertEqual(len(results), self.test_trials.n_trials)
for result in results:
self.assertEqual(
np.var(self.sp_counts) / np.mean(self.sp_counts), result)

def test_fanofactor_trials_pool_trials(self):
results = statistics.fanofactor(self.test_trials, pool_trials=True)
self.assertEqual(len(results), self.test_trials.n_spiketrains_trial_by_trial[0])

def test_fanofactor_trials_pool_trials_pool_spiketrains(self):
results = statistics.fanofactor(self.test_trials, pool_trials=True, pool_spike_trains=True)
self.assertEqual(len(results), 1)

def test_fanofactor_trials_pool_trials_false_pool_spiketrains_false(self):
results = statistics.fanofactor(self.test_trials, pool_trials=False, pool_spike_trains=False)
self.assertEqual(len(results), self.test_trials.n_trials)
for result in results:
self.assertEqual(len(result), self.test_trials.n_spiketrains_trial_by_trial[0])


class LVTestCase(unittest.TestCase):
Expand Down