Search in sources :

Example 1 with TreeLengthStatistic

use of dr.evomodel.tree.TreeLengthStatistic in project beast-mcmc by beast-dev.

the class YuleModelTest method yuleTester.

// public void testYuleWithWideExchange() {
// 
// TreeModel treeModel = new TreeModel("treeModel", tree);
// Doesn't compile...
// yuleTester(treeModel, ExchangeOperatorTest.getWideExchangeSchedule(treeModel));
// }
private void yuleTester(TreeModel treeModel, OperatorSchedule schedule) {
    MCMC mcmc = new MCMC("mcmc1");
    MCMCOptions options = new MCMCOptions(1000000);
    TreeLengthStatistic tls = new TreeLengthStatistic(TL, treeModel);
    TreeHeightStatistic rootHeight = new TreeHeightStatistic(TREE_HEIGHT, treeModel);
    Parameter b = new Parameter.Default("b", 2.0, 0.0, Double.MAX_VALUE);
    Parameter d = new Parameter.Default("d", 0.0, 0.0, Double.MAX_VALUE);
    SpeciationModel speciationModel = new BirthDeathGernhard08Model(b, d, null, BirthDeathGernhard08Model.TreeType.TIMESONLY, Units.Type.YEARS);
    Likelihood likelihood = new SpeciationLikelihood(treeModel, speciationModel, "yule.like");
    ArrayLogFormatter formatter = new ArrayLogFormatter(false);
    MCLogger[] loggers = new MCLogger[2];
    loggers[0] = new MCLogger(formatter, 100, false);
    loggers[0].add(likelihood);
    loggers[0].add(rootHeight);
    loggers[0].add(tls);
    loggers[1] = new MCLogger(new TabDelimitedFormatter(System.out), 100000, false);
    loggers[1].add(likelihood);
    loggers[1].add(rootHeight);
    loggers[1].add(tls);
    mcmc.setShowOperatorAnalysis(true);
    mcmc.init(options, likelihood, schedule, loggers);
    mcmc.run();
    List<Trace> traces = formatter.getTraces();
    ArrayTraceList traceList = new ArrayTraceList("yuleModelTest", traces, 0);
    for (int i = 1; i < traces.size(); i++) {
        traceList.analyseTrace(i);
    }
    // expectation of root height for 4 tips and lambda = 2
    // rootHeight = 0.541666
    // TL = 1.5
    TraceCorrelation tlStats = traceList.getCorrelationStatistics(traceList.getTraceIndex(TL));
    assertExpectation(TL, tlStats, 1.5);
    TraceCorrelation treeHeightStats = traceList.getCorrelationStatistics(traceList.getTraceIndex(TREE_HEIGHT));
    assertExpectation(TREE_HEIGHT, treeHeightStats, 0.5416666);
}
Also used : TraceCorrelation(dr.inference.trace.TraceCorrelation) Likelihood(dr.inference.model.Likelihood) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) BirthDeathGernhard08Model(dr.evomodel.speciation.BirthDeathGernhard08Model) MCMC(dr.inference.mcmc.MCMC) SpeciationModel(dr.evomodel.speciation.SpeciationModel) TabDelimitedFormatter(dr.inference.loggers.TabDelimitedFormatter) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) Trace(dr.inference.trace.Trace) ArrayTraceList(dr.inference.trace.ArrayTraceList) MCMCOptions(dr.inference.mcmc.MCMCOptions) TreeLengthStatistic(dr.evomodel.tree.TreeLengthStatistic) TreeHeightStatistic(dr.evomodel.tree.TreeHeightStatistic) Parameter(dr.inference.model.Parameter) ArrayLogFormatter(dr.inference.loggers.ArrayLogFormatter) MCLogger(dr.inference.loggers.MCLogger)

Example 2 with TreeLengthStatistic

use of dr.evomodel.tree.TreeLengthStatistic in project beast-mcmc by beast-dev.

the class RLYModelTest method randomLocalYuleTester.

