Beispiel #1
0
def test_pca_transform(array_type):
    A = array_type(A_list).astype('float32')
    A_pca_abs = np.abs(A_pca)
    A_svd_abs = np.abs(A_svd)

    adata = AnnData(A)

    sc.pp.pca(adata,
              n_comps=4,
              zero_center=True,
              svd_solver='arpack',
              dtype='float64')

    assert np.linalg.norm(A_pca_abs[:, :4] -
                          np.abs(adata.obsm['X_pca'])) < 2e-05

    sc.pp.pca(
        adata,
        n_comps=5,
        zero_center=True,
        svd_solver='randomized',
        dtype='float64',
        random_state=14,
    )
    assert np.linalg.norm(A_pca_abs - np.abs(adata.obsm['X_pca'])) < 2e-05

    sc.pp.pca(adata,
              n_comps=4,
              zero_center=False,
              dtype='float64',
              random_state=14)
    assert np.linalg.norm(A_svd_abs[:, :4] -
                          np.abs(adata.obsm['X_pca'])) < 2e-05
Beispiel #2
0
def test_pca_reproducible(pbmc3k_normalized, array_type, float_dtype):
    pbmc = pbmc3k_normalized
    pbmc.X = array_type(pbmc.X)

    a = sc.pp.pca(pbmc, copy=True, dtype=float_dtype, random_state=42)
    b = sc.pp.pca(pbmc, copy=True, dtype=float_dtype, random_state=42)
    c = sc.pp.pca(pbmc, copy=True, dtype=float_dtype, random_state=0)

    assert_equal(a, b)
    # Test that changing random seed changes result
    assert not np.array_equal(a.obsm["X_pca"], c.obsm["X_pca"])
Beispiel #3
0
def test_pca_reproducible(pbmc3k_normalized, array_type):
    pbmc = pbmc3k_normalized
    pbmc.X = array_type(pbmc.X)

    a = sc.pp.pca(pbmc, copy=True, dtype=np.float64, random_state=42)
    b = sc.pp.pca(pbmc, copy=True, dtype=np.float64, random_state=42)
    c = sc.pp.pca(pbmc, copy=True, dtype=np.float64, random_state=0)

    assert_equal(a, b)
    # Test that changing random seed changes result
    # Does not show up reliably with 32 bit computation
    assert not np.array_equal(a.obsm["X_pca"], c.obsm["X_pca"])