Search in sources :

Example 1 with Variable

use of dr.inference.model.Variable in project beast-mcmc by beast-dev.

the class Tutorial1 method main.

public static void main(String[] arg) throws IOException, TraceException {
    // constructing random variable representing mean of normal distribution
    Variable.D mean = new Variable.D("mean", 1.0);
    // give mean a uniform prior [-1000, 1000]
    mean.addBounds(new Parameter.DefaultBounds(1000, -1000, 1));
    // constructing random variable representing stdev of normal distribution
    Variable.D stdev = new Variable.D("stdev", 1.0);
    // give stdev a uniform prior [0, 1000]
    stdev.addBounds(new Parameter.DefaultBounds(1000, 0, 1));
    // construct normal distribution model
    NormalDistributionModel normal = new NormalDistributionModel(mean, stdev);
    // construct a likelihood for normal distribution
    DistributionLikelihood likelihood = new DistributionLikelihood(normal);
    // construct data
    Attribute.Default<double[]> d = new Attribute.Default<double[]>("x", new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    // add data (representing 9 independent observations) to likelihood
    likelihood.addData(d);
    // construct two "operators" to be used as the proposal distribution
    MCMCOperator meanMove = new ScaleOperator(mean, 0.75);
    MCMCOperator stdevMove = new ScaleOperator(stdev, 0.75);
    // construct a logger to log progress of MCMC run to stdout (screen)
    MCLogger logger1 = new MCLogger(100);
    logger1.add(mean);
    logger1.add(stdev);
    // construct a logger to log to a log file for later analysis
    MCLogger logger2 = new MCLogger("tutorial1.log", 100, false, 0);
    logger2.add(mean);
    logger2.add(stdev);
    // construct MCMC object
    MCMC mcmc = new MCMC("tutorial1:normal");
    // initialize MCMC with chain length, likelihood, operators and loggers
    mcmc.init(100000, likelihood, new MCMCOperator[] { meanMove, stdevMove }, new Logger[] { logger1, logger2 });
    // run the mcmc
    mcmc.chain();
    // perform post-analysis
    TraceAnalysis.report("tutorial1.log");
}
Also used : Variable(dr.inference.model.Variable) Attribute(dr.util.Attribute) MCMC(dr.inference.mcmc.MCMC) NormalDistributionModel(dr.inference.distribution.NormalDistributionModel) 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 2 with Variable

use of dr.inference.model.Variable in project beast-mcmc by beast-dev.

the class CachedDistributionLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String name = xo.hasId() ? xo.getId() : CACHED_PRIOR;
    final AbstractDistributionLikelihood likelihood = (AbstractDistributionLikelihood) xo.getChild(AbstractDistributionLikelihood.class);
    final Variable variable = (Variable) xo.getChild(Variable.class);
    final Logger logger = Logger.getLogger("dr.inference");
    logger.info("Constructing a cache around likelihood '" + likelihood.getId() + "', signal = " + variable.getVariableName());
    return new CachedDistributionLikelihood(name, likelihood, variable);
}
Also used : Variable(dr.inference.model.Variable) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) Logger(java.util.logging.Logger)

Example 3 with Variable

use of dr.inference.model.Variable in project beast-mcmc by beast-dev.

the class GammaSiteBMAParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL);
    Parameter muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
    Parameter logitInvar = (Parameter) xo.getElementFirstChild(LOGIT_PROPORTION_INVARIANT);
    final XMLObject cxo = xo.getChild(LOG_GAMMA_SHAPE);
    Parameter logShape = (Parameter) cxo.getChild(Parameter.class);
    int catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES);
    Variable<Integer> modelChoose = (Variable<Integer>) xo.getElementFirstChild(MODEL_CHOOSE);
    return new GammaSiteBMA(substitutionModel, muParam, logitInvar, logShape, catCount, modelChoose);
}
Also used : GammaSiteBMA(dr.oldevomodel.sitemodel.GammaSiteBMA) Variable(dr.inference.model.Variable) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Example 4 with Variable

use of dr.inference.model.Variable in project beast-mcmc by beast-dev.