private void randomLocalYuleTester(TreeModel treeModel, Parameter I, Parameter b, OperatorSchedule schedule) {
    MCMC mcmc = new MCMC("mcmc1");
    MCMCOptions options = new MCMCOptions(1000000);
    TreeLengthStatistic tls = new TreeLengthStatistic(TL, treeModel);
    TreeHeightStatistic rootHeight = new TreeHeightStatistic(TREE_HEIGHT, treeModel);
    Parameter m = new Parameter.Default("m", 1.0, 0.0, Double.MAX_VALUE);
    SpeciationModel speciationModel = new RandomLocalYuleModel(b, I, m, false, Units.Type.YEARS, 4);
    Likelihood likelihood = new SpeciationLikelihood(treeModel, speciationModel, "randomYule.like");
    ArrayLogFormatter formatter = new ArrayLogFormatter(false);
    MCLogger[] loggers = new MCLogger[2];
    loggers[0] = new MCLogger(formatter, 100, false);
    loggers[0].add(likelihood);
    loggers[0].add(rootHeight);
    loggers[0].add(tls);
    loggers[0].add(I);
    loggers[1] = new MCLogger(new TabDelimitedFormatter(System.out), 100000, false);
    loggers[1].add(likelihood);
    loggers[1].add(rootHeight);
    loggers[1].add(tls);
    loggers[1].add(I);
    mcmc.setShowOperatorAnalysis(true);
    mcmc.init(options, likelihood, schedule, loggers);
    mcmc.run();
    List<Trace> traces = formatter.getTraces();
    ArrayTraceList traceList = new ArrayTraceList("yuleModelTest", traces, 0);
    for (int i = 1; i < traces.size(); i++) {
        traceList.analyseTrace(i);
    }
    TraceCorrelation tlStats = traceList.getCorrelationStatistics(traceList.getTraceIndex("root." + birthRateIndicator));
    System.out.println("mean = " + tlStats.getMean());
    System.out.println("expected mean = 0.5");
    assertExpectation("root." + birthRateIndicator, tlStats, 0.5);
}
Also used : TraceCorrelation(dr.inference.trace.TraceCorrelation) Likelihood(dr.inference.model.Likelihood) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) MCMC(dr.inference.mcmc.MCMC) SpeciationModel(dr.evomodel.speciation.SpeciationModel) TabDelimitedFormatter(dr.inference.loggers.TabDelimitedFormatter) SpeciationLikelihood(dr.evomodel.speciation.SpeciationLikelihood) Trace(dr.inference.trace.Trace) RandomLocalYuleModel(dr.evomodel.speciation.RandomLocalYuleModel) ArrayTraceList(dr.inference.trace.ArrayTraceList) MCMCOptions(dr.inference.mcmc.MCMCOptions) TreeLengthStatistic(dr.evomodel.tree.TreeLengthStatistic) TreeHeightStatistic(dr.evomodel.tree.TreeHeightStatistic) Parameter(dr.inference.model.Parameter) ArrayLogFormatter(dr.inference.loggers.ArrayLogFormatter) MCLogger(dr.inference.loggers.MCLogger)

Example 3 with TreeLengthStatistic

use of dr.evomodel.tree.TreeLengthStatistic in project beast-mcmc by beast-dev.

the class TreeLengthStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Tree tree = (Tree) xo.getChild(Tree.class);
    return new TreeLengthStatistic(name, tree);
}
Also used : Tree(dr.evolution.tree.Tree) TreeLengthStatistic(dr.evomodel.tree.TreeLengthStatistic)

Aggregations

TreeLengthStatistic (dr.evomodel.tree.TreeLengthStatistic)3 SpeciationLikelihood (dr.evomodel.speciation.SpeciationLikelihood)2 SpeciationModel (dr.evomodel.speciation.SpeciationModel)2 TreeHeightStatistic (dr.evomodel.tree.TreeHeightStatistic)2 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)2 MCLogger (dr.inference.loggers.MCLogger)2 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)2 MCMC (dr.inference.mcmc.MCMC)2 MCMCOptions (dr.inference.mcmc.MCMCOptions)2 Likelihood (dr.inference.model.Likelihood)2 Parameter (dr.inference.model.Parameter)2 ArrayTraceList (dr.inference.trace.ArrayTraceList)2 Trace (dr.inference.trace.Trace)2 TraceCorrelation (dr.inference.trace.TraceCorrelation)2 Tree (dr.evolution.tree.Tree)1 BirthDeathGernhard08Model (dr.evomodel.speciation.BirthDeathGernhard08Model)1 RandomLocalYuleModel (dr.evomodel.speciation.RandomLocalYuleModel)1