use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.
the class MatrixMatrixProductParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
MatrixParameter[] temp = new MatrixParameter[3];
temp[0] = (MatrixParameter) xo.getChild(LEFT).getChild(MatrixParameter.class);
temp[1] = MatrixParameter.recast(((CompoundParameter) xo.getChild(RIGHT).getChild(CompoundParameter.class)).getVariableName(), (CompoundParameter) xo.getChild(RIGHT).getChild(CompoundParameter.class));
if (xo.getChild(IN_PLACE) != null) {
temp[2] = (MatrixParameter) xo.getChild(IN_PLACE).getChild(MatrixParameter.class);
} else {
int rowDim = temp[0].getRowDimension();
int colDim = temp[1].getColumnDimension();
Parameter[] params = new Parameter[colDim];
for (int i = 0; i < colDim; i++) {
params[i] = new Parameter.Default(rowDim);
}
temp[2] = new MatrixParameter(null, params);
}
Parameter ColumnMask;
if (xo.getChild(COLUMN_MASK) != null)
ColumnMask = (Parameter) xo.getChild(COLUMN_MASK).getChild(MatrixParameter.class);
else
ColumnMask = new Parameter.Default(null, temp[1].getColumnDimension(), 1);
return new MatrixMatrixProduct(temp, ColumnMask);
}
use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.
the class DirichletProcessPrior method testDirichletProcess.
// END: main
private static void testDirichletProcess(double[] mapping, int categoryCount, double gamma, double expectedLogL) {
Parameter categoriesParameter = new Parameter.Default(mapping);
Parameter gammaParameter = new Parameter.Default(gamma);
CompoundParameter dummy = new CompoundParameter("dummy");
for (int i = 0; i < categoryCount; i++) {
dummy.addParameter(new Parameter.Default(1.0));
}
DirichletProcessPrior dpp = new DirichletProcessPrior(categoriesParameter, dummy, null, gammaParameter);
dpp.setVerbose();
// int[] counts = dpp.getCounts();
System.out.println("lnL: " + dpp.getCategoriesLogDensity());
System.out.println("expected lnL: " + expectedLogL);
}
use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.
the class DirichletProcessOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
DirichletProcessPrior dpp = (DirichletProcessPrior) xo.getChild(DirichletProcessPrior.class);
Likelihood likelihood = (Likelihood) xo.getElementFirstChild(DATA_LOG_LIKELIHOOD);
Parameter categoriesParameter = (Parameter) xo.getElementFirstChild(DirichletProcessPriorParser.CATEGORIES);
CountableRealizationsParameter allParameters = (CountableRealizationsParameter) xo.getChild(CountableRealizationsParameter.class);
CompoundParameter uniquelyRealizedParameters = (CompoundParameter) xo.getChild(CompoundParameter.class);
int M = xo.getIntegerAttribute(MH_STEPS);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
return new //
DirichletProcessOperator(//
dpp, //
categoriesParameter, //
uniquelyRealizedParameters, //
allParameters, //
likelihood, //
M, //
weight);
}
use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.
the class DiscretizedLociRatesParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final boolean normalize = xo.getAttribute(NORMALIZE, false);
final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_MEAN_LOCI_RATE_TO, Double.NaN);
final int categoryCount = xo.getIntegerAttribute(CATEGORY_COUNT);
CompoundParameter lociRates = (CompoundParameter) xo.getElementFirstChild(LOCI_RATES);
Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES);
ParametricDistributionModel distributionModel = (ParametricDistributionModel) xo.getElementFirstChild(DISTRIBUTION);
Logger.getLogger("dr.evomodel").info("Using discretized loci rates model.");
Logger.getLogger("dr.evomodel").info("Number of categories: " + categoryCount);
Logger.getLogger("dr.evomodel").info(" parametric model = " + distributionModel.getModelName());
if (normalize) {
Logger.getLogger("dr.evomodel").info(" mean rate is normalized to " + normalizeBranchRateTo);
}
return new DiscretizedLociRates(lociRates, rateCategoryParameter, distributionModel, normalize, normalizeBranchRateTo, categoryCount);
}
use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.
the class EpochBranchModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Logger.getLogger("dr.evomodel").info("\nUsing multi-epoch branch model.");
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
SubstitutionModel ancestralSubstitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
List<Epoch> epochs = new ArrayList<Epoch>();
for (int i = 0; i < xo.getChildCount(); i++) {
if (xo.getChild(i) instanceof XMLObject) {
XMLObject xoc = (XMLObject) xo.getChild(i);
if (xoc.getName().equals(EPOCH)) {
Parameter tt = null;
if (xoc.hasAttribute(TRANSITION_TIME)) {
double t = xoc.getAttribute(TRANSITION_TIME, 0.0);
tt = new Parameter.Default(1, t);
}
SubstitutionModel s = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
if (xoc.hasChildNamed(TRANSITION_TIME)) {
if (tt != null) {
throw new XMLParseException("An epoch cannot have a transitionTime attribute and a parameter");
}
tt = (Parameter) xoc.getElementFirstChild(TRANSITION_TIME);
}
epochs.add(new Epoch(s, tt));
}
}
}
Collections.sort(epochs);
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
CompoundParameter transitionTimes = new CompoundParameter("epochTimes");
for (Epoch epoch : epochs) {
substitutionModels.add(epoch.substitutionModel);
transitionTimes.addParameter(epoch.timeParameter);
}
substitutionModels.add(ancestralSubstitutionModel);
return new EpochBranchModel(tree, substitutionModels, transitionTimes);
}
Aggregations