Exemple #1
0
def test_pca_inverse_transform(datatype):
    gdf = pygdf.DataFrame()
    gdf['0'] = np.asarray([-1, -2, -3, 1, 2, 3], dtype=datatype)
    gdf['1'] = np.asarray([-1, -1, -2, 1, 1, 2], dtype=datatype)

    cutsvd = cuTSVD(n_components=1)
    Xcutsvd = cutsvd.fit_transform(gdf)

    print("Calling inverse_transform")
    input_gdf = cutsvd.inverse_transform(Xcutsvd)
    print(input_gdf)
    assert array_equal(input_gdf, gdf, 0.4, with_sign=True)
Exemple #2
0
def test_pca_fit_transform(datatype):
    gdf = pygdf.DataFrame()
    gdf['0'] = np.asarray([-1, -2, -3, 1, 2, 3], dtype=datatype)
    gdf['1'] = np.asarray([-1, -1, -2, 1, 1, 2], dtype=datatype)

    X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]],
                 dtype=datatype)

    print("Calling fit_transform")
    cutsvd = cuTSVD(n_components=1)
    Xcutsvd = cutsvd.fit_transform(gdf)
    sktsvd = skTSVD(n_components=1)
    Xsktsvd = sktsvd.fit_transform(X)

    assert array_equal(Xcutsvd, Xsktsvd, 1e-3, with_sign=False)
Exemple #3
0
def test_tsvd_fit(datatype):
    gdf = pygdf.DataFrame()
    gdf['0'] = np.asarray([-1, -2, -3, 1, 2, 3], dtype=datatype)
    gdf['1'] = np.asarray([-1, -1, -2, 1, 1, 2], dtype=datatype)

    X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]],
                 dtype=datatype)

    print("Calling fit")
    cutsvd = cuTSVD(n_components=1)
    cutsvd.fit(gdf)
    sktsvd = skTSVD(n_components=1)
    sktsvd.fit(X)

    for attr in [
            'singular_values_', 'components_', 'explained_variance_ratio_'
    ]:
        with_sign = False if attr in ['components_'] else True
        assert array_equal(getattr(cutsvd, attr),
                           getattr(sktsvd, attr),
                           0.4,
                           with_sign=with_sign)