def test_direct_with_without_rowvar(): """Tests the direct method, with and without rowvar, works correctly.""" np.random.seed(1) data = np.random.normal(size=(10, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data.T, rowvar=True) pc1._direct() pc2._direct() check_cols_match_except_sign(pc1._eigvec, pc2._eigvec)
def test_em_with_without_rowvar(): """Tests the EM method, with and without rowvar, works correctly.""" np.random.seed(1) data = np.random.normal(size=(20, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data.T, rowvar=True) pc1._expectation_maximization(10) pc2._expectation_maximization(10) check_cols_match_except_sign(pc1._eigvec, pc2._eigvec)
def test_em_vs_snapshot_pc_rowvar_false(): """Tests that EM and snapshot agree.""" np.random.seed(1) data = np.random.normal(size=(10, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data) pc1._snapshot() pc2._expectation_maximization(5) check_cols_match_except_sign(pc1._eigvec[:, :5], pc2._eigvec)
def test_snapshot_vs_direct_pc_rowvar_false(): """Tests that snapshot and direct agree.""" np.random.seed(1) data = np.random.normal(size=(10, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data) pc1._direct() pc2._snapshot() check_cols_match_except_sign(pc1._eigvec[:, :4], pc2._eigvec[:, :4])
def test_project_with_without_rowvar(): """Tests the project works with rowvar correctly.""" np.random.seed(1) data = np.random.normal(size=(10, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data.T, rowvar=True) pc1._direct() pc2._direct() check_cols_match_except_sign(pc1.project(3), pc2.project(3).T) check_cols_match_except_sign(pc1.project(3), pc2.project(3).T)
def __init__(self, npc=None, *args, **keywords): self._pc = PrincipalComponents(data) self._pc._direct() if npc is None: npc = len(self._pc._eigval) data = self._pc.project(npc) super(SplineModelPCAGaussianMixture, self).__init__(ncomponent, data, norm=False, *args, **keywords)
def test_ndim_property(): """Tests the ndim property works with rowvar correctly.""" data = np.zeros((10, 50)) pc1 = PrincipalComponents(data) pc2 = PrincipalComponents(data.T, rowvar=True) assert pc1.ndim == pc2.ndim