Example #1
0
def test_pca__fit(sample_dataset):
    est = pca.TruncatedSVD(compute=False)
    est = pca.pca_fit(sample_dataset, est)
    assert hasattr(est, "components_")
    est = pca.TruncatedSVD(compute=False)
    est = pca.pca_fit(sample_dataset.drop_vars("call_alternate_allele_count"), est)
    assert hasattr(est, "components_")
Example #2
0
def test_pca__transform(sample_dataset):
    est = pca.TruncatedSVD()
    est = pca.pca_fit(sample_dataset, est)
    pca.pca_transform(sample_dataset, est).compute()
    pca.pca_transform(
        sample_dataset.drop_vars("call_alternate_allele_count"), est
    ).compute()
Example #3
0
def test_pca__stats(sample_dataset):
    # Test estimator with absent properties
    est = pca.TruncatedSVD()
    est = pca.pca_fit(sample_dataset, est)
    del est.explained_variance_ratio_
    ds = pca.pca_stats(xr.Dataset(), est)
    assert "sample_pca_explained_variance_ratio" not in ds
    assert "sample_pca_explained_variance" in ds
    # Validate loadings by ensuring that the sum of squares
    # across variants is equal to the eigenvalues (which are
    # equal to the explained variance)
    np.testing.assert_almost_equal(
        (ds["sample_pca_loading"] ** 2).sum(dim="variants").values,
        ds["sample_pca_explained_variance"].values,
        decimal=3,
    )