Debian Codegraph @

src/dr/inferencexml/distribution/MultivariateNormalDistributionModelParser.java

raw symbols SCIP
1 /*
2 * MultivariateNormalDistributionModelParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * Reads a normal distribution model from a DOM Document element.
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 // AbstractXMLObjectParser implementation
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 }