use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.
the class MixedDistributionLikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
XMLObject cxo0 = xo.getChild(DISTRIBUTION0);
ParametricDistributionModel model0 = (ParametricDistributionModel) cxo0.getChild(ParametricDistributionModel.class);
XMLObject cxo1 = xo.getChild(DISTRIBUTION1);
ParametricDistributionModel model1 = (ParametricDistributionModel) cxo1.getChild(ParametricDistributionModel.class);
Statistic data = (Statistic) ((XMLObject) xo.getChild(DATA)).getChild(Statistic.class);
Statistic indicators = (Statistic) ((XMLObject) xo.getChild(INDICATORS)).getChild(Statistic.class);
ParametricDistributionModel[] models = { model0, model1 };
try {
return new MixedDistributionLikelihood(models, data, indicators);
} catch (Exception e) {
throw new XMLParseException(e.getMessage());
}
}
use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.
the class PartitionData method createClockRateModel.
public BranchRateModel createClockRateModel() {
BranchRateModel branchRateModel = null;
if (this.clockModelIndex == 0) {
// Strict Clock
Parameter rateParameter = new Parameter.Default(1, clockParameterValues[0]);
branchRateModel = new StrictClockBranchRates(rateParameter);
} else if (this.clockModelIndex == LRC_INDEX) {
// Lognormal relaxed clock
double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
Parameter mean = new Parameter.Default(LogNormalDistributionModelParser.MEAN, 1, clockParameterValues[1]);
Parameter stdev = new Parameter.Default(LogNormalDistributionModelParser.STDEV, 1, clockParameterValues[2]);
//TODO: choose between log scale / real scale
ParametricDistributionModel distributionModel = new LogNormalDistributionModel(mean, stdev, clockParameterValues[3], lrcParametersInRealSpace, lrcParametersInRealSpace);
branchRateModel = new //
DiscretizedBranchRates(//
createTreeModel(), //
rateCategoryParameter, //
distributionModel, //
1, //
false, //
Double.NaN, //randomizeRates
true, // keepRates
false, // cacheRates
false);
} else if (this.clockModelIndex == 2) {
// Exponential relaxed clock
double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
Parameter mean = new Parameter.Default(DistributionModelParser.MEAN, 1, clockParameterValues[4]);
ParametricDistributionModel distributionModel = new ExponentialDistributionModel(mean, clockParameterValues[5]);
// branchRateModel = new DiscretizedBranchRates(createTreeModel(), rateCategoryParameter,
// distributionModel, 1, false, Double.NaN);
branchRateModel = new //
DiscretizedBranchRates(//
createTreeModel(), //
rateCategoryParameter, //
distributionModel, //
1, //
false, //
Double.NaN, //randomizeRates
true, // keepRates
false, // cacheRates
false);
} else if (this.clockModelIndex == 3) {
// Inverse Gaussian
double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
Parameter mean = new Parameter.Default(InverseGaussianDistributionModelParser.MEAN, 1, clockParameterValues[6]);
Parameter stdev = new Parameter.Default(InverseGaussianDistributionModelParser.STDEV, 1, clockParameterValues[7]);
ParametricDistributionModel distributionModel = new InverseGaussianDistributionModel(mean, stdev, clockParameterValues[8], false);
branchRateModel = new //
DiscretizedBranchRates(//
createTreeModel(), //
rateCategoryParameter, //
distributionModel, //
1, //
false, //
Double.NaN, //randomizeRates
true, // keepRates
false, // cacheRates
false);
} else {
System.out.println("Not yet implemented");
}
return branchRateModel;
}
use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.
the class AlloppNetworkPriorModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
final XMLObject erXo = xo.getChild(EVENTRATE);
final Parameter eventrate = (Parameter) erXo.getChild(Parameter.class);
final XMLObject psfXo = xo.getChild(POPULATION_SCALING_FACTOR);
final Parameter popscalingfactor = (Parameter) psfXo.getChild(Parameter.class);
final XMLObject tpdXo = xo.getChild(TIP_POPULATION_DISTRIBUTION);
ParametricDistributionModel tippopmodel = (ParametricDistributionModel) tpdXo.getChild(ParametricDistributionModel.class);
final XMLObject rpdXo = xo.getChild(ROOT_POPULATION_DISTRIBUTION);
ParametricDistributionModel rootpopmodel = (ParametricDistributionModel) rpdXo.getChild(ParametricDistributionModel.class);
final XMLObject hpdXo = xo.getChild(HYBRID_POPULATION_DISTRIBUTION);
ParametricDistributionModel hybpopmodel = (ParametricDistributionModel) hpdXo.getChild(ParametricDistributionModel.class);
return new AlloppNetworkPriorModel(eventrate, popscalingfactor, tippopmodel, rootpopmodel, hybpopmodel, units);
}
use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.
the class AlloppNetworkPrior method calculateLogLikelihood.
@Override
protected double calculateLogLikelihood() {
double llhood = 0.0;
//network topology and times prior
llhood += loglikelihoodEvents();
//System.out.print(llhood); System.out.print(" ");
llhood += loglikeNumHybridizations();
//System.out.print(llhood); System.out.print(" ");
// population prior for tips
Parameter tippvals = asnm.getTipPopValues();
ParametricDistributionModel tipmodel = prior.getTipPopModel();
for (int i = 0; i < tippvals.getDimension(); i++) {
llhood += tipmodel.logPdf(tippvals.getParameterValue(i));
}
// population prior for root ends
Parameter rootpvals = asnm.getRootPopValues();
ParametricDistributionModel rootmodel = prior.getRootPopModel();
for (int i = 0; i < rootpvals.getDimension(); i++) {
llhood += rootmodel.logPdf(rootpvals.getParameterValue(i));
}
// population prior for new hybrids
ParametricDistributionModel hybmodel = prior.getHybridPopModel();
for (int i = 0; i < asnm.getNumberOfTetraTrees(); i++) {
llhood += hybmodel.logPdf(asnm.getOneHybPopValue(i));
}
//System.out.println(llhood);
return llhood;
}
use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.
the class ContinuousBranchRatesParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final boolean normalize = xo.getAttribute(NORMALIZE, false);
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 rateQuantilesParameter;
if (xo.hasChildNamed(RATE_QUANTILES)) {
rateQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_QUANTILES);
} else {
rateQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORY_QUANTILES);
}
Logger.getLogger("dr.evomodel").info("Using continuous relaxed clock model.");
Logger.getLogger("dr.evomodel").info(" parametric model = " + distributionModel.getModelName());
Logger.getLogger("dr.evomodel").info(" rate categories = " + rateQuantilesParameter.getDimension());
if (normalize) {
Logger.getLogger("dr.evomodel").info(" mean rate is normalized to " + normalizeBranchRateTo);
}
if (xo.hasAttribute(SINGLE_ROOT_RATE)) {
Logger.getLogger("dr.evomodel").warning(" WARNING: single root rate is not implemented!");
}
return new ContinuousBranchRates(tree, rateQuantilesParameter, distributionModel, normalize, normalizeBranchRateTo);
}
Aggregations