Пример #1
0
    def test_population_rset(self):
        import pyhmf as pynn
        pynn.setup()

        p = pynn.Population(123, pynn.EIF_cond_exp_isfa_ista)
        
        r1, r2 = pynn.NativeRNG(0), pynn.NativeRNG(0)
        d1 = pynn.RandomDistribution("uniform", [-55.0, -50.0])
        d2 = pynn.RandomDistribution("uniform", [-55.0, -50.0])

        p.rset("v_reset", d1)
        assert_array_equal(p.get("v_reset"), d2.next(len(p)))
Пример #2
0
    def test_distribution_clip(self):
        import pyhmf as pynn
        pynn.setup()

        r = pynn.NativeRNG(0)
        d = pynn.RandomDistribution("uniform", [0.0, 25.0], r, (12.5, 12.5), "clip")

        assert_array_equal(d.next(100), numpy.ones(100) * 12.5)
Пример #3
0
    def test_normaldistribution(self):
        import pyhmf as pynn
        pynn.setup()
        
        mean = 42.0
        std  = 3.3
        r = pynn.NativeRNG(10)
        d = pynn.RandomDistribution("normal", [mean, std])
        
        data = d.next(100000)

        self.assertAlmostEqual(numpy.mean(data), mean, places=1)
        self.assertAlmostEqual(numpy.std(data), std, places=1)
Пример #4
0
    def test_distribution_redraw(self):
        import pyhmf as pynn
        pynn.setup()

        r = pynn.NativeRNG(0)
        d = pynn.RandomDistribution("uniform", [0.0, 25.0], r, (5.0, 20.0), "redraw")
        
        data = d.next(260)
        self.assertLessEqual(max(data), 20.0)
        self.assertGreaterEqual(min(data), 5.0)
        data2 = data[data <= 5.0]
        data2 = data2[data2 >= 20]
        self.assertEqual(len(data2), 0)
Пример #5
0
    def test_init_random(self):

        size = random.randint(2, 10)**2
        seed = 1337

        pynn_dist = pynn.RandomDistribution(distribution='uniform',
                                            rng=NativeRNGProxy(seed))
        pyhmf_dist = pyhmf.RandomDistribution(distribution='uniform',
                                              rng=pyhmf.NativeRNG(seed))

        numpy.testing.assert_almost_equal(
            self.construct_with_backend(pynn, size, pynn_dist),
            self.construct_with_backend(pyhmf, size, pyhmf_dist))
Пример #6
0
    def test_projection(self):

        path = tempfile.mkstemp()[1]

        size_a = random.randint(1, 100)
        size_b = random.randint(1, 100)

        dist = pyhmf.RandomDistribution(rng=pyhmf.NativeRNG(1337))

        conn_pyhmf = pyhmf.AllToAllConnector(weights=dist, delays=42)
        proj_pyhmf = pyhmf.Projection(
                pyhmf.Population(size_a, pyhmf.IF_cond_exp),
                pyhmf.Population(size_b, pyhmf.IF_cond_exp),
                conn_pyhmf)
        
        proj_pyhmf.saveConnections(getattr(pyhmf, self.file_type)(path, 'w'))

        conn_pynn = pynn.FromFileConnector(getattr(pynn.recording.files, self.file_type)(path))
        proj_pynn = pynn.Projection(
                pynn.Population(size_a, pynn.IF_cond_exp),
                pynn.Population(size_b, pynn.IF_cond_exp),
                conn_pynn)

        numpy.testing.assert_equal(proj_pyhmf.getWeights(format='array'), proj_pynn.getWeights(format='array'))