Beispiel #1
0
 def prior_eval(self):
     """ Returns the prior evaluator class initialized with a set of
     pre-defined distributions for each parameters.
     """
     parameters, values = zip(*self.parameters.items())
     prior_dists = []
     for param, val in zip(parameters, values):
         if param in ["mass1", "mass2"]:
             dist = distributions.Uniform(**{param: (6, 50)})
         elif param in ["inclination", "dec"]:
             dist = distributions.SinAngle(**{param: None})
         elif param in ["polarization", "ra", "coa_phase"]:
             dist = distributions.Uniform(**{param: (0, 2 * 3.1415)})
         elif param in ["distance"]:
             dist = distributions.UniformRadius(distance=(val - 100,
                                                          val + 300))
         elif param in [
                 "spin1x", "spin1y", "spin1z", "spin2x", "spin2y", "spin2z"
         ]:
             dist = distributions.Uniform(**{param: (-0.1, 0.1)})
         elif param in ["tc"]:
             dist = distributions.Uniform(tc=(val - 0.2, val + 0.2))
         else:
             raise KeyError("Do not recognize parameter %s" % param)
         prior_dists.append(dist)
     return distributions.JointDistribution(parameters, *prior_dists)
Beispiel #2
0
 def full(self, fd_waveform, fd_waveform_generator, zdhp_psd, request):
     marg_prior = [distributions.Uniform(distance=(50, 5000))]
     model = self.TEST_CLASS(
         ['tc'], fd_waveform, fd_waveform_generator, self.fmin,
         psds={ifo: zdhp_psd for ifo in self.ifos},
         distance_marginalization=True, marg_prior=marg_prior)
     return self.CALL_CLASS(model, self.DEFAULT_CALLSTAT,
                            return_all_stats=False)
Beispiel #3
0
 def simple(self, random_data, fd_waveform_generator):
     marg_prior = [distributions.Uniform(distance=(50, 5000))]
     data = {ifo: random_data for ifo in self.ifos}
     model = self.TEST_CLASS([], data, fd_waveform_generator,
                             f_lower=self.fmin,
                             distance_marginalization=True,
                             marg_prior=marg_prior)
     return self.CALL_CLASS(model, self.DEFAULT_CALLSTAT)
Beispiel #4
0
    def test_likelihood_evaluator_init(self):

        # data args
        seglen = 4
        sample_rate = 2048
        N = seglen * sample_rate / 2 + 1
        fmin = 30.

        # setup waveform generator and signal parameters
        m1, m2, s1z, s2z, tsig = 38.6, 29.3, 0., 0., 3.1
        ra, dec, pol, dist = 1.37, -1.26, 2.76, 3 * 500.
        gen = generator.FDomainDetFrameGenerator(generator.FDomainCBCGenerator,
                                                 0.,
                                                 variable_args=["tc"],
                                                 detectors=["H1", "L1"],
                                                 delta_f=1. / seglen,
                                                 f_lower=fmin,
                                                 approximant="TaylorF2",
                                                 mass1=m1,
                                                 mass2=m2,
                                                 spin1z=s1z,
                                                 spin2z=s2z,
                                                 ra=ra,
                                                 dec=dec,
                                                 polarization=pol,
                                                 distance=dist)
        signal = gen.generate(tc=tsig)

        # get PSDs
        psd = pypsd.aLIGOZeroDetHighPower(N, 1. / seglen, 20.)
        psds = {"H1": psd, "L1": psd}

        # get a prior evaluator
        uniform_prior = distributions.Uniform(tc=(tsig - 0.2, tsig + 0.2))
        prior_eval = inference.prior.PriorEvaluator(["tc"], uniform_prior)

        # setup likelihood evaluator
        likelihood_eval = inference.GaussianLikelihood(gen,
                                                       signal,
                                                       fmin,
                                                       psds=psds,
                                                       prior=prior_eval,
                                                       return_meta=False)
Beispiel #5
0
 def model(self, fd_waveform, fd_waveform_generator, prior_eval, zdhp_psd,
           request):
     eval_class = models.models[request.param]
     if request.param == "marginalized_gaussian_noise":
         # Test that the sampler works for time_marginalization
         model = eval_class(
             fd_waveform_generator.variable_args,
             fd_waveform,
             fd_waveform_generator,
             self.fmin,
             psds={ifo: zdhp_psd
                   for ifo in self.ifos},
             prior=prior_eval,
             time_marginalization=True,
             marg_prior=[distributions.Uniform(time=(0, 10000))])
     else:
         model = eval_class(fd_waveform_generator.variable_args,
                            fd_waveform,
                            fd_waveform_generator,
                            self.fmin,
                            psds={ifo: zdhp_psd
                                  for ifo in self.ifos},
                            prior=prior_eval)
     return models.CallModel(model, "logposterior", return_all_stats=False)
Beispiel #6
0
import matplotlib.pyplot as plt
from pycbc import distributions

# Create a mass distribution object that is uniform between 0.5 and 1.5
# solar masses.
mass1_distribution = distributions.Uniform(mass1=(0.5, 1.5))
# Take 100000 random variable samples from this uniform mass distribution.
mass1_samples = mass1_distribution.rvs(size=1000000)

# Draw another distribution that is Gaussian between 0.5 and 1.5 solar masses
# with a mean of 1.2 solar masses and a standard deviation of 0.15 solar
# masses. Gaussian takes the variance as an input so square the standard
# deviation.
variance = 0.15 * 0.15
mass2_gaussian = distributions.Gaussian(mass2=(0.5, 1.5),
                                        mass2_mean=1.2,
                                        mass2_var=variance)

# Take 100000 random variable samples from this gaussian mass distribution.
mass2_samples = mass2_gaussian.rvs(size=1000000)

# We can make pairs of distributions together, instead of apart.
two_mass_distributions = distributions.Uniform(mass3=(1.6, 3.0),
                                               mass4=(1.6, 3.0))
two_mass_samples = two_mass_distributions.rvs(size=1000000)

# Choose 50 bins for the histogram subplots.
n_bins = 50

# Plot histograms of samples in subplots
fig, axes = plt.subplots(nrows=2, ncols=2)