Esempio n. 1
0
    def check_transform(Estimator, n_components, shape):
        X = DATA[shape]

        Y1 = Estimator(n_components, **KWDS[Estimator]).fit(X).transform(X)
        Y2 = Estimator(n_components, **KWDS[Estimator]).fit_transform(X)

        assert_columns_allclose_upto_sign(Y1, Y2)
Esempio n. 2
0
    def check_transform(Estimator, n_components, shape):
        X = DATA[shape]

        Y1 = Estimator(n_components, **KWDS[Estimator]).fit(X).transform(X)
        Y2 = Estimator(n_components, **KWDS[Estimator]).fit_transform(X)

        assert_columns_allclose_upto_sign(Y1, Y2)
Esempio n. 3
0
    def check_components(Estimator, n_components, shape):
        X = DATA[shape]

        pca = Estimator(n_components, **KWDS[Estimator]).fit(X)
        skpca = SKPCA(n_components).fit(X)

        assert_columns_allclose_upto_sign(pca.components_.T,
                                          skpca.components_.T)
Esempio n. 4
0
    def check_components(Estimator, n_components, shape):
        X = DATA[shape]

        pca = Estimator(n_components, **KWDS[Estimator]).fit(X)
        skpca = SKPCA(n_components).fit(X)

        assert_columns_allclose_upto_sign(pca.components_.T,
                                          skpca.components_.T)
Esempio n. 5
0
    def check_transform(Estimator, n_components, shape):
        X = DATA[shape]

        pca = Estimator(n_components, **KWDS[Estimator])
        skpca = SKPCA(n_components)

        Y = pca.fit_transform(X)
        Ysk = skpca.fit_transform(X)
        assert_columns_allclose_upto_sign(Y, Ysk)
Esempio n. 6
0
    def check_transform(Estimator, n_components, shape):
        X = DATA[shape]

        pca = Estimator(n_components, **KWDS[Estimator])
        skpca = SKPCA(n_components)

        Y = pca.fit_transform(X)
        Ysk = skpca.fit_transform(X)
        assert_columns_allclose_upto_sign(Y, Ysk)
Esempio n. 7
0
    def check_results(Estimator, copy_data):
        if Estimator is EMPCA:
            # copy_data not yet implemented
            pca = Estimator(2, **KWDS[Estimator])
        else:
            pca = Estimator(2, copy_data=copy_data, **KWDS[Estimator])

        Y1 = pca.fit_transform(X.copy(), weights=W.copy())
        Y2 = pca.transform(X.copy(), weights=W.copy())

        assert_columns_allclose_upto_sign(Y1, Y2)
Esempio n. 8
0
    def check_results(Estimator, copy_data):
        if Estimator is EMPCA:
            # copy_data not yet implemented
            pca = Estimator(2, **KWDS[Estimator])
        else:
            pca = Estimator(2, copy_data=copy_data, **KWDS[Estimator])

        Y1 = pca.fit_transform(X.copy(), weights=W.copy())
        Y2 = pca.transform(X.copy(), weights=W.copy())

        assert_columns_allclose_upto_sign(Y1, Y2)
Esempio n. 9
0
    def check_results(Estimator, n_outliers, noise_level, rtol):
        i = rand.randint(0, 100, size=n_outliers)
        j = rand.randint(0, 2, size=n_outliers)
        X2 = X.copy()
        X2[i, j] += noise_level * rand.randn(n_outliers)
        W2 = np.ones_like(X2)
        W2[i, j] = 1. / noise_level

        pca2 = Estimator(2, **KWDS[Estimator]).fit(X2, weights=W2)
        assert_columns_allclose_upto_sign(pca.components_.T,
                                          pca2.components_.T,
                                          rtol=rtol)
Esempio n. 10
0
    def check_results(Estimator, n_outliers, noise_level, rtol):
        i = rand.randint(0, 100, size=n_outliers)
        j = rand.randint(0, 2, size=n_outliers)
        X2 = X.copy()
        X2[i, j] += noise_level * rand.randn(n_outliers)
        W2 = np.ones_like(X2)
        W2[i, j] = 1. / noise_level

        pca2 = Estimator(2, **KWDS[Estimator]).fit(X2, weights=W2)
        assert_columns_allclose_upto_sign(pca.components_.T,
                                          pca2.components_.T,
                                          rtol=rtol)
