示例#1
0
    def test_cpp_het(self):
        # testing output with generic inputs
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_het = stgen.cpp(rate, A, t_stop, t_start=t_start)
        # testing the ouput formats
        self.assertEqual([type(train) for train in cpp_het],
                         [neo.SpikeTrain] * len(cpp_het))
        self.assertEqual(cpp_het[0].simplified.units, 1000 * ms)
        self.assertEqual(type(cpp_het), list)
        # testing units
        self.assertEqual([train.simplified.units for train in cpp_het],
                         [1000 * ms] * len(cpp_het))
        # testing output t_start and t_stop
        for st in cpp_het:
            self.assertEqual(st.t_stop, t_stop)
            self.assertEqual(st.t_start, t_start)
        # testing the number of output spiketrains
        self.assertEqual(len(cpp_het), len(A) - 1)
        self.assertEqual(len(cpp_het), len(rate))

        # testing the units
        A = [0, 0.9, 0.1]
        t_stop = 10000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_unit = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(cpp_unit[0].units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_stop.units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_start.units, t_stop.units)
        # testing without copying any spikes
        A = [1, 0, 0]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_het_empty = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(len(cpp_het_empty[0]), 0)

        # testing output with rate equal to 0
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [0, 0] * Hz
        cpp_het_empty_r = stgen.cpp(rate, A, t_stop, t_start=t_start)
        self.assertEqual([len(train) for train in cpp_het_empty_r],
                         [0] * len(cpp_het_empty_r))

        # testing completely sync spiketrains
        A = [0, 0, 1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 3] * Hz
        cpp_het_eq = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertTrue(
            np.allclose(cpp_het_eq[0].magnitude, cpp_het_eq[1].magnitude))
