예제 #1
0
    def test_input(self):
        def pairwise_test(points_1, points_2):
            pass

        rate = ((), )
        bounds = 1
        pairwisef = pairwise_test
        mix_prob = 1
        iterations = 1
        burn_in = 1
        with self.assertRaises(TypeError):
            out = PyPgen.MaPP(rate=rate,
                              bounds=bounds,
                              pairwisef=pairwisef,
                              mix_prob=mix_prob,
                              iterations=iterations,
                              burn_in=burn_in)
        rate = 1
        with self.assertRaises(TypeError):
            out = PyPgen.MaPP(rate=rate,
                              bounds=bounds,
                              pairwisef=pairwisef,
                              mix_prob=mix_prob,
                              iterations=iterations,
                              burn_in=burn_in)
예제 #2
0
    def test_basic(self):
        rate = 5
        bounds = [1, 10]
        out = PyPgen.HPP_temporal(rate=rate, bounds=bounds)
        self.assertTrue(np.amin(out) > bounds[0])
        self.assertTrue(np.amax(out) < bounds[1])
        plt.title(
            str(len(out)) + " samples of a temporal HPP of rate " + str(rate) +
            " in 10s")
        plt.plot(out, np.arange(len(out)), ".k")
        plt.xlabel("Time [s]")
        plt.ylabel("Count")
        plt.savefig(os.path.join(path2res, "HPP_temporal_test.png"),
                    bbox_inches='tight',
                    dpi=100,
                    edgecolor='w')
        # plt.show()
        plt.close("all")

        realizations = 3
        rate = 5
        bounds = [1, 10]
        out = PyPgen.HPP_temporal(rate=rate,
                                  bounds=bounds,
                                  realizations=realizations)
        self.assertTrue(len(out) == realizations)
        for i in np.arange(realizations):
            self.assertTrue(np.amin(out[i]) > bounds[0])
            self.assertTrue(np.amax(out[i]) < bounds[1])
예제 #3
0
 def test_typecheck(self):
     with self.assertRaises(TypeError):
         PyPgen.NHPP(
             ((), ),
             ((), ),
             ((), ),
         )
예제 #4
0
    def test_2Dscalarsampleplot(self):

        rate = 2
        realizations = 1
        bounds = [[0, 10], [0, 10]]
        dimensions = len(bounds)
        out = PyPgen.HPP_rate(rate=rate,
                              bounds=bounds,
                              realizations=realizations)
        self.assertTrue(np.amin(out[:, 0]) > bounds[0][0])
        self.assertTrue(np.amax(out[:, 0]) < bounds[0][1])
        self.assertTrue(np.amin(out[:, 1]) > bounds[1][0])
        self.assertTrue(np.amax(out[:, 1]) < bounds[1][1])

        plt.title(
            str(len(out)) + " samples of a HPP of rate " + str(rate) +
            " in 10 unit square")
        plt.scatter(out[:, 0], out[:, 1], c="k")
        plt.xlabel("X")
        plt.ylabel("Y")
        plt.savefig(os.path.join(path2res, "HPP_rate_2Dtest.png"),
                    bbox_inches='tight',
                    dpi=100,
                    edgecolor='w')
        # plt.show()
        plt.close("all")
예제 #5
0
 def test_realizations_samples(self):
     samples = [20, 10]
     realizations = 1
     bounds = [[0, 10], [0, 10]]
     dimensions = len(bounds)
     with self.assertRaises(ValueError):
         out = PyPgen.HPP_samples(samples=samples,
                                  bounds=bounds,
                                  realizations=realizations)
     realizations = 3
     bounds = [[0, 10], [0, 10]]
     dimensions = len(bounds)
     with self.assertRaises(ValueError):
         out = PyPgen.HPP_samples(samples=samples,
                                  bounds=bounds,
                                  realizations=realizations)
