def test_custom_init(self): A, B = self._get_AB() n = len(A) pi = np.array([7, 5, 1, 3, 10, 4, 8, 6, 9, 11, 2, 12]) - [1] * n custom_init = np.eye(n) custom_init = custom_init[pi] gm = GMP(n_init=1, init=custom_init, max_iter=30, shuffle_input=True, gmp=False) gm.fit(A, B) self.assertTrue((gm.perm_inds_ == pi).all()) self.assertEqual(gm.score_, 11156)
def test_custom_init_seeds(self): A, B = self._get_AB() n = len(A) pi_original = np.array([7, 5, 1, 3, 10, 4, 8, 6, 9, 11, 2, 12]) - 1 pi = np.array([5, 1, 3, 10, 4, 8, 6, 9, 11, 2, 12]) - 1 pi[pi > 6] -= 1 # use seed 0 in A to 7 in B seeds_A = [0] seeds_B = [6] custom_init = np.eye(n - 1) custom_init = custom_init[pi] gm = GMP(n_init=1, init=custom_init, max_iter=30, shuffle_input=True, gmp=False) gm.fit(A, B, seeds_A=seeds_A, seeds_B=seeds_B) self.assertTrue((gm.perm_inds_ == pi_original).all()) self.assertEqual(gm.score_, 11156)
def test_SGM_inputs(self): with pytest.raises(TypeError): GMP(n_init=-1.5) with pytest.raises(ValueError): GMP(init_method="random") with pytest.raises(TypeError): GMP(max_iter=-1.5) with pytest.raises(TypeError): GMP(shuffle_input="hey") with pytest.raises(TypeError): GMP(eps=-1) with pytest.raises(TypeError): GMP(gmp="hey") with pytest.raises(TypeError): GMP(padding=2) with pytest.raises(ValueError): GMP(padding="hey") with pytest.raises(ValueError): GMP().fit( np.random.random((3, 4)), np.random.random((3, 4)), np.arange(2), np.arange(2), ) with pytest.raises(ValueError): GMP().fit( np.random.random((3, 4)), np.random.random((3, 4)), np.arange(2), np.arange(2), ) with pytest.raises(ValueError): GMP().fit(np.identity(3), np.identity(3), np.identity(3), np.arange(2)) with pytest.raises(ValueError): GMP().fit(np.identity(3), np.identity(3), np.arange(1), np.arange(2)) with pytest.raises(ValueError): GMP().fit(np.identity(3), np.identity(3), np.arange(5), np.arange(5)) with pytest.raises(ValueError): GMP().fit(np.identity(3), np.identity(3), -1 * np.arange(2), -1 * np.arange(2))
def setup_class(cls): cls.barycenter = GMP(gmp=False) cls.rand = GMP(n_init=100, init_method="rand", gmp=False) cls.barygm = GMP(gmp=True)
def setUpClass(cls) -> None: cls.barycenter = GMP(gmp=False) cls.rand = GMP(n_init=100, init="rand", gmp=False) cls.barygm = GMP(gmp=True)
def test_parallel(self): A, B = self._get_AB() gmp = GMP(gmp=False, n_init=2, n_jobs=2) gmp.fit(A, B) score = gmp.score_ self.assertTrue(11156 <= score < 13500)