Search in sources :

Example 16 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class DiscretizedBranchRatesParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final int overSampling = xo.getAttribute(OVERSAMPLING, 1);
    //final boolean normalize = xo.getBooleanAttribute(NORMALIZE, false);
    final boolean normalize = xo.getAttribute(NORMALIZE, false);
    /*if(xo.hasAttribute(NORMALIZE))
            normalize = xo.getBooleanAttribute(NORMALIZE);
        }*/
    //final double normalizeBranchRateTo = xo.getDoubleAttribute(NORMALIZE_BRANCH_RATE_TO);
    final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_BRANCH_RATE_TO, Double.NaN);
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    ParametricDistributionModel distributionModel = (ParametricDistributionModel) xo.getElementFirstChild(DISTRIBUTION);
    Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES);
    Logger.getLogger("dr.evomodel").info("\nUsing discretized relaxed clock model.");
    Logger.getLogger("dr.evomodel").info("  over sampling = " + overSampling);
    Logger.getLogger("dr.evomodel").info("  parametric model = " + distributionModel.getModelName());
    Logger.getLogger("dr.evomodel").info("   rate categories = " + rateCategoryParameter.getDimension());
    if (normalize) {
        Logger.getLogger("dr.evomodel").info("   mean rate is normalized to " + normalizeBranchRateTo);
    }
    if (xo.hasAttribute(SINGLE_ROOT_RATE)) {
        //singleRootRate = xo.getBooleanAttribute(SINGLE_ROOT_RATE);
        Logger.getLogger("dr.evomodel").warning("   WARNING: single root rate is not implemented!");
    }
    final boolean randomizeRates = xo.getAttribute(RANDOMIZE_RATES, true);
    final boolean keepRates = xo.getAttribute(KEEP_RATES, false);
    final boolean cachedRates = xo.getAttribute(CACHED_RATES, false);
    if (randomizeRates && keepRates) {
        throw new XMLParseException("Unable to both randomize and keep current rate categories");
    }
    return new DiscretizedBranchRates(tree, rateCategoryParameter, distributionModel, overSampling, normalize, normalizeBranchRateTo, randomizeRates, keepRates, cachedRates);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) DiscretizedBranchRates(dr.evomodel.branchratemodel.DiscretizedBranchRates) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) Parameter(dr.inference.model.Parameter)

Example 17 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class MixtureModelBranchRatesParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    ArrayList<ParametricDistributionModel> modelsList = new ArrayList<ParametricDistributionModel>();
    final boolean normalize = xo.getAttribute(NORMALIZE, false);
    final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_BRANCH_RATE_TO, Double.NaN);
    final boolean useQuantilesForRates = xo.getAttribute(USE_QUANTILE, true);
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof XMLObject) {
            if (((XMLObject) child).getName().equals(DISTRIBUTION)) {
                XMLObject childXML = (XMLObject) child;
                modelsList.add((ParametricDistributionModel) childXML.getChild(0));
            }
        }
    }
    //Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES);
    ParametricDistributionModel[] models = modelsList.toArray(new ParametricDistributionModel[modelsList.size()]);
    Parameter rateCategoryQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORY_QUANTILES);
    Parameter distributionIndexParameter = (Parameter) xo.getElementFirstChild(DISTRIBUTION_INDEX);
    Logger.getLogger("dr.evomodel").info("Using random discretized relaxed clock model with a mixture distribution.");
    for (int i = 0; i < models.length; i++) {
        Logger.getLogger("dr.evomodel").info("  parametric model " + (i + 1) + " = " + models[i].getModelName());
    }
    //Logger.getLogger("dr.evomodel").info("   rate categories = " + rateCategoryParameter.getDimension());
    Logger.getLogger("dr.evomodel").info("   rate categories = " + rateCategoryQuantilesParameter.getDimension());
    if (normalize) {
        Logger.getLogger("dr.evomodel").info("   mean rate is normalized to " + normalizeBranchRateTo);
    }
    if (xo.hasAttribute(SINGLE_ROOT_RATE)) {
        //singleRootRate = xo.getBooleanAttribute(SINGLE_ROOT_RATE);
        Logger.getLogger("dr.evomodel").warning("   WARNING: single root rate is not implemented!");
    }
    if (!useQuantilesForRates) {
        Logger.getLogger("dr.evomodel").info("Rates are set to not being drawn using quantiles. Thus they are not drawn from any particular distribution.");
    }
    return new MixtureModelBranchRates(tree, rateCategoryQuantilesParameter, models, distributionIndexParameter, useQuantilesForRates, normalize, normalizeBranchRateTo);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) MixtureModelBranchRates(dr.evomodel.branchratemodel.MixtureModelBranchRates) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) ArrayList(java.util.ArrayList) Parameter(dr.inference.model.Parameter)

