Example #1
0
    def it_compares_to_all_dyetracks_with_row_fit():
        _priors = PriorsMLEFixtures.illumination(row_k_sigma=0.2)
        radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
            dyemat, _priors, n_channels=1, n_samples=500)

        mask = true_dyt_iz > 0
        radmat = radmat[mask]
        true_ks = true_ks[mask]
        nn_v2_context = _test(
            radmat,
            n_neighbors=0,
            run_against_all_dyetracks=True,
            run_row_k_fit=True,
        )

        # Uncomment this to compare to random
        # true_ks = np.random.normal(1.0, 0.5, true_ks.shape[0])

        # In this mode I expect to get back outputs for every radrow vs every dytrow
        assert nn_v2_context.against_all_dyetrack_pvals.shape == (
            radmat.shape[0],
            dyemat.shape[0],
        )
        assert nn_v2_context.against_all_dyetrack_pred_ks.shape == (
            radmat.shape[0],
            dyemat.shape[0],
        )

        pks = nn_v2_context.pred_ks
        mask = ~np.isnan(pks)
        pear_r, _ = stats.pearsonr(true_ks[mask], pks[mask])
        assert pear_r > 0.5
Example #2
0
 def it_enforces_reverse_sort_on_count_per_dyt():
     _dyepeps = np.array(
         [
             [1, 1, 10],
             [1, 2, 30],
         ],
         dtype=np.uint64,
     )
     radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
         dyemat, priors, n_channels=1, n_samples=5)
     with zest.raises(CException,
                      in_args="must be reverse sorted by count per dyt"):
         _test(radmat, _dyepeps=_dyepeps)
Example #3
0
 def it_catches_non_sequential_dyt_iz_in_dyepeps():
     _dyepeps = np.array(
         [
             [1, 1, 10],
             [2, 1, 10],
             [1, 2, 30],
         ],
         dtype=np.uint64,
     )
     radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
         dyemat, priors, n_channels=1, n_samples=5)
     with zest.raises(CException, in_args="Non sequential dyt_i"):
         _test(radmat, _dyepeps=_dyepeps)
Example #4
0
    def it_generates_multichannel_radmat_different_betas():
        _priors = PriorsMLEFixtures.illumination_multi_channel(
            gain_mus_ch=[5000, 15000],
            gain_sigmas_ch=[0, 0],
            bg_sigmas_ch=[0, 0],
            row_k_sigma=0.0,
        )
        radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
            dyemat_2ch, _priors, n_channels=2, n_samples=1)
        # fmt off
        expected = np.array([
            [
                0,
                0,
                0,
                0,
                0,
                0,
            ],
            [
                5000,
                0,
                0,
                15000,
                0,
                0,
            ],
            [
                10000,
                5000,
                5000,
                30000,
                15000,
                15000,
            ],
            [
                15000,
                10000,
                5000,
                45000,
                30000,
                15000,
            ],
        ], )
        # fmt on

        assert np.allclose(radmat, expected)
Example #5
0
 def it_classifies_multichannel():
     _priors = PriorsMLEFixtures.illumination_multi_channel(
         gain_mus_ch=[5000, 15000],
         gain_sigmas_ch=[0, 0],
         bg_sigmas_ch=[0, 0],
     )
     # gain_model = GainModel.multi_channel(
     #     beta=[5000, 15000], sigma=[0, 0], zero_sigma=[0, 0]
     # )
     radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
         dyemat_2ch, _priors, n_channels=2, n_samples=5)
     nn_v2_context = _test(radmat, _dyemat=dyemat_2ch)
     n_same = (true_dyt_iz == nn_v2_context.pred_dyt_iz).sum()
     # This is almost always higher than 0.5, but how to prevent the
     # occasional hiccup?  Classify n times?  You don't want to just
     # retry and allow a terrible result to slip through.
     assert n_same >= int(0.5 * true_dyt_iz.shape[0])
Example #6
0
    def it_fits_k():
        # Does it make a copy of
        _priors = PriorsMLEFixtures.illumination(row_k_sigma=0.2)
        radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
            dyemat, _priors, n_channels=1, n_samples=500)
        mask = true_dyt_iz > 0
        radmat = radmat[mask]
        true_ks = true_ks[mask]
        nn_v2_context = _test(radmat)

        # Uncomment this to compare to random
        # true_ks = np.random.normal(1.0, 0.5, true_ks.shape[0])

        # Check that there's a reasonable correlation between true and pred k
        # I ran this several times and found with random true_ks
        # ie: true_ks = np.random.normal(1.0, 0.5, true_ks.shape[0])
        # was like 0.02 where real was > 0.4
        pks = nn_v2_context.pred_ks
        mask = ~np.isnan(pks)
        pear_r, _ = stats.pearsonr(true_ks[mask], pks[mask])
        assert pear_r > 0.4
Example #7
0
    def it_compares_to_all_dyetracks_without_row_fit():
        radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
            dyemat, priors, n_channels=1, n_samples=5)
        nn_v2_context = _test(radmat,
                              n_neighbors=0,
                              run_against_all_dyetracks=True,
                              run_row_k_fit=False)

        # In this mode I expect to get back outputs for every radrow vs every dytrow
        # But the radrows generated from empties can be ignore
        mask = true_dyt_iz > 0
        n_good_calls = (
            true_dyt_iz[mask] == nn_v2_context.pred_dyt_iz[mask]).sum()
        assert n_good_calls >= int(0.75 * mask.sum())
        assert np.all(nn_v2_context.against_all_dyetrack_pred_ks[:, 1:] == 1.0)
        assert nn_v2_context.against_all_dyetrack_pvals.shape == (
            radmat.shape[0],
            dyemat.shape[0],
        )
        assert nn_v2_context.against_all_dyetrack_pred_ks.shape == (
            radmat.shape[0],
            dyemat.shape[0],
        )
Example #8
0
 def it_classifies():
     radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat(
         dyemat, priors, n_channels=1, n_samples=5)
     nn_v2_context = _test(radmat)
     n_same = (true_dyt_iz == nn_v2_context.pred_dyt_iz).sum()
     assert n_same >= int(0.65 * true_dyt_iz.shape[0])