use of dr.evomodel.branchratemodel.DiscretizedBranchRates 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.evomodel.branchratemodel.DiscretizedBranchRates 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);
}
Aggregations