-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_probabilities.py
133 lines (112 loc) · 5.11 KB
/
test_probabilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# test_probabilities.py ---
#
# Filename: test_probabilities.py
# Description:
# Author:
# Maintainer:
# Created: Thu Mar 22 15:05:41 2012 (+0530)
# Version:
# Last-Updated: Mon Apr 2 11:24:55 2012 (+0530)
# By: subha
# Update #: 78
# URL:
# Keywords:
# Compatibility:
#
#
# Commentary:
#
#
#
#
# Change log:
#
#
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
#
#
# Code:
import unittest
from probabilities import SpikeCondProb, dump_stimulus_linked_probabilities
class TestSpikeCondProb(unittest.TestCase):
def setUp(self):
self.datafilepath = 'test_data/data.h5'
self.netfilepath = 'test_data/network.h5'
self.netfile_new_path = 'test_data/network_new.h5'
self.test_object = SpikeCondProb(self.datafilepath, self.netfilepath, self.netfile_new_path)
def test_calc_spike_prob(self):
spike_prob = self.test_object.calc_spike_prob('TCR_0', 'SupPyrRS_1', 10e-3, 10e-3)
self.assertAlmostEqual(spike_prob, 0.5)
def test_calc_spike_prob_all_connected(self):
spike_prob = self.test_object.calc_spike_prob_all_connected(10e-3, 10e-3)
self.assertAlmostEqual(spike_prob['TCR_0-SupPyrRS_1'], 0.5)
def test_calc_spike_prob_all_unconnected(self):
spike_prob = self.test_object.calc_spike_prob_all_unconnected(10e-3, 10e-3)
self.assertAlmostEqual(spike_prob['TCR_0-SupPyrRS_0'], 0.2)
def test_calc_prespike_prob_excitatory_connected(self):
# Only 5 entries in TCR_0 are within (-15 ms, -5 ms) of spike
# time in SupPyrRS.
spike_prob = self.test_object.calc_prespike_prob_excitatory_connected(10e-3, 15e-3)
self.assertAlmostEqual(spike_prob['TCR_0-SupPyrRS_1'], 0.5)
def test_calc_prespike_prob_excitatory_unconnected(self):
spike_prob = self.test_object.calc_prespike_prob_excitatory_unconnected(5e-3, 10e-3)
self.assertAlmostEqual(spike_prob['TCR_1-SupPyrRS_1'], 0.1)
def test_calc_spike_prob_after_bgstim(self):
"""For this test data.h5 file has a /stimulus/stim_bg with
stimulus from 1.498 s to 1.5 s, second stimulus from 3.0 to
3.02 s and a third stimulus from 4.75 s to 4.77 s. Only the
spike after the first one (at 1.513 s) and the third one will be counted."""
spike_prob = self.test_object.calc_spike_prob_after_bgstim('SupPyrRS_1', 0.02, 0.01)
self.assertAlmostEqual(spike_prob, 1.0)
def test_calc_spike_prob_after_probestim(self):
spike_prob = self.test_object.calc_spike_prob_after_probestim('SupPyrRS_1', 0.02, 0.01)
self.assertAlmostEqual(spike_prob, 0.0)
def test_calc_spikecount_avg_after_bgstim(self):
"""In the spike train there is 1 spiek after 1.51 s and two
spikes after 4.78 s (4.78575 s and 4.82025 s, which is between
0.4 s amd 0.5 s after the window start."""
spike_count_avg = self.test_object.calc_spikecount_avg_after_bgstim('SupPyrRS_1', 0.05, 0.01)
self.assertAlmostEqual(spike_count_avg, 1.5)
def test_calc_spikecount_avg_after_probestim(self):
"""In the spike train there is 1 spike at 3.52325 s. The probe
stimulus ends at 3.0 s. So a delay of 0.5 s with width of 0.05
s captures this."""
spike_count_avg = self.test_object.calc_spikecount_avg_after_probestim('SupPyrRS_1', 0.05, 0.5)
self.assertAlmostEqual(spike_count_avg, 1.0)
def test_dump_stimulus_linked_probabilities(self):
filelist = ['/data/subha/rsync_ghevar_cortical_data_clone/2012_03_22/data_20120322_114922_24526.h5']
dump_stimulus_linked_probabilities(filelist, [0.01, 0.02, 0.03, 0.04, 0.05], [0.0, 0.05])
def test_get_bg_shortest_path_lengths(self):
"""The network_new.h5 file has only one TCR cell connected to a background stimulus.
This cell is connected to one of the
"""
lengths = self.test_object.get_bg_shortest_path_lengths()
self.assertEqual(len(lengths), 1)
self.assertEqual(len(lengths[lengths.keys()[0]]), 2)
def test_get_probe_shortest_path_lengths(self):
"""The network_new.h5 file has only one TCR cell (TCR_0)
connected to the probe stimulus. This cell is connected to
one of the
"""
lengths = self.test_object.get_probe_shortest_path_lengths()
self.assertEqual(len(lengths), 1)
self.assertEqual(len(lengths[lengths.keys()[0]]), 2)
if __name__ == '__main__':
unittest.main()
#
# test_probabilities.py ends here