示例#2
0
    def test_cpp_hom(self):
        # testing output with generic inputs
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom = stgen.cpp(rate, A, t_stop, t_start=t_start)
        # testing the ouput formats
        self.assertEqual([type(train) for train in cpp_hom],
                         [neo.SpikeTrain] * len(cpp_hom))
        self.assertEqual(cpp_hom[0].simplified.units, 1000 * ms)
        self.assertEqual(type(cpp_hom), list)
        # testing quantities format of the output
        self.assertEqual([train.simplified.units for train in cpp_hom],
                         [1000 * ms] * len(cpp_hom))
        # testing output t_start t_stop
        for st in cpp_hom:
            self.assertEqual(st.t_stop, t_stop)
            self.assertEqual(st.t_start, t_start)
        self.assertEqual(len(cpp_hom), len(A) - 1)

        # testing the units
        A = [0, 0.9, 0.1]
        t_stop = 10000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_unit = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(cpp_unit[0].units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_stop.units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_start.units, t_stop.units)

        # testing output without copy of spikes
        A = [1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom_empty = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual([len(train) for train in cpp_hom_empty],
                         [0] * len(cpp_hom_empty))

        # testing output with rate equal to 0
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 0 * Hz
        cpp_hom_empty_r = stgen.cpp(rate, A, t_stop, t_start=t_start)
        self.assertEqual([len(train) for train in cpp_hom_empty_r],
                         [0] * len(cpp_hom_empty_r))

        # testing output with same spike trains in output
        A = [0, 0, 1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom_eq = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertTrue(
            np.allclose(cpp_hom_eq[0].magnitude, cpp_hom_eq[1].magnitude))
示例#3
0
 def test_cpp_jttered(self):
     # testing output with generic inputs
     amplitude_distribution = np.array([0, .9, .1])
     t_stop = 10 * 1000 * pq.ms
     t_start = 5 * 1000 * pq.ms
     rate = 3 * pq.Hz
     cpp_shift = stgen.cpp(
         rate,
         amplitude_distribution,
         t_stop,
         t_start=t_start,
         shift=3 * pq.ms)
     # testing the ouput formats
     self.assertEqual(
         [type(train) for train in cpp_shift], [neo.SpikeTrain] * len(
             cpp_shift))
     self.assertEqual(cpp_shift[0].simplified.units, 1000 * pq.ms)
     self.assertEqual(type(cpp_shift), list)
     # testing quantities format of the output
     self.assertEqual(
         [train.simplified.units for train in cpp_shift],
         [1000 * pq.ms] * len(cpp_shift))
     # testing output t_start t_stop
     for spiketrain in cpp_shift:
         self.assertEqual(spiketrain.t_stop, t_stop)
         self.assertEqual(spiketrain.t_start, t_start)
     self.assertEqual(len(cpp_shift), len(amplitude_distribution) - 1)
示例#4
0
 def test_cpp_jttered(self):
     # testing output with generic inputs
     A = [0, .9, .1]
     t_stop = 10 * 1000 * ms
     t_start = 5 * 1000 * ms
     rate = 3 * Hz
     cpp_shift = stgen.cpp(rate, A, t_stop, t_start=t_start, shift=3 * ms)
     # testing the ouput formats
     self.assertEqual([type(train) for train in cpp_shift],
                      [neo.SpikeTrain] * len(cpp_shift))
     self.assertEqual(cpp_shift[0].simplified.units, 1000 * ms)
     self.assertEqual(type(cpp_shift), list)
     # testing quantities format of the output
     self.assertEqual([train.simplified.units for train in cpp_shift],
                      [1000 * ms] * len(cpp_shift))
     # testing output t_start t_stop
     for st in cpp_shift:
         self.assertEqual(st.t_stop, t_stop)
         self.assertEqual(st.t_start, t_start)
     self.assertEqual(len(cpp_shift), len(A) - 1)
 def test_cpp_jttered(self):
     # testing output with generic inputs
     A = [0, .9, .1]
     t_stop = 10 * 1000 * ms
     t_start = 5 * 1000 * ms
     rate = 3 * Hz
     cpp_shift = stgen.cpp(
         rate, A, t_stop, t_start=t_start, shift=3*ms)
     # testing the ouput formats
     self.assertEqual(
         [type(train) for train in cpp_shift], [neo.SpikeTrain]*len(
             cpp_shift))
     self.assertEqual(cpp_shift[0].simplified.units, 1000 * ms)
     self.assertEqual(type(cpp_shift), list)
     # testing quantities format of the output
     self.assertEqual(
         [train.simplified.units for train in cpp_shift],
         [1000 * ms]*len(cpp_shift))
     # testing output t_start t_stop
     for st in cpp_shift:
         self.assertEqual(st.t_stop, t_stop)
         self.assertEqual(st.t_start, t_start)
     self.assertEqual(len(cpp_shift), len(A) - 1)
示例#6
0
 def setUp(self):
     np.random.seed(0)
     # Spade parameters
     self.bin_size = 1 * pq.ms
     self.winlen = 10
     self.n_subset = 10
     self.n_surr = 10
     self.alpha = 0.05
     self.stability_thresh = [0.1, 0.1]
     self.psr_param = [0, 0, 0]
     self.min_occ = 4
     self.min_spikes = 4
     self.max_occ = 4
     self.max_spikes = 4
     self.min_neu = 4
     # Test data parameters
     # CPP parameters
     self.n_neu = 100
     self.amplitude = [0] * self.n_neu + [1]
     self.cpp = stg.cpp(rate=3 * pq.Hz,
                        amplitude_distribution=self.amplitude,
                        t_stop=5 * pq.s)
     # Number of patterns' occurrences
     self.n_occ1 = 10
     self.n_occ2 = 12
     self.n_occ3 = 15
     # Patterns lags
     self.lags1 = [2]
     self.lags2 = [1, 3]
     self.lags3 = [1, 2, 4, 5, 7]
     # Length of the spiketrain
     self.t_stop = 3000
     # Patterns times
     self.patt1_times = neo.SpikeTrain(
         np.arange(0, 1000, 1000 // self.n_occ1) * pq.ms,
         t_stop=self.t_stop * pq.ms)
     self.patt2_times = neo.SpikeTrain(
         np.arange(1000, 2000, 1000 // self.n_occ2)[:-1] * pq.ms,
         t_stop=self.t_stop * pq.ms)
     self.patt3_times = neo.SpikeTrain(
         np.arange(2000, 3000, 1000 // self.n_occ3)[:-1] * pq.ms,
         t_stop=self.t_stop * pq.ms)
     # Patterns
     self.patt1 = [self.patt1_times] + [
         neo.SpikeTrain(self.patt1_times.view(pq.Quantity) + lag * pq.ms,
                        t_stop=self.t_stop * pq.ms) for lag in self.lags1
     ]
     self.patt2 = [self.patt2_times] + [
         neo.SpikeTrain(self.patt2_times.view(pq.Quantity) + lag * pq.ms,
                        t_stop=self.t_stop * pq.ms) for lag in self.lags2
     ]
     self.patt3 = [self.patt3_times] + [
         neo.SpikeTrain(self.patt3_times.view(pq.Quantity) + lag * pq.ms,
                        t_stop=self.t_stop * pq.ms) for lag in self.lags3
     ]
     # Data
     self.msip = self.patt1 + self.patt2 + self.patt3
     # Expected results
     self.n_spk1 = len(self.lags1) + 1
     self.n_spk2 = len(self.lags2) + 1
     self.n_spk3 = len(self.lags3) + 1
     self.elements1 = list(range(self.n_spk1))
     self.elements2 = list(range(self.n_spk2))
     self.elements3 = list(range(self.n_spk3))
     self.elements_msip = [
         self.elements1,
         list(range(self.n_spk1, self.n_spk1 + self.n_spk2)),
         list(
             range(self.n_spk1 + self.n_spk2,
                   self.n_spk1 + self.n_spk2 + self.n_spk3))
     ]
     self.occ1 = np.unique(
         conv.BinnedSpikeTrain(self.patt1_times,
                               self.bin_size).spike_indices[0])
     self.occ2 = np.unique(
         conv.BinnedSpikeTrain(self.patt2_times,
                               self.bin_size).spike_indices[0])
     self.occ3 = np.unique(
         conv.BinnedSpikeTrain(self.patt3_times,
                               self.bin_size).spike_indices[0])
     self.occ_msip = [list(self.occ1), list(self.occ2), list(self.occ3)]
     self.lags_msip = [self.lags1, self.lags2, self.lags3]
     self.patt_psr = self.patt3 + [self.patt3[-1][:3]]
示例#7
0
    def test_cpp_het(self):
        # testing output with generic inputs
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            """
            Catch RuntimeWarning: divide by zero encountered in true_divide
            mean_interval = 1 / rate.magnitude, when rate == 0 Hz.
            """
            cpp_het = stgen.cpp(rate, A, t_stop, t_start=t_start)
            # testing the ouput formats
            self.assertEqual([type(train) for train in cpp_het],
                             [neo.SpikeTrain] * len(cpp_het))
            self.assertEqual(cpp_het[0].simplified.units, 1000 * ms)
            self.assertEqual(type(cpp_het), list)
            # testing units
            self.assertEqual([train.simplified.units for train in cpp_het],
                             [1000 * ms] * len(cpp_het))
            # testing output t_start and t_stop
            for st in cpp_het:
                self.assertEqual(st.t_stop, t_stop)
                self.assertEqual(st.t_start, t_start)
            # testing the number of output spiketrains
            self.assertEqual(len(cpp_het), len(A) - 1)
            self.assertEqual(len(cpp_het), len(rate))

            # testing the units
            A = [0, 0.9, 0.1]
            t_stop = 10000 * ms
            t_start = 5 * 1000 * ms
            rate = [3, 4] * Hz
            cpp_unit = stgen.cpp(rate, A, t_stop, t_start=t_start)

            self.assertEqual(cpp_unit[0].units, t_stop.units)
            self.assertEqual(cpp_unit[0].t_stop.units, t_stop.units)
            self.assertEqual(cpp_unit[0].t_start.units, t_stop.units)
            # testing without copying any spikes
            A = [1, 0, 0]
            t_stop = 10 * 1000 * ms
            t_start = 5 * 1000 * ms
            rate = [3, 4] * Hz
            cpp_het_empty = stgen.cpp(rate, A, t_stop, t_start=t_start)

            self.assertEqual(len(cpp_het_empty[0]), 0)

            # testing output with rate equal to 0
            A = [0, .9, .1]
            t_stop = 10 * 1000 * ms
            t_start = 5 * 1000 * ms
            rate = [0, 0] * Hz
            cpp_het_empty_r = stgen.cpp(rate, A, t_stop, t_start=t_start)
            self.assertEqual([len(train) for train in cpp_het_empty_r],
                             [0] * len(cpp_het_empty_r))

            # testing completely sync spiketrains
            A = [0, 0, 1]
            t_stop = 10 * 1000 * ms
            t_start = 5 * 1000 * ms
            rate = [3, 3] * Hz
            cpp_het_eq = stgen.cpp(rate, A, t_stop, t_start=t_start)

            self.assertTrue(
                np.allclose(cpp_het_eq[0].magnitude, cpp_het_eq[1].magnitude))
    def test_cpp_het(self):
        # testing output with generic inputs
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_het = stgen.cpp(rate, A, t_stop, t_start=t_start)
        # testing the ouput formats
        self.assertEqual(
            [type(train) for train in cpp_het], [neo.SpikeTrain]*len(cpp_het))
        self.assertEqual(cpp_het[0].simplified.units, 1000 * ms)
        self.assertEqual(type(cpp_het), list)
        # testing units
        self.assertEqual(
            [train.simplified.units for train in cpp_het], [1000 * ms]*len(
                cpp_het))
        # testing output t_start and t_stop
        for st in cpp_het:
            self.assertEqual(st.t_stop, t_stop)
            self.assertEqual(st.t_start, t_start)
        # testing the number of output spiketrains
        self.assertEqual(len(cpp_het), len(A) - 1)
        self.assertEqual(len(cpp_het), len(rate))

        # testing the units
        A = [0, 0.9, 0.1]
        t_stop = 10000*ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_unit = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(cpp_unit[0].units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_stop.units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_start.units, t_stop.units)
        # testing without copying any spikes
        A = [1, 0, 0]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 4] * Hz
        cpp_het_empty = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(len(cpp_het_empty[0]), 0)

        # testing output with rate equal to 0
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [0, 0] * Hz
        cpp_het_empty_r = stgen.cpp(rate, A, t_stop, t_start=t_start)
        self.assertEqual(
            [len(train) for train in cpp_het_empty_r], [0]*len(
                cpp_het_empty_r))

        # testing completely sync spiketrains
        A = [0, 0, 1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = [3, 3] * Hz
        cpp_het_eq = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertTrue(np.allclose(
            cpp_het_eq[0].magnitude, cpp_het_eq[1].magnitude))
    def test_cpp_hom(self):
        # testing output with generic inputs
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom = stgen.cpp(rate, A, t_stop, t_start=t_start)
        # testing the ouput formats
        self.assertEqual(
            [type(train) for train in cpp_hom], [neo.SpikeTrain]*len(cpp_hom))
        self.assertEqual(cpp_hom[0].simplified.units, 1000 * ms)
        self.assertEqual(type(cpp_hom), list)
        # testing quantities format of the output
        self.assertEqual(
            [train.simplified.units for train in cpp_hom], [1000 * ms]*len(
                cpp_hom))
        # testing output t_start t_stop
        for st in cpp_hom:
            self.assertEqual(st.t_stop, t_stop)
            self.assertEqual(st.t_start, t_start)
        self.assertEqual(len(cpp_hom), len(A) - 1)

        # testing the units
        A = [0, 0.9, 0.1]
        t_stop = 10000*ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_unit = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(cpp_unit[0].units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_stop.units, t_stop.units)
        self.assertEqual(cpp_unit[0].t_start.units, t_stop.units)

        # testing output without copy of spikes
        A = [1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom_empty = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertEqual(
            [len(train) for train in cpp_hom_empty], [0]*len(cpp_hom_empty))

        # testing output with rate equal to 0
        A = [0, .9, .1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 0 * Hz
        cpp_hom_empty_r = stgen.cpp(rate, A, t_stop, t_start=t_start)
        self.assertEqual(
            [len(train) for train in cpp_hom_empty_r], [0]*len(
                cpp_hom_empty_r))

        # testing output with same spike trains in output
        A = [0, 0, 1]
        t_stop = 10 * 1000 * ms
        t_start = 5 * 1000 * ms
        rate = 3 * Hz
        cpp_hom_eq = stgen.cpp(rate, A, t_stop, t_start=t_start)

        self.assertTrue(
            np.allclose(cpp_hom_eq[0].magnitude, cpp_hom_eq[1].magnitude))
示例#10
0
# for i, spiketrain in enumerate(spiketrain_list):
#         t = spiketrain.rescale(ms)
#         plt.plot(t, i * np.ones_like(t), 'k.', markersize=2)
# plt.axis('tight')
# plt.xlim(0, 1000)
# plt.xlabel('Time (ms)', fontsize=16)
# plt.ylabel('Spike Train Index', fontsize=16)
# plt.gca().tick_params(axis='both', which='major', labelsize=14)
# #plt.show()
# cc_matrix = corrcoef(BinnedSpikeTrain(spiketrain_list, 1 * ms))
# print(cc_matrix[0][1])

rate_correlation = []
for x in permutations(np.divide(np.linspace(0, 100, 11),100), 3):
    if sum(x) == 1:
        spiketrain_list = cpp(500 * Hz, x, 1000 * ms)
        rate = len(LIF_R_ASC_AT(w_e, w_i, spiketrain_list[0], spiketrain_list[1]))
        cc_matrix = corrcoef(BinnedSpikeTrain(spiketrain_list, 5 * ms))
        rate_correlation.append([cc_matrix[0][1], rate])

print(rate_correlation)
x_val = [x[0] for x in rate_correlation]
y_val = [x[1] for x in rate_correlation]
#plt.scatter(x_val, y_val, marker="x")
sns.regplot(x_val, y_val, ci=None)
plt.ylim((0, 30))
plt.xlim((0, 1))
plt.xlabel("Pearson’s correlation coefficient")
plt.ylabel("Output firing rate (Hz)")
#sns.lmplot("Correlation", "Output firing rate (Hz)", pd.DataFrame((x_val, y_val), columns =['Correlation', 'Output firing rate (Hz)']))
plt.show()