| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inferencexml.distribution; |
| 27 |
|
| 28 |
import dr.inference.distribution.MultivariateDistributionLikelihood; |
| 29 |
import dr.inference.distribution.MultivariateNormalDistributionModel; |
| 30 |
import dr.inference.model.MatrixParameter; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class MultivariateNormalDistributionModelParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String NORMAL_DISTRIBUTION_MODEL = "multivariateNormalDistributionModel"; |
| 40 |
|
| 41 |
public String getParserName() { |
| 42 |
return NORMAL_DISTRIBUTION_MODEL; |
| 43 |
} |
| 44 |
|
| 45 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 46 |
|
| 47 |
XMLObject cxo = xo.getChild(MultivariateDistributionLikelihood.MVN_MEAN); |
| 48 |
Parameter mean = (Parameter) cxo.getChild(Parameter.class); |
| 49 |
|
| 50 |
cxo = xo.getChild(MultivariateDistributionLikelihood.MVN_PRECISION); |
| 51 |
MatrixParameter precision = (MatrixParameter) cxo.getChild(MatrixParameter.class); |
| 52 |
|
| 53 |
if (mean.getDimension() != precision.getRowDimension() || |
| 54 |
mean.getDimension() != precision.getColumnDimension()) |
| 55 |
throw new XMLParseException("Mean and precision have wrong dimensions in " + xo.getName() + " element"); |
| 56 |
|
| 57 |
return new MultivariateNormalDistributionModel(mean, precision); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 65 |
return rules; |
| 66 |
} |
| 67 |
|
| 68 |
private final XMLSyntaxRule[] rules = { |
| 69 |
new ElementRule(MultivariateDistributionLikelihood.MVN_MEAN, |
| 70 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 71 |
new ElementRule(MultivariateDistributionLikelihood.MVN_PRECISION, |
| 72 |
new XMLSyntaxRule[]{new ElementRule(MatrixParameter.class)}), |
| 73 |
}; |
| 74 |
|
| 75 |
public String getParserDescription() { |
| 76 |
return "Describes a normal distribution with a given mean and precision " + |
| 77 |
"that can be used in a distributionLikelihood element"; |
| 78 |
} |
| 79 |
|
| 80 |
public Class getReturnType() { |
| 81 |
return MultivariateNormalDistributionModel.class; |
| 82 |
} |
| 83 |
|
| 84 |
} |