def add_prior(self, prior): RelaxedClock.add_prior(self, prior) gamma_param_prior = xml.prior(prior, id="clockRateGammaShapePrior.s:%s" % self.name, name="distribution", x="@clockRateGammaShape:%s" % self.name) xml.Exponential(gamma_param_prior, id="clockRateGammaShapePriorExponential.s:%s" % self.name, name="distr", mean="1.0")
def add_prior(self, prior): BaseClock.add_prior(self, prior) # Gamma prior over rates sub_prior = xml.prior(prior, id="RandomRatesPrior.c:%s" % self.name, name="distribution", x="@clockrates.c:%s" % self.name) xml.Gamma(sub_prior, id="RandomRatesPrior:%s" % self.name, name="distr", alpha="@%s" % self.shape_id, beta="@%s" % self.scale_id) # Exponential prior over Gamma scale parameter # (mean param copied from rate heterogeneity implementation in BaseModel) if self.estimate_variance: sub_prior = xml.prior(prior, id="randomClockGammaScalePrior.s:%s" % self.name, name="distribution", x="@%s" % self.shape_id) xml.Exponential(sub_prior, id="randomClockGammaScalePriorExponential.s:%s" % self.name, mean="0.23", name="distr") # Poisson prior over number of rate changes sub_prior = xml.prior(prior, id="RandomRateChangesPrior.c:%s" % self.name, name="distribution") xml.x(sub_prior, id="RandomRateChangesCount:%s" % self.name, spec="util.Sum", arg="@Indicators.c:%s" % self.name) poisson = xml.distr(sub_prior, id="RandomRatechangesPoisson.c:%s" % self.name, spec="beast.math.distributions.Poisson") xml.parameter(poisson, text="0.6931471805599453", id="RandomRateChangesPoissonLambda:%s" % self.name, estimate=False, name="lambda")
def _add_prior(self, prior, name): switch_prior = xml.prior( prior, id="%s:pdcovarion_s_prior.s" % name, name="distribution", x="@%s:pdcovarion_s.s" % name) gamma = xml.Gamma(switch_prior, id="%s: Gamma.0" % name, name="distr") xml.parameter( gamma, text="0.05", id="%s:pdcovarion_switch_gamma_param1" % name, name="alpha", lower="0.0", upper="0.0") xml.parameter( gamma, text="10.0", id="%s:pdcovarion_switch_gamma_param2" % name, name="beta", lower="0.0", upper="0.0") origin_prior = xml.prior( prior, id="%s:pdcovarion_origin_prior.s" % name, name="distribution", x="@%s:pdcovarion_origin.s" % name) xml.Uniform( origin_prior, id="%s:PDCovOriginUniform" % name, name="distr", upper="Infinity") death_prior = xml.prior( prior, id="%s:pdcovarion_death_prior.s" % name, name="distribution", x="@{:}:pdcovarion_death.s".format(name)) xml.Exponential( death_prior, id="%s:PDCovDeathExp" % name, name="distr", mean="1.0")
def add_prior(self, prior): """ Add prior distributions for Gamma-distributed rate heterogenetiy, if configured. """ if self.rate_variation: # Gamma prior with mean 1 over all mutation rates sub_prior = xml.prior(prior, id="featureClockRatePrior.s:%s" % self.name, name="distribution") compound = xml.input(sub_prior, id="featureClockRateCompound:%s" % self.name, spec="beast.core.parameter.CompoundValuable", name="x") plate = xml.plate(compound, var="rate", range=self.all_rates) xml.var(plate, idref="featureClockRate:%s:$(rate)" % self.name) xml.input(sub_prior, id="featureClockRatePriorGamma:%s" % self.name, spec="beast.math.distributions.Gamma", name="distr", alpha="@featureClockRateGammaShape:%s" % self.name, beta="@featureClockRateGammaScale:%s" % self.name) # Exponential hyperprior on scale of Gamma prior # Exponential prior favours small scales over large scales, i.e. less rate variation # Mean scale 0.23 chosen for general sensibility, e.g.: # - Prior distribution is roughly 50/50 that ratio of fastest # to slowest feature rate in a dataset of size 200 is below # or above 10. # - Prior probability of roughly 0.90 that this ratio is below # 100. sub_prior = xml.prior( prior, id="featureClockRateGammaScalePrior.s:%s" % self.name, name="distribution", x="@featureClockRateGammaScale:%s" % self.name) xml.Exponential( sub_prior, id="featureClockRateGammaShapePriorExponential.s:%s" % self.name, mean="0.23", name="distr")
def add_branchrate_model(self, beast): RelaxedClock.add_branchrate_model(self, beast) xml.Exponential(self.branchrate, id="ExponentialDistribution.c:%s" % self.name, mean=self.mean_rate_idref, name="distr")