Пример #1
0
    def setUp(self):
        folder = os.path.dirname(os.path.realpath(__file__))

        self.time_original = 8
        spiketrain = np.array([1, 3, 5, 6])
        self.values = [spiketrain, spiketrain, spiketrain, np.array([1])]

        self.features = NetworkFeatures()
Пример #2
0
    def test_preprocess(self):
        self.features = NetworkFeatures()

        time, spiketrains = self.features.preprocess(self.time_original, self.values)

        self.assertEqual(time, self.time_original)
        self.assertIsInstance(spiketrains[0], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[1], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[2], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[3], neo.core.SpikeTrain)

        self.assertTrue(np.array_equal(spiketrains[0], self.values[0]))
        self.assertTrue(np.array_equal(spiketrains[1], self.values[1]))
        self.assertTrue(np.array_equal(spiketrains[2], self.values[2]))
        self.assertTrue(np.array_equal(spiketrains[3], self.values[3]))

        self.assertEqual(spiketrains[0].t_stop, self.time_original)
Пример #3
0
    def setUp(self):
        folder = os.path.dirname(os.path.realpath(__file__))

        self.time_original = 8
        spiketrain = np.array([1, 3, 5, 6])
        self.values = [spiketrain, spiketrain, spiketrain, np.array([1])]

        self.implemented_features = [
            "cv", "mean_cv", "binned_isi", "mean_isi", "local_variation",
            "mean_firing_rate", "fanofactor", "instantaneous_rate",
            "van_rossum_dist", "victor_purpura_dist", "corrcoef", "covariance",
            "mean_local_variation"
        ]

        self.features = NetworkFeatures(instantaneous_rate_nr_samples=2)

        self.time, self.spiketrains = self.features.preprocess(
            self.time_original, self.values)
Пример #4
0
    def test_init(self):
        def feature(time, values):
            return "t", "U"

        features = NetworkFeatures(new_features=feature,
                                   features_to_run=None,
                                   adaptive=["cv"],
                                   labels={"cv": ["test"]},
                                   instantaneous_rate_nr_samples=-1.,
                                   isi_bin_size=-1,
                                   corrcoef_bin_size=-1,
                                   covariance_bin_size=-1,
                                   units=pq.ms)

        self.assertIsInstance(features, NetworkFeatures)
        self.assertEqual(features.features_to_run, [])
        self.assertEqual(features.adaptive, ["cv"])
        self.assertEqual(features.instantaneous_rate_nr_samples, -1)
        self.assertEqual(features.isi_bin_size, -1)
        self.assertEqual(features.corrcoef_bin_size, -1)
        self.assertEqual(features.covariance_bin_size, -1)
        self.assertEqual(features.units, pq.ms)
        self.assertEqual(set(features.implemented_features()),
                         set(["feature"] + self.implemented_features))
Пример #5
0
    def test_initNone(self):
        self.features = NetworkFeatures()

        self.assertIsInstance(self.features, NetworkFeatures)