Esempio n. 11
0
    def check_results(Estimator):
        pca1 = Estimator(2, **KWDS[Estimator]).fit(X, weights=W)
        pca2 = Estimator(2, **KWDS[Estimator]).fit(X2, weights=W)
        assert_columns_allclose_upto_sign(pca1.components_.T,
                                          pca2.components_.T)
        assert_allclose(pca1.explained_variance_, pca2.explained_variance_)
        assert_allclose(pca1.explained_variance_ratio_,
                        pca2.explained_variance_ratio_)

        Y1 = pca1.transform(X, W)
        Y2 = pca2.transform(X2, W)
        assert_columns_allclose_upto_sign(Y1, Y2)

        Z1 = pca1.reconstruct(X, W)
        Z2 = pca2.reconstruct(X2, W)
        assert_allclose(Z1, Z2)
Esempio n. 12
0
    def check_results(Estimator):
        pca1 = Estimator(2, **KWDS[Estimator]).fit(X, weights=W)
        pca2 = Estimator(2, **KWDS[Estimator]).fit(X2, weights=W)
        assert_columns_allclose_upto_sign(pca1.components_.T,
                                          pca2.components_.T)
        assert_allclose(pca1.explained_variance_,
                        pca2.explained_variance_)
        assert_allclose(pca1.explained_variance_ratio_,
                        pca2.explained_variance_ratio_)

        Y1 = pca1.transform(X, W)
        Y2 = pca2.transform(X2, W)
        assert_columns_allclose_upto_sign(Y1, Y2)

        Z1 = pca1.reconstruct(X, W)
        Z2 = pca2.reconstruct(X2, W)
        assert_allclose(Z1, Z2)
Esempio n. 13
0
    def check_results(Estimator):
        pca1 = Estimator(2, **KWDS[Estimator]).fit(X)
        pca2 = Estimator(2, **KWDS[Estimator]).fit(X, weights=W)
        assert_columns_allclose_upto_sign(pca1.components_.T,
                                          pca2.components_.T)
        assert_allclose(pca1.explained_variance_,
                        pca2.explained_variance_)
        assert_allclose(pca1.explained_variance_ratio_,
                        pca2.explained_variance_ratio_)

        Y1 = pca1.transform(X)
        Y2 = pca2.transform(X, weights=W)
        assert_columns_allclose_upto_sign(Y1, Y2)

        X1 = pca1.inverse_transform(Y1)
        X2 = pca2.inverse_transform(Y2)
        assert_allclose(X1, X2)

        assert_columns_allclose_upto_sign(pca1.fit_transform(X),
                                          pca2.fit_transform(X, weights=W))

        assert_allclose(pca1.reconstruct(X),
                        pca2.reconstruct(X, weights=W))

        assert_allclose(pca1.fit_reconstruct(X),
                        pca2.fit_reconstruct(X, weights=W))
Esempio n. 14
0
    def check_results(Estimator):
        pca1 = Estimator(2, **KWDS[Estimator]).fit(X)
        pca2 = Estimator(2, **KWDS[Estimator]).fit(X, weights=W)
        assert_columns_allclose_upto_sign(pca1.components_.T,
                                          pca2.components_.T)
        assert_allclose(pca1.explained_variance_, pca2.explained_variance_)
        assert_allclose(pca1.explained_variance_ratio_,
                        pca2.explained_variance_ratio_)

        Y1 = pca1.transform(X)
        Y2 = pca2.transform(X, weights=W)
        assert_columns_allclose_upto_sign(Y1, Y2)

        X1 = pca1.inverse_transform(Y1)
        X2 = pca2.inverse_transform(Y2)
        assert_allclose(X1, X2)

        assert_columns_allclose_upto_sign(pca1.fit_transform(X),
                                          pca2.fit_transform(X, weights=W))

        assert_allclose(pca1.reconstruct(X), pca2.reconstruct(X, weights=W))

        assert_allclose(pca1.fit_reconstruct(X),
                        pca2.fit_reconstruct(X, weights=W))