use of dr.inference.model.MatrixParameter in project beast-mcmc by beast-dev.
the class DataFromTreeTipsParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeTraitParserUtilities utilities = new TreeTraitParserUtilities();
String traitName = (String) xo.getAttribute(TreeTraitParserUtilities.TRAIT_NAME);
MultivariateTraitTree treeModel = (MultivariateTraitTree) xo.getChild(MultivariateTraitTree.class);
TreeTraitParserUtilities.TraitsAndMissingIndices returnValue = utilities.parseTraitsFromTaxonAttributes(xo, traitName, treeModel, true);
MatrixParameter dataParameter = MatrixParameter.recast(returnValue.traitParameter.getId(), returnValue.traitParameter);
if (xo.hasChildNamed(TreeTraitParserUtilities.MISSING)) {
Parameter missing = (Parameter) xo.getChild(TreeTraitParserUtilities.MISSING).getChild(Parameter.class);
missing.setDimension(dataParameter.getDimension());
for (int i = 0; i < missing.getDimension(); i++) {
if (returnValue.missingIndices.contains(i)) {
missing.setParameterValue(i, 1);
} else {
missing.setParameterValue(i, 0);
}
}
}
return dataParameter;
}
use of dr.inference.model.MatrixParameter in project beast-mcmc by beast-dev.
the class MultivariateNormalDistributionModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
XMLObject cxo = xo.getChild(MultivariateDistributionLikelihood.MVN_MEAN);
Parameter mean = (Parameter) cxo.getChild(Parameter.class);
cxo = xo.getChild(MultivariateDistributionLikelihood.MVN_PRECISION);
MatrixParameter precision = (MatrixParameter) cxo.getChild(MatrixParameter.class);
if (mean.getDimension() != precision.getRowDimension() || mean.getDimension() != precision.getColumnDimension())
throw new XMLParseException("Mean and precision have wrong dimensions in " + xo.getName() + " element");
return new MultivariateNormalDistributionModel(mean, precision);
}
use of dr.inference.model.MatrixParameter in project beast-mcmc by beast-dev.
the class MultivariateOUModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
Parameter effectParameter = (Parameter) ((XMLObject) xo.getChild(DATA)).getChild(Parameter.class);
Parameter timesParameter = (Parameter) ((XMLObject) xo.getChild(TIME)).getChild(Parameter.class);
Parameter designParameter = (Parameter) ((XMLObject) xo.getChild(DESIGN)).getChild(Parameter.class);
MatrixParameter gammaParameter = (MatrixParameter) xo.getChild(MatrixParameter.class);
if (effectParameter.getDimension() != timesParameter.getDimension() || effectParameter.getDimension() != designParameter.getDimension()) {
// System.err.println("dim(design) "+designParameter.getDimension());
throw new XMLParseException("dim(" + effectParameter.getStatisticName() + ") != dim(" + timesParameter.getStatisticName() + ") != dim(" + designParameter.getStatisticName() + ") in " + xo.getName() + " element");
}
MultivariateOUModel glm = new MultivariateOUModel(substitutionModel, effectParameter, gammaParameter, timesParameter.getParameterValues(), designParameter.getParameterValues());
addIndependentParameters(xo, glm, effectParameter);
return glm;
}
use of dr.inference.model.MatrixParameter 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.MatrixParameter in project beast-mcmc by beast-dev.
the class Tree_Clustering_Shared_Routines method setMembershipTreeToVirusIndexes.
public static int[] setMembershipTreeToVirusIndexes(int numdata, MatrixParameter virusLocations, int numNodes, TreeModel treeModel) {
//I suspect this is an expensive operation, so I don't want to do it many times,
//which is also unnecessary - MAY have to update whenever a different tree is used.
int[] correspondingTreeIndexForVirus = new int[numdata];
for (int i = 0; i < numdata; i++) {
Parameter v = virusLocations.getParameter(i);
String curName = v.getParameterName();
// System.out.println(curName);
int isFound = 0;
for (int j = 0; j < numNodes; j++) {
String treeId = treeModel.getTaxonId(j);
if (curName.equals(treeId)) {
// System.out.println(" isFound at j=" + j);
correspondingTreeIndexForVirus[i] = j;
isFound = 1;
break;
}
}
if (isFound == 0) {
System.out.println("not found. Exit now.");
System.exit(0);
}
}
return (correspondingTreeIndexForVirus);
}
Aggregations