def test_check_constraint_valley(self): # valley sequence beta = -1*np.exp(-(np.linspace(0,1, self.n_param) - 0.4)**2 / 0.01) V = check_constraint(beta=beta, constraint="valley") self.assertEqual(V.shape, (self.n_param-1, self.n_param-1)) self.assertTrue(np.array_equal(V, V.astype(bool))) self.assertEqual(np.sum(V), 0)
def test_check_constraint_valley_and_peak(self): x = np.linspace(0,1,100) beta = np.exp(-(x - 0.3)**2 / 0.01) + -1*np.exp(-(x - 0.8)**2 / 0.01) V = check_constraint(beta=beta, constraint="peak-and-valley") self.assertEqual(V.shape, (len(self.x)-1, len(self.x)-1)) self.assertTrue(np.array_equal(V, V.astype(bool))) self.assertEqual(np.sum(V), 0)
def test_check_constraint_conc(self): # convex sequence beta = np.exp(np.linspace(0, 2, self.n_param)) V = check_constraint(beta=beta, constraint="conc") self.assertEqual(V.shape, (self.n_param-2, self.n_param-2)) self.assertTrue((np.diag(V) == np.ones(self.n_param-2)).all()) # concave beta = -1*np.exp(np.linspace(0, 2, self.n_param)) V = check_constraint(beta=beta, constraint="conc") self.assertEqual(V.shape, (self.n_param-2, self.n_param-2)) self.assertTrue((np.diag(V) == np.zeros(self.n_param-2)).all()) # convex sequence with concave part beta = np.exp(np.linspace(0, 2, self.n_param)) beta[2] = -1*beta[2] V = check_constraint(beta=beta, constraint="conc") self.assertEqual(V.shape, (self.n_param-2, self.n_param-2)) self.assertEqual(V.sum(), self.n_param-2-2) # concave sequence with convex part beta = -1*np.exp(np.linspace(0, 2, self.n_param)) beta[2] = -1*beta[2] V = check_constraint(beta=beta, constraint="conc") self.assertEqual(V.shape, (self.n_param-2, self.n_param-2)) self.assertEqual(V.sum(), 2)
def test_check_constraint_dec(self): # increasing sequence beta = np.linspace(0,1, self.n_param) V = check_constraint(beta=beta, constraint="dec", ) self.assertEqual(V.shape, (self.n_param-1, self.n_param-1)) self.assertTrue((np.diag(V) == np.ones(self.n_param-1)).all()) # decreasing sequence beta = np.linspace(0,-1, self.n_param) V = check_constraint(beta=beta, constraint="dec", ) self.assertEqual(V.shape, (self.n_param-1, self.n_param-1)) self.assertTrue((np.diag(V) == np.zeros(self.n_param-1)).all()) # increasing sequence with decreasing part beta = np.linspace(0,1,self.n_param) beta[2] = -1 V = check_constraint(beta=beta, constraint="dec", ) self.assertEqual(V.shape, (self.n_param-1, self.n_param-1)) self.assertEqual(V.sum(), self.n_param-2) # decreasing sequence with increasing part beta = np.linspace(0,-1,self.n_param) beta[2] = 1 V = check_constraint(beta=beta, constraint="dec", ) self.assertEqual(V.shape, (self.n_param-1, self.n_param-1)) self.assertEqual(V.sum(), 1)
def test_check_constraint_smooth(self): # random sequence beta = np.random.random(self.n_param) V = check_constraint(beta=beta, constraint="smooth") self.assertEqual(V.shape, (self.n_param-2, self.n_param-2)) self.assertTrue((np.diag(V) == np.ones(self.n_param-2)).all())