예제 #6
0
    def test_halfsinus3D(self):
        phase_1 = 0
        phase_2 = 0
        phase_3 = 0
        period_1 = 1
        period_2 = 2
        period_3 = 3
        amplitude = 1
        offset = 1
        rate_max = amplitude + amplitude + amplitude + offset
        dimensions = 3

        def rate_halfsinus3D(x_1, x_2, x_3):
            sins = np.sin(2.*np.pi*x_1/period_1 + phase_1) + \
                np.sin(2.*np.pi*x_2/period_2 + phase_2) + \
                np.sin(2.*np.pi*x_3/period_3 + phase_3)
            out = amplitude * (sins * (sins > 0)) + offset
            return (out)

        bounds = [[1, 10], [10, 20], [20, 21]]
        out = PyPgen.NHPP(rate_halfsinus3D, rate_max, bounds)
        self.assertTrue(out.shape[-1] == dimensions)
        self.assertTrue(len(out.shape) > 1)
        self.assertTrue(np.amin(out[:, 0]) > bounds[0][0])
        self.assertTrue(np.amax(out[:, 0]) < bounds[0][1])
        self.assertTrue(np.amin(out[:, 1]) > bounds[1][0])
        self.assertTrue(np.amax(out[:, 1]) < bounds[1][1])
        self.assertTrue(np.amin(out[:, 2]) > bounds[2][0])
        self.assertTrue(np.amax(out[:, 2]) < bounds[2][1])
예제 #7
0
 def test_2Dscalarrealizations(self):
     rate = 2
     realizations = 3
     bounds = [[0, 10], [10, 0]]
     dimensions = len(bounds)
     out = PyPgen.HPP_rate(rate=rate,
                           bounds=bounds,
                           realizations=realizations)
     self.assertTrue(len(out) == realizations)
     for i in np.arange(realizations):
         self.assertTrue(np.amin(out[i][:, 0]) > bounds[0][0])
         self.assertTrue(np.amax(out[i][:, 0]) < bounds[0][1])
         self.assertTrue(np.amin(out[i][:, 1]) > bounds[1][1])
         self.assertTrue(np.amax(out[i][:, 1]) < bounds[1][0])
예제 #8
0
 def test_3D(self):
     samples = [3, 4, 5]
     realizations = 3
     bounds = [[0, 10], [0, 10]]
     dimensions = len(bounds)
     out = PyPgen.HPP_samples(samples=samples,
                              bounds=bounds,
                              realizations=realizations)
     self.assertTrue(len(out) == realizations)
     for i in np.arange(realizations):
         self.assertTrue(np.amin(out[i][:, 0]) > bounds[0][0])
         self.assertTrue(np.amax(out[i][:, 0]) < bounds[0][1])
         self.assertTrue(np.amin(out[i][:, 1]) > bounds[1][0])
         self.assertTrue(np.amax(out[i][:, 1]) < bounds[1][1])
         self.assertTrue(len(out[i]) == samples[i])
예제 #9
0
    def test_basic(self):
        shape = 3
        scale = 1
        bounds = [1, 10]
        dimensions = 1
        realizations = 3

        def info(size):
            return (np.random.gamma(shape=shape, scale=scale, size=size))

        out = PyPgen.MPP(info=info, bounds=bounds, realizations=realizations)
        self.assertTrue(len(out) == realizations)
        for i in np.arange(realizations):
            self.assertTrue(np.amin(out[i][:, 0]) > bounds[0])
            self.assertTrue(np.amax(out[i][:, 0]) < bounds[1])
            self.assertTrue(out[i].shape[-1] == dimensions)
예제 #10
0
    def test_halfsinus1D(self):
        phase = 0
        period = 2
        amplitude = 3
        offset = 1
        rate_max = amplitude + offset
        dimensions = 1

        def rate_halfsinus1D(time):
            sins = np.sin(2. * np.pi * time / period + phase)
            out = amplitude * (sins * (sins > 0)) + offset
            return (out)

        bounds = [1, 10]
        out = PyPgen.NHPP(rate_halfsinus1D, rate_max, bounds)
        self.assertTrue(out.shape[-1] == dimensions)
        self.assertTrue(len(out.shape) > 1)
        self.assertTrue(np.amin(out) > bounds[0])
        self.assertTrue(np.amax(out) < bounds[1])