Exemple #1
0
 def test_spike_contrast_non_overlapping_spiketrains(self):
     np.random.seed(15)
     spike_train_1 = stgen.StationaryPoissonProcess(
         rate=10 * Hz, t_start=0. * ms,
         t_stop=10000. * ms).generate_spiketrain()
     spike_train_2 = stgen.StationaryPoissonProcess(
         rate=10 * Hz, t_start=5000. * ms,
         t_stop=10000. * ms).generate_spiketrain()
     spiketrains = [spike_train_1, spike_train_2]
     synchrony = spike_contrast(spiketrains, t_stop=5000 * ms)
     # the synchrony of non-overlapping spiketrains must be zero
     self.assertEqual(synchrony, 0.)
 def test_spike_contrast_same_signal(self):
     np.random.seed(21)
     spike_train = stgen.StationaryPoissonProcess(
         rate=10.*Hz, t_start=0.*ms, t_stop=10000.*ms).generate_spiketrain()
     spike_trains = [spike_train, spike_train]
     synchrony = spike_contrast(spike_trains, min_bin=1 * ms)
     self.assertEqual(synchrony, 1.0)
Exemple #3
0
 def test_joint_isi_dithering_output(self):
     process = stg.StationaryPoissonProcess(
         rate=100. * pq.Hz, refractory_period=3 * pq.ms, t_stop=0.1 * pq.s)
     spiketrain = process.generate_spiketrain()
     surrogate_train = surr.JointISI(spiketrain).dithering()[0]
     ground_truth = [0.0060744, 0.01886591, 0.02732847, 0.03683888,
                     0.04569622, 0.05196334, 0.05899197, 0.07855664]
     assert_array_almost_equal(surrogate_train.magnitude, ground_truth)
    def test_spike_contrast_random(self):
        # randomly generated spiketrains that share the same t_start and
        # t_stop
        np.random.seed(24)  # to make the results reproducible
        poisson_process_1 = stgen.StationaryPoissonProcess(
            rate=10.*Hz, t_start=0.*ms, t_stop=10000.*ms)
        poisson_process_2 = stgen.StationaryPoissonProcess(
            rate=1.*Hz, t_start=0.*ms, t_stop=10000.*ms)
        spike_train_1 = poisson_process_1.generate_spiketrain()
        spike_train_2 = poisson_process_1.generate_spiketrain()
        spike_train_3 = poisson_process_1.generate_spiketrain()
        spike_train_4 = poisson_process_1.generate_spiketrain()
        spike_train_5 = poisson_process_2.generate_spiketrain()
        spike_train_6 = poisson_process_2.generate_spiketrain()

        spike_trains = [spike_train_1, spike_train_2, spike_train_3,
                        spike_train_4, spike_train_5, spike_train_6]
        synchrony = spike_contrast(spike_trains)
        self.assertAlmostEqual(synchrony, 0.1875795, places=6)
    def test_spike_contrast_double_duration(self):
        np.random.seed(19)
        poisson_process = stgen.StationaryPoissonProcess(
            rate=10 * Hz, t_start=0. * ms, t_stop=10000. * ms)
        spike_train_1 = poisson_process.generate_spiketrain()
        spike_train_2 = poisson_process.generate_spiketrain()
        spike_train_3 = poisson_process.generate_spiketrain()

        spike_trains = [spike_train_1, spike_train_2, spike_train_3]
        synchrony = spike_contrast(spike_trains, t_stop=20000 * ms)
        self.assertEqual(synchrony, 0.5)
 def test_spike_contrast_trace(self):
     np.random.seed(15)
     poisson_process = stgen.StationaryPoissonProcess(
         rate=10 * Hz, t_start=0. * ms, t_stop=1000. * ms)
     spike_train_1 = poisson_process.generate_spiketrain()
     spike_train_2 = poisson_process.generate_spiketrain()
     synchrony, trace = spike_contrast([spike_train_1, spike_train_2],
                                       return_trace=True)
     self.assertEqual(synchrony, max(trace.synchrony))
     self.assertEqual(len(trace.contrast), len(trace.active_spiketrains))
     self.assertEqual(len(trace.active_spiketrains), len(trace.synchrony))
     self.assertEqual(len(trace.bin_size), len(trace.synchrony))
     self.assertIsInstance(trace.bin_size, pq.Quantity)
     self.assertEqual(trace.bin_size[0], 500 * pq.ms)
     self.assertAlmostEqual(trace.bin_size[-1], 10.1377798 * pq.ms)