Пример #6
0
class TestNetworkFeatures(unittest.TestCase):
    def setUp(self):
        folder = os.path.dirname(os.path.realpath(__file__))

        self.time_original = 8
        spiketrain = np.array([1, 3, 5, 6])
        self.values = [spiketrain, spiketrain, spiketrain, np.array([1])]

        self.implemented_features = [
            "cv", "mean_cv", "binned_isi", "mean_isi", "local_variation",
            "mean_firing_rate", "fanofactor", "instantaneous_rate",
            "van_rossum_dist", "victor_purpura_dist", "corrcoef", "covariance",
            "mean_local_variation"
        ]

        self.features = NetworkFeatures(instantaneous_rate_nr_samples=2)

        self.time, self.spiketrains = self.features.preprocess(
            self.time_original, self.values)

    def test_initNone(self):
        self.features = NetworkFeatures()

        self.assertIsInstance(self.features, NetworkFeatures)

    def test_init(self):
        def feature(time, values):
            return "t", "U"

        features = NetworkFeatures(new_features=feature,
                                   features_to_run=None,
                                   adaptive=["cv"],
                                   labels={"cv": ["test"]},
                                   instantaneous_rate_nr_samples=-1.,
                                   isi_bin_size=-1,
                                   corrcoef_bin_size=-1,
                                   covariance_bin_size=-1,
                                   units=pq.ms)

        self.assertIsInstance(features, NetworkFeatures)
        self.assertEqual(features.features_to_run, [])
        self.assertEqual(features.adaptive, ["cv"])
        self.assertEqual(features.instantaneous_rate_nr_samples, -1)
        self.assertEqual(features.isi_bin_size, -1)
        self.assertEqual(features.corrcoef_bin_size, -1)
        self.assertEqual(features.covariance_bin_size, -1)
        self.assertEqual(features.units, pq.ms)
        self.assertEqual(set(features.implemented_features()),
                         set(["feature"] + self.implemented_features))

    def test_preprocess(self):
        self.features = NetworkFeatures()

        time, spiketrains = self.features.preprocess(self.time_original,
                                                     self.values)

        self.assertEqual(time, self.time_original)
        self.assertIsInstance(spiketrains[0], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[1], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[2], neo.core.SpikeTrain)
        self.assertIsInstance(spiketrains[3], neo.core.SpikeTrain)

        self.assertTrue(np.array_equal(spiketrains[0], self.values[0]))
        self.assertTrue(np.array_equal(spiketrains[1], self.values[1]))
        self.assertTrue(np.array_equal(spiketrains[2], self.values[2]))
        self.assertTrue(np.array_equal(spiketrains[3], self.values[3]))

        self.assertEqual(spiketrains[0].t_stop, self.time_original)

    def test_cv(self):
        time, values = self.features.cv(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertTrue(
            np.array_equal([
                0.51207638319124049, 0.51207638319124049, 0.51207638319124049,
                0
            ], values))

    def test_mean_cv(self):
        time, values = self.features.mean_cv(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(0.38405728739343037, values)

    def test_binned_isi(self):
        time, values = self.features.binned_isi(self.time, self.spiketrains)

        centers = np.arange(0, self.time_original + 1)[1:] - 0.5

        self.assertTrue(np.array_equal(centers, time))
        self.assertTrue(
            np.array_equal(
                values, [[0, 1, 2, 0, 0, 0, 0, 0], [0, 1, 2, 0, 0, 0, 0, 0],
                         [0, 1, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]))

    def test_mean_isi(self):
        time, values = self.features.mean_isi(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(1.66666666666666667, values)

    def test_lv(self):
        time, values = self.features.local_variation(self.time,
                                                     self.spiketrains)

        self.assertIsNone(time)
        self.assertTrue(
            np.array_equal([
                0.16666666666666666, 0.16666666666666666, 0.16666666666666666,
                None
            ], values))

    def test_mean_lv(self):
        time, values = self.features.mean_local_variation(
            self.time, self.spiketrains)

        self.assertIsNone(time)
        mean = np.mean(
            [0.16666666666666666, 0.16666666666666666, 0.16666666666666666])
        self.assertEqual(mean, values)

    def test_mean_firing_rate(self):
        time, values = self.features.mean_firing_rate(self.time,
                                                      self.spiketrains)

        self.assertIsNone(time)
        self.assertTrue(np.array_equal([500, 500, 500, 125], values))

    def test_instantaneous_rate(self):
        time, values = self.features.instantaneous_rate(
            self.time, self.spiketrains)

        rates = [938.762478, 938.7583322]

        correct_t = np.linspace(0, 8, 3)[:-1]

        self.assertTrue(np.all(np.isclose(values[0], rates)))
        self.assertTrue(np.all(np.isclose(values[1], rates)))
        self.assertTrue(np.all(np.isclose(values[2], rates)))
        self.assertIsNone(values[3])
        self.assertTrue(np.array_equal(time, correct_t))

    def test_fanofactor(self):
        time, values = self.features.fanofactor(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(values, 0.51923076923076927)

    def test_van_rossum_dist(self):
        time, values = self.features.van_rossum_dist(self.time,
                                                     self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(values.shape, (4, 4))

        # correct_values = [[0.0, 5.9604644775390625e-08, 5.9604644775390625e-08, 2.9980016657780828],
        #              [5.9604644775390625e-08, 0.0, 5.9604644775390625e-08, 2.9980016657780828],
        #              [5.9604644775390625e-08, 5.9604644775390625e-08, 0.0, 2.9980016657780828],
        #              [2.9980016657780828, 2.9980016657780828, 2.9980016657780828, 0.0]]

        # self.assertTrue(np.array_equal(values, correct_values))

        diag = np.diag_indices(4)
        self.assertTrue(np.all(values[diag] == 0))

    def test_victor_purpura_dist(self):
        time, values = self.features.victor_purpura_dist(
            self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(values.shape, (4, 4))
        diag = np.diag_indices(4)
        self.assertTrue(np.all(values[diag] == 0))

    def test_corrcoef(self):
        time, values = self.features.corrcoef(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(values.shape, (4, 4))
        diag = np.diag_indices(4)
        self.assertTrue(np.all(values[diag] == 1))

    def test_covariance(self):
        time, values = self.features.covariance(self.time, self.spiketrains)

        self.assertIsNone(time)
        self.assertEqual(values.shape, (4, 4))

    def test_reference_feature(self):
        time, values = self.features.reference_feature(1, 1)

        self.assertIsNone(time)
        self.assertIsNone(values)
Пример #7
0
    def test_initNone(self):
        self.features = NetworkFeatures(logger_level="error")

        self.assertIsInstance(self.features, NetworkFeatures)