Example #1
0
    def test_precomputed_sum(self, adata: AnnData):
        mat = random_transition_matrix(adata.n_obs)
        pk = PrecomputedKernel(mat)
        vk = VelocityKernel(adata).compute_transition_matrix(softmax_scale=4)

        expected = (0.5 * vk.transition_matrix) + (0.5 * pk.transition_matrix)
        actual = (pk + vk).compute_transition_matrix()

        np.testing.assert_array_almost_equal(
            expected.toarray(), actual.transition_matrix.toarray())
Example #2
0
    def test_precomputed_no_adata(self):
        pk = PrecomputedKernel(random_transition_matrix(50))
        pk.write_to_adata()

        assert isinstance(pk.adata, AnnData)
        assert pk.adata.shape == (50, 1)
        assert pk.adata.obs.shape == (50, 0)
        assert pk.adata.var.shape == (1, 0)
        assert "T_fwd_params" in pk.adata.uns.keys()
        np.testing.assert_array_equal(pk.adata.obsp["T_fwd"].toarray(),
                                      pk.transition_matrix.toarray())
Example #3
0
    def test_copy_cond_num(self, adata: AnnData):
        for KernelClass in [
                VelocityKernel,
                ConnectivityKernel,
                PalantirKernel,
                PrecomputedKernel,
        ]:
            if KernelClass is PrecomputedKernel:
                k1 = KernelClass(random_transition_matrix(adata.n_obs),
                                 compute_cond_num=True)
            elif KernelClass is VelocityKernel:
                k1 = KernelClass(
                    adata, compute_cond_num=True).compute_transition_matrix(
                        softmax_scale=4)
            else:
                k1 = KernelClass(
                    adata, compute_cond_num=True).compute_transition_matrix()
            k2 = k1.copy()

            assert k1.condition_number == k2.condition_number
Example #4
0
    def test_precomputed_transition_matrix(self, adata: AnnData):
        mat = random_transition_matrix(adata.n_obs)
        pk = PrecomputedKernel(mat)

        np.testing.assert_array_equal(mat, pk.transition_matrix.toarray())
Example #5
0
    def test_precomputed_adata(self, adata: AnnData):
        pk = PrecomputedKernel(random_transition_matrix(adata.n_obs),
                               adata=adata)

        assert pk.adata is adata
Example #6
0
 def test_precomputed_not_a_transition_matrix(self):
     mat = random_transition_matrix(100)
     mat[0, 0] = 0xDEADBEEF
     with pytest.raises(ValueError):
         _ = PrecomputedKernel(mat)