Search in sources :

Example 6 with Parameter

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

the class BeagleTreeLikelihood method main.

public static void main(String[] args) {
    try {
        MathUtils.setSeed(666);
        System.out.println("Test case 1: simulateOnePartition");
        int sequenceLength = 1000;
        ArrayList<Partition> partitionsList = new ArrayList<Partition>();
        // create tree
        NewickImporter importer = new NewickImporter("(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);");
        Tree tree = importer.importTree(null);
        TreeModel treeModel = new TreeModel(tree);
        // create Frequency Model
        Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
        FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
        // create branch model
        Parameter kappa1 = new Parameter.Default(1, 1);
        Parameter kappa2 = new Parameter.Default(1, 1);
        HKY hky1 = new HKY(kappa1, freqModel);
        HKY hky2 = new HKY(kappa2, freqModel);
        HomogeneousBranchModel homogenousBranchSubstitutionModel = new HomogeneousBranchModel(hky1);
        List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
        substitutionModels.add(hky1);
        substitutionModels.add(hky2);
        List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>();
        freqModels.add(freqModel);
        Parameter epochTimes = new Parameter.Default(1, 20);
        // create branch rate model
        Parameter rate = new Parameter.Default(1, 0.001);
        BranchRateModel branchRateModel = new StrictClockBranchRates(rate);
        // create site model
        GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
        BranchModel homogeneousBranchModel = new HomogeneousBranchModel(hky1);
        BranchModel epochBranchModel = new EpochBranchModel(treeModel, substitutionModels, epochTimes);
        // create partition
        Partition partition1 = new //
        Partition(//
        treeModel, //
        homogenousBranchSubstitutionModel, //
        siteRateModel, //
        branchRateModel, //
        freqModel, // from
        0, // to
        sequenceLength - 1, // every
        1);
        partitionsList.add(partition1);
        // feed to sequence simulator and generate data
        BeagleSequenceSimulator simulator = new BeagleSequenceSimulator(partitionsList);
        Alignment alignment = simulator.simulate(false, false);
        BeagleTreeLikelihood nbtl = new BeagleTreeLikelihood(alignment, treeModel, homogeneousBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
        System.out.println("nBTL(homogeneous) = " + nbtl.getLogLikelihood());
        nbtl = new BeagleTreeLikelihood(alignment, treeModel, epochBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
        System.out.println("nBTL(epoch) = " + nbtl.getLogLikelihood());
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
// END: try-catch block
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Partition(dr.app.beagle.tools.Partition) EpochBranchModel(dr.evomodel.branchmodel.EpochBranchModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) BranchModel(dr.evomodel.branchmodel.BranchModel) EpochBranchModel(dr.evomodel.branchmodel.EpochBranchModel) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) MarkovModulatedSubstitutionModel(dr.evomodel.substmodel.MarkovModulatedSubstitutionModel) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) TreeModel(dr.evomodel.tree.TreeModel) Alignment(dr.evolution.alignment.Alignment) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) NewickImporter(dr.evolution.io.NewickImporter) HKY(dr.evomodel.substmodel.nucleotide.HKY) Tree(dr.evolution.tree.Tree) Parameter(dr.inference.model.Parameter)

Example 7 with Parameter

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

the class ConjugateRootTraitPrior method parseConjugateRootTraitPrior.

public static ConjugateRootTraitPrior parseConjugateRootTraitPrior(XMLObject xo, final int dim) throws XMLParseException {
    XMLObject cxo = xo.getChild(CONJUGATE_ROOT_PRIOR);
    Parameter meanParameter = (Parameter) cxo.getChild(MultivariateDistributionLikelihood.MVN_MEAN).getChild(Parameter.class);
    if (meanParameter.getDimension() != dim) {
        throw new XMLParseException("Root prior mean dimension does not match trait diffusion dimension");
    }
    Parameter sampleSizeParameter = (Parameter) cxo.getChild(PRIOR_SAMPLE_SIZE).getChild(Parameter.class);
    return new ConjugateRootTraitPrior(meanParameter.getParameterValues(), sampleSizeParameter.getParameterValue(0));
}
Also used : XMLObject(dr.xml.XMLObject) Parameter(dr.inference.model.Parameter) XMLParseException(dr.xml.XMLParseException)

Example 8 with Parameter

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

the class BranchCategoriesParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter allocationParameter = (Parameter) xo.getElementFirstChild(ALLOCATION);
    CountableBranchCategoryProvider cladeModel;
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    if (!xo.getAttribute(RANDOMIZE, true)) {
        CountableBranchCategoryProvider.CladeBranchCategoryModel cm = new CountableBranchCategoryProvider.CladeBranchCategoryModel(treeModel, allocationParameter);
        for (int i = 0; i < xo.getChildCount(); ++i) {
            if (xo.getChild(i) instanceof XMLObject) {
                XMLObject xoc = (XMLObject) xo.getChild(i);
                if (xoc.getName().equals(LocalClockModelParser.CLADE)) {
                    TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                    boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
                    boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
                    // XML index-start = 1 not 0
                    int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
                    try {
                        cm.setClade(taxonList, rateCategory, includeStem, excludeClade, false);
                    } catch (TreeUtils.MissingTaxonException e) {
                        throw new XMLParseException("Unable to find taxon for clade in countable mixture model: " + e.getMessage());
                    }
                } else if (xoc.getName().equals(LocalClockModelParser.TRUNK)) {
                    TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                    boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
                    boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
                    // XML index-start = 1 not 0
                    int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
                    try {
                        cm.setClade(taxonList, rateCategory, includeStem, excludeClade, true);
                    } catch (TreeUtils.MissingTaxonException e) {
                        throw new XMLParseException("Unable to find taxon for trunk in countable mixture model: " + e.getMessage());
                    }
                }
            }
        }
        cladeModel = cm;
    } else {
        CountableBranchCategoryProvider.IndependentBranchCategoryModel cm = new CountableBranchCategoryProvider.IndependentBranchCategoryModel(treeModel, allocationParameter);
        cm.randomize();
        cladeModel = cm;
    }
    return cladeModel;
}
Also used : TaxonList(dr.evolution.util.TaxonList) TreeModel(dr.evomodel.tree.TreeModel) Parameter(dr.inference.model.Parameter) CountableBranchCategoryProvider(dr.evomodel.branchratemodel.CountableBranchCategoryProvider) TreeUtils(dr.evolution.tree.TreeUtils)

