Search in sources :

Example 1 with BirthDeathSerialSamplingModel

use of dr.evomodel.speciation.BirthDeathSerialSamplingModel in project beast-mcmc by beast-dev.

the class BirthDeathSSLikelihoodTest method likelihoodTester.

private void likelihoodTester(Tree tree, double birthRate, double deathRate, Variable<Double> origin, double logL) {
    Variable<Double> b = new Variable.D("b", birthRate);
    Variable<Double> d = new Variable.D("d", deathRate);
    Variable<Double> psi = new Variable.D("psi", this.psi);
    Variable<Double> p = new Variable.D("p", this.p);
    Variable<Double> r = new Variable.D("r", 0.5);
    Variable<Double> fTime = new Variable.D("time", 0.0);
    SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, true, origin, Units.Type.YEARS);
    Likelihood likelihood = new SpeciationLikelihood(tree, speciationModel, "bdss.like");
    assertEquals(logL, likelihood.getLogLikelihood());
}
Also used : Likelihood(dr.inference.model.Likelihood) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) BirthDeathSerialSamplingModel(dr.evomodel.speciation.BirthDeathSerialSamplingModel) SpeciationModel(dr.evomodel.speciation.SpeciationModel) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood)

Example 2 with BirthDeathSerialSamplingModel

use of dr.evomodel.speciation.BirthDeathSerialSamplingModel in project beast-mcmc by beast-dev.

the class BirthDeathSerialSamplingModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String modelName = xo.getId();
    final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
    boolean hasFinalSample = xo.getAttribute(HAS_FINAL_SAMPLE, false);
    final Parameter lambda = (Parameter) xo.getElementFirstChild(LAMBDA);
    boolean relativeDeath = xo.hasChildNamed(RELATIVE_MU);
    Parameter mu;
    if (relativeDeath) {
        mu = (Parameter) xo.getElementFirstChild(RELATIVE_MU);
    } else {
        mu = (Parameter) xo.getElementFirstChild(MU);
    }
    final Parameter psi = (Parameter) xo.getElementFirstChild(PSI);
    //Issue 656: fix p=0
    final Parameter p = xo.hasChildNamed(SAMPLE_PROBABILITY) ? (Parameter) xo.getElementFirstChild(SAMPLE_PROBABILITY) : new Parameter.Default(0.0);
    Parameter origin = null;
    if (xo.hasChildNamed(ORIGIN)) {
        origin = (Parameter) xo.getElementFirstChild(ORIGIN);
    }
    final Parameter r = xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? (Parameter) xo.getElementFirstChild(SAMPLE_BECOMES_NON_INFECTIOUS) : new Parameter.Default(0.0);
    //        r.setParameterValueQuietly(0, 1 - r.getParameterValue(0)); // donot use it, otherwise log is changed improperly
    //        final Parameter finalTimeInterval = xo.hasChildNamed(FINAL_TIME_INTERVAL) ?
    //                (Parameter) xo.getElementFirstChild(FINAL_TIME_INTERVAL) : new Parameter.Default(0.0);
    Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? getCitationRT() : getCitationPsiOrg());
    return new BirthDeathSerialSamplingModel(modelName, lambda, mu, psi, p, relativeDeath, r, hasFinalSample, origin, units);
}
Also used : BirthDeathSerialSamplingModel(dr.evomodel.speciation.BirthDeathSerialSamplingModel) Parameter(dr.inference.model.Parameter) Units(dr.evolution.util.Units) XMLUnits(dr.evoxml.util.XMLUnits)

Example 3 with BirthDeathSerialSamplingModel

use of dr.evomodel.speciation.BirthDeathSerialSamplingModel in project beast-mcmc by beast-dev.

the class BirthDeathEpidemiologyModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String modelName = xo.getId();
    final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
    final Parameter R0Parameter = (Parameter) xo.getElementFirstChild(R0);
    final Parameter recoveryRateParameter = (Parameter) xo.getElementFirstChild(RECOVERY_RATE);
    final Parameter samplingProbabiltyParameter = (Parameter) xo.getElementFirstChild(SAMPLING_PROBABILITY);
    Parameter origin = null;
    if (xo.hasChildNamed(ORIGIN)) {
        origin = (Parameter) xo.getElementFirstChild(ORIGIN);
    }
    Logger.getLogger("dr.evomodel").info("Using epidemiological parameterization of " + getCitationRT());
    return new BirthDeathSerialSamplingModel(modelName, R0Parameter, recoveryRateParameter, samplingProbabiltyParameter, origin, units);
}
Also used : BirthDeathSerialSamplingModel(dr.evomodel.speciation.BirthDeathSerialSamplingModel) Parameter(dr.inference.model.Parameter) Units(dr.evolution.util.Units) XMLUnits(dr.evoxml.util.XMLUnits)

Example 4 with BirthDeathSerialSamplingModel

use of dr.evomodel.speciation.BirthDeathSerialSamplingModel in project beast-mcmc by beast-dev.

the class BirthDeathSSLikelihoodTest method testBirthDeathLikelihoodBEAST2.

public void testBirthDeathLikelihoodBEAST2() {
    System.out.println("RootHeight = " + tree2.getRootHeight());
    Variable<Double> origin = new Variable.D("origin", 6.0);
    final double birthRate = 2.0;
    final double deathRate = 1.0;
    // rate of sampling taxa through time
    final double psiRate = 0.5;
    // the proportion of taxa sampled, default to fix to 0
    final double sampleProbability = 0.0;
    final boolean hasFinalSample = false;
    Variable<Double> b = new Variable.D("b", birthRate);
    Variable<Double> d = new Variable.D("d", deathRate);
    Variable<Double> psi = new Variable.D("psi", psiRate);
    Variable<Double> p = new Variable.D("p", sampleProbability);
    // sampleBecomesNonInfectiousProb
    Variable<Double> r = new Variable.D("r", 0.0);
    SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, hasFinalSample, origin, Units.Type.YEARS);
    Likelihood likelihood = new SpeciationLikelihood(tree2, speciationModel, "bdss.like");
    assertEquals(-19.0198, likelihood.getLogLikelihood(), 1e-5);
}
Also used : Likelihood(dr.inference.model.Likelihood) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) BirthDeathSerialSamplingModel(dr.evomodel.speciation.BirthDeathSerialSamplingModel) SpeciationModel(dr.evomodel.speciation.SpeciationModel) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood)

Aggregations

BirthDeathSerialSamplingModel (dr.evomodel.speciation.BirthDeathSerialSamplingModel)4 Units (dr.evolution.util.Units)2 SpeciationLikelihood (dr.evomodel.speciation.SpeciationLikelihood)2 SpeciationModel (dr.evomodel.speciation.SpeciationModel)2 XMLUnits (dr.evoxml.util.XMLUnits)2 Likelihood (dr.inference.model.Likelihood)2 Parameter (dr.inference.model.Parameter)2