Ejemplo n.º 1
0
    def test_apply(self):
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        f = mfblp_filter(w=5, s=s, a=.1, b=1.)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) < 0.1).all())
Ejemplo n.º 2
0
    def test_apply(self) :
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        f = mfblp_filter(w=5, s=s, a=.1, b=1.)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) < 0.1).all())
Ejemplo n.º 3
0
    def test_apply_restrict(self):
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        f = mfblp_filter(w=5, s=s, a=.1, b=1.)
        m = f.apply_restrict(x)
        self.assertTrue((np.abs(m - x) > 0.1).nonzero()[0].shape[0] < 3)
Ejemplo n.º 4
0
    def test_apply_restrict(self) :
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        f = mfblp_filter(w=5, s=s, a=.1, b=1.)
        m = f.apply_restrict(x)
        self.assertTrue((np.abs(m - x) > 0.1).nonzero()[0].shape[0] < 3)
Ejemplo n.º 5
0
    def test_search_w7(self):
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=7, s=s, a=.1, b=10.)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 0.1).all())
Ejemplo n.º 6
0
    def test_apply_noisy_gaussian(self):
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([10, 12, 15, 17, 20]).astype(float)

        np.random.seed(42)
        #x = x + np.random.normal(0, .1, size=x.shape)

        f = mfblp_filter(w=9, s=s, a=.1, b=10.)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) > 0.5).nonzero()[0].shape[0] < 5)
Ejemplo n.º 7
0
    def test_apply_noisy_uniform(self):
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        np.random.seed(42)
        x = x + np.random.uniform(low=-0.5, high=0.5)

        f = mfblp_filter(w=7, s=s, a=.1, b=.1)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) < 0.1).all())
Ejemplo n.º 8
0
    def test_search_w7(self) :
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=7, s=s, a=.1, b=10.)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 0.1).all())
Ejemplo n.º 9
0
    def test_apply_noisy_gaussian(self) :
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([10, 12, 15, 17, 20]).astype(float)

        np.random.seed(42)
        #x = x + np.random.normal(0, .1, size=x.shape)

        f = mfblp_filter(w=9, s=s, a=.1, b=10.)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) > 0.5).nonzero()[0].shape[0] < 5)
Ejemplo n.º 10
0
    def test_apply_noisy_uniform(self) :
        x = np.array([12] * 100 + [20] * 100 + [15] * 100).astype(float)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)

        np.random.seed(42)
        x = x + np.random.uniform(low=-0.5, high=0.5)

        f = mfblp_filter(w=7, s=s, a=.1, b=.1)
        m = f.apply(x)
        self.assertTrue((np.abs(m - x) < 0.1).all())
Ejemplo n.º 11
0
    def test_search_noisy_gaussian(self):
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        np.random.seed(42)
        x = x + np.random.normal(0, .5, size=x.shape)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=15, s=s, a=.5, b=.5)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 3.).all())
Ejemplo n.º 12
0
    def test_search_noisy_uniform(self):
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        np.random.seed(42)
        x = x + np.random.uniform(low=-0.5, high=0.5)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=11, s=s, a=.1, b=10.)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 2.).all())
Ejemplo n.º 13
0
    def test_get_likelihood(self):
        x = np.array([0.9, 0.91, 0.9, 2.05, 1.9, 3.1, 2.91])
        m1 = np.array([1.1, 1.1, 1.1, 2.1, 2.1, 3.1, 3.1])
        m2 = np.array([2.1, 2.1, 1.3, 1.1, 5.2, 1.1, 3.4])

        f = mfblp_filter(w=5, s=np.array([1., 2., 3.]), a=1., b=10.)
        l1 = f.get_likelihood(x, m1)
        l2 = f.get_likelihood(x, m2)

        self.assertTrue(l1.shape == x.shape)
        self.assertTrue((l1 < l2).all())
        self.assertTrue(l1.sum() < l2.sum())
Ejemplo n.º 14
0
    def test_search_noisy_gaussian(self) :
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        np.random.seed(42)
        x = x + np.random.normal(0, .5, size=x.shape)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=15, s=s, a=.5, b=.5)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 3.).all())
Ejemplo n.º 15
0
    def test_search_noisy_uniform(self) :
        x = np.array([12] * 100 + [19] * 100 + [15] * 100).astype(float)
        np.random.seed(42)
        x = x + np.random.uniform(low=-0.5, high=0.5)
        s = np.array([9.5, 10, 12, 15, 16, 19, 20, 21]).astype(float)
        starts = np.ones(x.shape)
        stepsize = 0.1
        steps = 300

        f = mfblp_filter(w=11, s=s, a=.1, b=10.)
        opt_ms = f.search(x, starts, stepsize, steps)
        self.assertTrue((np.abs(opt_ms - x) < 2.).all())
Ejemplo n.º 16
0
    def test_get_likelihood(self) :
        x = np.array([0.9, 0.91, 0.9, 2.05, 1.9, 3.1, 2.91])
        m1 = np.array([1.1, 1.1, 1.1, 2.1, 2.1, 3.1, 3.1])
        m2 = np.array([2.1, 2.1, 1.3, 1.1, 5.2, 1.1, 3.4])
        
        f = mfblp_filter(w=5, s=np.array([1., 2., 3.]), a=1., b=10.)
        l1 = f.get_likelihood(x, m1)
        l2 = f.get_likelihood(x, m2)

        self.assertTrue(l1.shape == x.shape)
        self.assertTrue((l1 < l2).all())
        self.assertTrue(l1.sum() < l2.sum())