Example 18 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class SpeciesTreeSimplePriorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    SpeciesTreeModel st = (SpeciesTreeModel) xo.getChild(SpeciesTreeModel.class);
    //ParametricDistributionModel pr = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class);
    Parameter pr = (Parameter) ((XMLObject) xo.getChild("sigma")).getChild(Parameter.class);
    final XMLObject cxo = xo.getChild(TIPS);
    final ParametricDistributionModel tipsPrior = (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
    return new SpeciesTreeSimplePrior(st, pr, tipsPrior);
}
Also used : ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) Parameter(dr.inference.model.Parameter) SpeciesTreeModel(dr.evomodel.speciation.SpeciesTreeModel) SpeciesTreeSimplePrior(dr.evomodel.speciation.SpeciesTreeSimplePrior)

Example 19 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class SpeciesTreeBMPriorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final SpeciesTreeModel st = (SpeciesTreeModel) xo.getChild(SpeciesTreeModel.class);
    //ParametricDistributionModel pr = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class);
    final Object child = xo.getChild(SIGMA);
    Parameter popSigma = child != null ? (Parameter) ((XMLObject) child).getChild(Parameter.class) : null;
    Parameter stSigma = (Parameter) ((XMLObject) xo.getChild(STSIGMA)).getChild(Parameter.class);
    final XMLObject cxo = (XMLObject) xo.getChild(TIPS);
    final ParametricDistributionModel tipsPrior = (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
    final boolean logRoot = xo.getAttribute(LOG_ROOT, false);
    return new SpeciesTreeBMPrior(st, popSigma, stSigma, tipsPrior, logRoot);
}
Also used : ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) SpeciesTreeBMPrior(dr.evomodel.speciation.SpeciesTreeBMPrior) Parameter(dr.inference.model.Parameter) SpeciesTreeModel(dr.evomodel.speciation.SpeciesTreeModel)

Example 20 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class DistributionLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final XMLObject cxo = xo.getChild(DISTRIBUTION);
    ParametricDistributionModel model = (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
    DistributionLikelihood likelihood = new DistributionLikelihood(model);
    XMLObject cxo1 = xo.getChild(DATA);
    final int from = cxo1.getAttribute(FROM, -1);
    int to = cxo1.getAttribute(TO, -1);
    if (from >= 0 || to >= 0) {
        if (to < 0) {
            to = Integer.MAX_VALUE;
        }
        if (!(from >= 0 && to >= 0 && from < to)) {
            throw new XMLParseException("ill formed from-to");
        }
        likelihood.setRange(from, to);
    }
    for (int j = 0; j < cxo1.getChildCount(); j++) {
        if (cxo1.getChild(j) instanceof Statistic) {
            likelihood.addData((Statistic) cxo1.getChild(j));
        } else {
            throw new XMLParseException("illegal element in " + cxo1.getName() + " element");
        }
    }
    return likelihood;
}
Also used : Statistic(dr.inference.model.Statistic) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood)

Aggregations

ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)21 Parameter (dr.inference.model.Parameter)16 ArrayList (java.util.ArrayList)4 TreeModel (dr.evomodel.tree.TreeModel)3 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)3 DiscretizedBranchRates (dr.evomodel.branchratemodel.DiscretizedBranchRates)2 VariableDemographicModel (dr.evomodel.coalescent.VariableDemographicModel)2 SpeciesTreeModel (dr.evomodel.speciation.SpeciesTreeModel)2 NormalDistributionModel (dr.inference.distribution.NormalDistributionModel)2 CompoundParameter (dr.inference.model.CompoundParameter)2 Statistic (dr.inference.model.Statistic)2 Attribute (dr.util.Attribute)2 SimpleTree (dr.evolution.tree.SimpleTree)1 Tree (dr.evolution.tree.Tree)1 Taxa (dr.evolution.util.Taxa)1 Taxon (dr.evolution.util.Taxon)1 TaxonList (dr.evolution.util.TaxonList)1 Units (dr.evolution.util.Units)1 AlloppNetworkPriorModel (dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1