Exemple #7
0
 def test_t_start_agnostic(self):
     np.random.seed(15)
     t_stop = 10 * second
     poisson_process = stgen.StationaryPoissonProcess(rate=10 * Hz,
                                                      t_stop=t_stop)
     spike_train_1 = poisson_process.generate_spiketrain()
     spike_train_2 = poisson_process.generate_spiketrain()
     spiketrains = [spike_train_1, spike_train_2]
     synchrony_target = spike_contrast(spiketrains)
     # a check for developer: test meaningful result
     assert synchrony_target > 0
     t_shift = 20 * second
     spiketrains_shifted = [
         neo.SpikeTrain(st.times + t_shift,
                        t_start=t_shift,
                        t_stop=t_stop + t_shift) for st in spiketrains
     ]
     synchrony = spike_contrast(spiketrains_shifted)
     self.assertAlmostEqual(synchrony, synchrony_target)
Exemple #8
0
    def test_joint_isi_dithering_format(self):

        rate = 100. * pq.Hz
        t_stop = 1. * pq.s
        process = stg.StationaryPoissonProcess(rate, t_stop=t_stop)
        spiketrain = process.generate_spiketrain()
        n_surrogates = 2
        dither = 10 * pq.ms

        # Test fast version
        joint_isi_instance = surr.JointISI(spiketrain, dither=dither,
                                           method='fast')
        surrogate_trains = joint_isi_instance.dithering(
            n_surrogates=n_surrogates)

        self.assertIsInstance(surrogate_trains, list)
        self.assertEqual(len(surrogate_trains), n_surrogates)
        self.assertEqual(joint_isi_instance.method, 'fast')

        for surrogate_train in surrogate_trains:
            self.assertIsInstance(surrogate_train, neo.SpikeTrain)
            self.assertEqual(surrogate_train.units, spiketrain.units)
            self.assertEqual(surrogate_train.t_start, spiketrain.t_start)
            self.assertEqual(surrogate_train.t_stop, spiketrain.t_stop)
            self.assertEqual(len(surrogate_train), len(spiketrain))

        # Test window_version
        joint_isi_instance = surr.JointISI(spiketrain,
                                           method='window',
                                           dither=2 * dither,
                                           n_bins=50)
        surrogate_trains = joint_isi_instance.dithering(
            n_surrogates=n_surrogates)

        self.assertIsInstance(surrogate_trains, list)
        self.assertEqual(len(surrogate_trains), n_surrogates)
        self.assertEqual(joint_isi_instance.method, 'window')

        for surrogate_train in surrogate_trains:
            self.assertIsInstance(surrogate_train, neo.SpikeTrain)
            self.assertEqual(surrogate_train.units, spiketrain.units)
            self.assertEqual(surrogate_train.t_start, spiketrain.t_start)
            self.assertEqual(surrogate_train.t_stop, spiketrain.t_stop)
            self.assertEqual(len(surrogate_train), len(spiketrain))

        # Test isi_dithering
        joint_isi_instance = surr.JointISI(spiketrain,
                                           method='window',
                                           dither=2 * dither,
                                           n_bins=50,
                                           isi_dithering=True,
                                           use_sqrt=True,
                                           cutoff=False)
        surrogate_trains = joint_isi_instance.dithering(
            n_surrogates=n_surrogates)

        self.assertIsInstance(surrogate_trains, list)
        self.assertEqual(len(surrogate_trains), n_surrogates)
        self.assertEqual(joint_isi_instance.method, 'window')

        for surrogate_train in surrogate_trains:
            self.assertIsInstance(surrogate_train, neo.SpikeTrain)
            self.assertEqual(surrogate_train.units, spiketrain.units)
            self.assertEqual(surrogate_train.t_start, spiketrain.t_start)
            self.assertEqual(surrogate_train.t_stop, spiketrain.t_stop)
            self.assertEqual(len(surrogate_train), len(spiketrain))

        # Test surrogate methods wrapper
        surrogate_trains = surr.surrogates(
            spiketrain,
            dt=15 * pq.ms,
            n_surrogates=n_surrogates,
            method='joint_isi_dithering')
        self.assertIsInstance(surrogate_trains, list)
        self.assertEqual(len(surrogate_trains), n_surrogates)

        for surrogate_train in surrogate_trains:
            self.assertIsInstance(surrogate_train, neo.SpikeTrain)
            self.assertEqual(surrogate_train.units, spiketrain.units)
            self.assertEqual(surrogate_train.t_start, spiketrain.t_start)
            self.assertEqual(surrogate_train.t_stop, spiketrain.t_stop)
            self.assertEqual(len(surrogate_train), len(spiketrain))
        with self.assertRaises(ValueError):
            joint_isi_instance = surr.JointISI(spiketrain,
                                               method='wrong method',
                                               dither=2 * dither,
                                               n_bins=50)