예제 #1
0
    def test_numba_likelihood(self):
        """
        Test likelihood using numba against the standard likelihood.
        """

        het = HeterodynedData(self.data,
                              times=self.times,
                              detector=self.detector,
                              par=self.parfile)

        priors = dict()
        priors["h0"] = Uniform(0.0, 1.0e-23, "h0")

        for likelihood in ["gaussian", "studentst"]:
            like1 = TargetedPulsarLikelihood(het,
                                             PriorDict(priors),
                                             likelihood=likelihood)
            like1.parameters = {"h0": 1e-24}

            like2 = TargetedPulsarLikelihood(het,
                                             PriorDict(priors),
                                             likelihood=likelihood,
                                             numba=True)
            like2.parameters = {"h0": 1e-24}

            assert like1.log_likelihood() == like2.log_likelihood()
예제 #2
0
    def test_includephase_likelihood(self):
        """
        Test the likelihood when include phase is set to True.
        """

        het = HeterodynedData(self.data,
                              times=self.times,
                              detector=self.detector,
                              par=self.parfile)

        priors = dict()
        priors["h0"] = Uniform(0.0, 1.0e-23, "h0")

        # run with includephase as False
        like1 = TargetedPulsarLikelihood(het,
                                         PriorDict(priors),
                                         likelihood="studentst")
        like1.parameters = {"h0": 1e-24}

        logl1 = like1.log_likelihood()

        # set includephase to True
        like2 = TargetedPulsarLikelihood(het,
                                         PriorDict(priors),
                                         likelihood="studentst")
        like2.parameters = {"h0": 1e-24}
        like2.include_phase = True

        logl2 = like2.log_likelihood()

        print(f"{logl1:.15f} {logl2:.15f}")

        assert np.allclose([logl1], [logl2], atol=1e-10, rtol=0.0)
예제 #3
0
    def test_likelihood_null_likelihood(self):
        """
        Test likelihood and null likelihood.
        """

        het = HeterodynedData(self.data,
                              times=self.times,
                              detector=self.detector,
                              par=self.parfile)

        priors = dict()
        priors["h0"] = Uniform(0.0, 1.0e-23, "h0")

        for likelihood in ["gaussian", "studentst"]:
            like = TargetedPulsarLikelihood(het,
                                            PriorDict(priors),
                                            likelihood=likelihood)
            like.parameters = {"h0": 0.0}

            assert like.log_likelihood() == like.noise_log_likelihood()
# create some fake heterodyned data
detector = "H1"  # the detector to use
times = np.linspace(1000000000.0, 1000086340.0, 1440)  # times
het = HeterodynedData(
    times=times,
    inject=True,
    par=parfile,
    injpar=parfile,
    fakeasd=1e-24,
    detector=detector,
)

# set prior on h0
priors = dict()
priors["h0"] = Uniform(0.0, 1e-24, "h0")

like = TargetedPulsarLikelihood(het, PriorDict(priors))

N = 500
h0s = np.linspace(0.0, 1e-24, N)
post = np.zeros(N)

for i, h0 in enumerate(h0s):
    params = {"h0": h0}
    like.parameters = params
    post[i] = like.log_likelihood() + priors["h0"].ln_prob(h0)

pl.plot(h0s, np.exp(post - np.max(post)), "b")
pl.axvline(het.injpar["H0"])
pl.show()