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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations