Search in sources :

Example 1 with SimpleOperatorSchedule

use of dr.inference.operators.SimpleOperatorSchedule in project beast-mcmc by beast-dev.

the class GibbsSubtreeSwapTestProblem method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    GibbsSubtreeSwap operator = new GibbsSubtreeSwap(treeModel, false, 1.0);
    ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, CoercionMode.COERCION_ON, 1.0);
    UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    schedule.addOperator(operator);
    schedule.addOperator(scaleOperator);
    schedule.addOperator(uniformOperator);
    return schedule;
}
Also used : SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) GibbsSubtreeSwap(dr.evomodel.operators.GibbsSubtreeSwap) Parameter(dr.inference.model.Parameter) UniformOperator(dr.inference.operators.UniformOperator) ScaleOperator(dr.inference.operators.ScaleOperator)

Example 2 with SimpleOperatorSchedule

use of dr.inference.operators.SimpleOperatorSchedule in project beast-mcmc by beast-dev.

the class NarrowExchangeTest method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(DefaultTreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    ExchangeOperator operator = new ExchangeOperator(ExchangeOperator.NARROW, treeModel, 1.0);
    ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, AdaptationMode.ADAPTATION_ON, 1.0);
    UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    schedule.addOperator(operator);
    schedule.addOperator(scaleOperator);
    schedule.addOperator(uniformOperator);
    return schedule;
}
Also used : SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) ExchangeOperator(dr.evomodel.operators.ExchangeOperator) Parameter(dr.inference.model.Parameter) UniformOperator(dr.inference.operators.UniformOperator) ScaleOperator(dr.inference.operators.ScaleOperator)

Example 3 with SimpleOperatorSchedule

use of dr.inference.operators.SimpleOperatorSchedule in project beast-mcmc by beast-dev.

the class ARGAddRemoveOperatorTest method getSchedule.

public static OperatorSchedule getSchedule(ARGModel arg) {
    CompoundParameter rootHeight = (CompoundParameter) arg.createNodeHeightsParameter(true, false, false);
    CompoundParameter internalHeights = (CompoundParameter) arg.createNodeHeightsParameter(false, true, false);
    // CompoundParameter allInternalNodeHeights = (CompoundParameter) arg.createNodeHeightsParameter(true, true, false);
    // CompoundParameter rates = (CompoundParameter) arg.createNodeRatesParameter(false, true, true);
    // ARGAddRemoveEventOperator operator1 = new ARGAddRemoveEventOperator(arg, 5, 0.5,
    // AdaptationMode.ADAPTATION_ON, internalHeights, allInternalNodeHeights, rates, 0.9, null,-1);
    ScaleOperator operator2 = new ScaleOperator(rootHeight, 0.75, AdaptationMode.ADAPTATION_ON, 5);
    ScaleOperator operator3 = new ScaleOperator(internalHeights, 0.75, AdaptationMode.ADAPTATION_ON, 10);
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    // schedule.addOperator(operator1);
    schedule.addOperator(operator2);
    schedule.addOperator(operator3);
    return schedule;
// <scaleOperator id="rootOperator" scaleFactor="0.5"
// weight="10">
// <parameter idref="argModel.rootHeight" />
// </scaleOperator>
// 
// <scaleOperator scaleFactor="0.95" weight="10">
// <parameter idref="argModel.internalNodeHeights" />
// </scaleOperator>
// <ARGEventOperator weight="5" addProbability="0.5"
// autoOptimize="false">
// <argTreeModel idref="argModel" />
// <internalNodes>
// <parameter idref="argModel.internalNodeHeights" />
// </internalNodes>
// <internalNodesPlusRoot>
// <parameter idref="argModel.allInternalNodeHeights" />
// </internalNodesPlusRoot>
// <nodeRates>
// <parameter idref="argModel.rates" />
// </nodeRates>
// </ARGEventOperator>
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) ScaleOperator(dr.inference.operators.ScaleOperator)

Example 4 with SimpleOperatorSchedule

use of dr.inference.operators.SimpleOperatorSchedule in project beast-mcmc by beast-dev.

the class LognormalPriorTest method testLognormalPrior.