Example 9 with Parameter

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

the class HamiltonianMonteCarloOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    int nSteps = xo.getIntegerAttribute(N_STEPS);
    double stepSize = xo.getDoubleAttribute(STEP_SIZE);
    double drawVariance = xo.getDoubleAttribute(DRAW_VARIANCE);
    int mode = xo.getAttribute(MODE, 0);
    GradientWrtParameterProvider derivative = (GradientWrtParameterProvider) xo.getChild(GradientWrtParameterProvider.class);
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    Transform transform = null;
    if (parameter == null) {
        Transform.Collection collection = (Transform.Collection) xo.getChild(Transform.Collection.class);
        parameter = collection.getParameter();
        transform = collection;
    }
    if (derivative.getDimension() != parameter.getDimension()) {
        throw new XMLParseException("Gradient (" + derivative.getDimension() + ") must be the same dimensions as the parameter (" + parameter.getDimension() + ")");
    }
    if (mode == 0) {
        return new HamiltonianMonteCarloOperator(CoercionMode.DEFAULT, weight, derivative, parameter, transform, stepSize, nSteps, drawVariance);
    } else {
        return new NoUTurnOperator(CoercionMode.DEFAULT, weight, derivative, parameter, stepSize, nSteps, drawVariance);
    }
}
Also used : NoUTurnOperator(dr.inference.operators.hmc.NoUTurnOperator) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) Parameter(dr.inference.model.Parameter) Transform(dr.util.Transform) HamiltonianMonteCarloOperator(dr.inference.operators.hmc.HamiltonianMonteCarloOperator)

Example 10 with Parameter

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

the class NegationOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter data = (Parameter) xo.getChild(Parameter.class);
    double weight = xo.getDoubleAttribute(WEIGHT);
    return new NegationOperator(data, weight);
}
Also used : Parameter(dr.inference.model.Parameter) NegationOperator(dr.inference.operators.NegationOperator)

Aggregations

Parameter (dr.inference.model.Parameter)397 TreeModel (dr.evomodel.tree.TreeModel)62 MatrixParameter (dr.inference.model.MatrixParameter)46 ArrayList (java.util.ArrayList)44 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)43 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)41 Units (dr.evolution.util.Units)36 XMLUnits (dr.evoxml.util.XMLUnits)36 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)30 Tree (dr.evolution.tree.Tree)25 DataType (dr.evolution.datatype.DataType)24 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)23 CompoundParameter (dr.inference.model.CompoundParameter)23 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)21 SitePatterns (dr.evolution.alignment.SitePatterns)20 HKY (dr.evomodel.substmodel.nucleotide.HKY)17 Likelihood (dr.inference.model.Likelihood)17 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)16 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)16 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)16