the class GTRParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    Variable rateACValue = null;
    if (xo.hasChildNamed(A_TO_C)) {
        rateACValue = (Variable) xo.getElementFirstChild(A_TO_C);
    }
    Variable rateAGValue = null;
    if (xo.hasChildNamed(A_TO_G)) {
        rateAGValue = (Variable) xo.getElementFirstChild(A_TO_G);
    }
    Variable rateATValue = null;
    if (xo.hasChildNamed(A_TO_T)) {
        rateATValue = (Variable) xo.getElementFirstChild(A_TO_T);
    }
    Variable rateCGValue = null;
    if (xo.hasChildNamed(C_TO_G)) {
        rateCGValue = (Variable) xo.getElementFirstChild(C_TO_G);
    }
    Variable rateCTValue = null;
    if (xo.hasChildNamed(C_TO_T)) {
        rateCTValue = (Variable) xo.getElementFirstChild(C_TO_T);
    }
    Variable rateGTValue = null;
    if (xo.hasChildNamed(G_TO_T)) {
        rateGTValue = (Variable) xo.getElementFirstChild(G_TO_T);
    }
    int countNull = 0;
    if (rateACValue == null)
        countNull++;
    if (rateAGValue == null)
        countNull++;
    if (rateATValue == null)
        countNull++;
    if (rateCGValue == null)
        countNull++;
    if (rateCTValue == null)
        countNull++;
    if (rateGTValue == null)
        countNull++;
    if (countNull != 1)
        throw new XMLParseException("Only five parameters may be specified in GTR, leave exactly one out, the others will be specifed relative to the one left out.");
    return new GTR(rateACValue, rateAGValue, rateATValue, rateCGValue, rateCTValue, rateGTValue, freqModel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Variable(dr.inference.model.Variable) GTR(dr.oldevomodel.substmodel.GTR)

Example 5 with Variable

use of dr.inference.model.Variable in project beast-mcmc by beast-dev.

the class NtdBMAParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Variable kappa = (Variable) xo.getElementFirstChild(KAPPA);
    Variable tn = (Variable) xo.getElementFirstChild(TN);
    Variable ac = (Variable) xo.getElementFirstChild(AC);
    Variable at = (Variable) xo.getElementFirstChild(AT);
    Variable gc = (Variable) xo.getElementFirstChild(GC);
    Variable gt = (Variable) xo.getElementFirstChild(GT);
    Variable modelChoose = (Variable) xo.getElementFirstChild(MODEL_CHOOSE);
    XMLObject cxo = xo.getChild(FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    return new NtdBMA(kappa, tn, ac, at, gc, gt, modelChoose, freqModel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Variable(dr.inference.model.Variable) NtdBMA(dr.oldevomodel.substmodel.NtdBMA)

Aggregations

Variable (dr.inference.model.Variable)9 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)4 Parameter (dr.inference.model.Parameter)3 AbstractDistributionLikelihood (dr.inference.distribution.AbstractDistributionLikelihood)1 CachedDistributionLikelihood (dr.inference.distribution.CachedDistributionLikelihood)1 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)1 NormalDistributionModel (dr.inference.distribution.NormalDistributionModel)1 MCLogger (dr.inference.loggers.MCLogger)1 MCMC (dr.inference.mcmc.MCMC)1 MCMCOperator (dr.inference.operators.MCMCOperator)1 RandomWalkIntegerOperator (dr.inference.operators.RandomWalkIntegerOperator)1 ScaleOperator (dr.inference.operators.ScaleOperator)1 UniformIntegerOperator (dr.inference.operators.UniformIntegerOperator)1 GammaSiteBMA (dr.oldevomodel.sitemodel.GammaSiteBMA)1 GTR (dr.oldevomodel.substmodel.GTR)1 HKY (dr.oldevomodel.substmodel.HKY)1 NtdBMA (dr.oldevomodel.substmodel.NtdBMA)1 SubstitutionModel (dr.oldevomodel.substmodel.SubstitutionModel)1 TN93 (dr.oldevomodel.substmodel.TN93)1 Attribute (dr.util.Attribute)1