public void testLognormalPrior() {
    // ConstantPopulation constant = new ConstantPopulation(Units.Type.YEARS);
    // constant.setN0(popSize); // popSize
    Parameter popSize = new Parameter.Default(6.0);
    popSize.setId(ConstantPopulationModelParser.POPULATION_SIZE);
    ConstantPopulationModel demo = new ConstantPopulationModel(popSize, Units.Type.YEARS);
    // Likelihood
    Likelihood dummyLikelihood = new DummyLikelihood(demo);
    // Operators
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    MCMCOperator operator = new ScaleOperator(popSize, 0.75);
    operator.setWeight(1.0);
    schedule.addOperator(operator);
    // Log
    ArrayLogFormatter formatter = new ArrayLogFormatter(false);
    MCLogger[] loggers = new MCLogger[2];
    loggers[0] = new MCLogger(formatter, 1000, false);
    // loggers[0].add(treeLikelihood);
    loggers[0].add(popSize);
    loggers[1] = new MCLogger(new TabDelimitedFormatter(System.out), 100000, false);
    // loggers[1].add(treeLikelihood);
    loggers[1].add(popSize);
    // MCMC
    MCMC mcmc = new MCMC("mcmc1");
    MCMCOptions options = new MCMCOptions(1000000);
    // meanInRealSpace="false"
    DistributionLikelihood logNormalLikelihood = new DistributionLikelihood(new LogNormalDistribution(1.0, 1.0), 0);
    logNormalLikelihood.addData(popSize);
    List<Likelihood> likelihoods = new ArrayList<Likelihood>();
    likelihoods.add(logNormalLikelihood);
    Likelihood prior = new CompoundLikelihood(0, likelihoods);
    likelihoods.clear();
    likelihoods.add(dummyLikelihood);
    Likelihood likelihood = new CompoundLikelihood(-1, likelihoods);
    likelihoods.clear();
    likelihoods.add(prior);
    likelihoods.add(likelihood);
    Likelihood posterior = new CompoundLikelihood(0, likelihoods);
    mcmc.setShowOperatorAnalysis(true);
    mcmc.init(options, posterior, schedule, loggers);
    mcmc.run();
    // time
    System.out.println(mcmc.getTimer().toString());
    // Tracer
    List<Trace> traces = formatter.getTraces();
    ArrayTraceList traceList = new ArrayTraceList("LognormalPriorTest", traces, 0);
    for (int i = 1; i < traces.size(); i++) {
        traceList.analyseTrace(i);
    }
    // <expectation name="param" value="4.48168907"/>
    TraceCorrelation popSizeStats = traceList.getCorrelationStatistics(traceList.getTraceIndex(ConstantPopulationModelParser.POPULATION_SIZE));
    System.out.println("Expectation of Log-Normal(1,1) is e^(M+S^2/2) = e^(1.5) = " + Math.exp(1.5));
    assertExpectation(ConstantPopulationModelParser.POPULATION_SIZE, popSizeStats, Math.exp(1.5));
}
Also used : CompoundLikelihood(dr.inference.model.CompoundLikelihood) Likelihood(dr.inference.model.Likelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) DummyLikelihood(dr.inference.model.DummyLikelihood) MCMC(dr.inference.mcmc.MCMC) ArrayList(java.util.ArrayList) LogNormalDistribution(dr.math.distributions.LogNormalDistribution) MCMCOptions(dr.inference.mcmc.MCMCOptions) DummyLikelihood(dr.inference.model.DummyLikelihood) ArrayLogFormatter(dr.inference.loggers.ArrayLogFormatter) TraceCorrelation(dr.inference.trace.TraceCorrelation) ConstantPopulationModel(dr.evomodel.coalescent.demographicmodel.ConstantPopulationModel) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) CompoundLikelihood(dr.inference.model.CompoundLikelihood) TabDelimitedFormatter(dr.inference.loggers.TabDelimitedFormatter) Trace(dr.inference.trace.Trace) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) ArrayTraceList(dr.inference.trace.ArrayTraceList) Parameter(dr.inference.model.Parameter) ScaleOperator(dr.inference.operators.ScaleOperator) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) MCMCOperator(dr.inference.operators.MCMCOperator) MCLogger(dr.inference.loggers.MCLogger)

Example 5 with SimpleOperatorSchedule

use of dr.inference.operators.SimpleOperatorSchedule in project beast-mcmc by beast-dev.

the class NarrowExchangeTest method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    ExchangeOperator operator = new ExchangeOperator(ExchangeOperator.NARROW, treeModel, 1.0);
    ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, CoercionMode.COERCION_ON, 1.0);
    UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    schedule.addOperator(operator);
    schedule.addOperator(scaleOperator);
    schedule.addOperator(uniformOperator);
    return schedule;
}
Also used : SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) ExchangeOperator(dr.evomodel.operators.ExchangeOperator) Parameter(dr.inference.model.Parameter) UniformOperator(dr.inference.operators.UniformOperator) ScaleOperator(dr.inference.operators.ScaleOperator)

Aggregations

SimpleOperatorSchedule (dr.inference.operators.SimpleOperatorSchedule)7 OperatorSchedule (dr.inference.operators.OperatorSchedule)6 Parameter (dr.inference.model.Parameter)5 ScaleOperator (dr.inference.operators.ScaleOperator)5 UniformOperator (dr.inference.operators.UniformOperator)3 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)2 MCMCOperator (dr.inference.operators.MCMCOperator)2 ConstantPopulationModel (dr.evomodel.coalescent.demographicmodel.ConstantPopulationModel)1 GibbsSubtreeSwap (dr.evomodel.operators.GibbsSubtreeSwap)1 TreeBitRandomWalkOperator (dr.evomodel.operators.TreeBitRandomWalkOperator)1 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)1 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)1 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)1 MCLogger (dr.inference.loggers.MCLogger)1 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)1 MCMC (dr.inference.mcmc.MCMC)1 MCMCOptions (dr.inference.mcmc.MCMCOptions)1 CompoundLikelihood (dr.inference.model.CompoundLikelihood)1 CompoundParameter (dr.inference.model.CompoundParameter)1 DummyLikelihood (dr.inference.model.DummyLikelihood)1