Debian Codegraph @

src/dr/inferencexml/operators/MVOUCovarianceOperatorParser.java

raw symbols SCIP
1 /*
2 * MVOUCovarianceOperatorParser.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.operators;
27
28 import dr.inference.model.MatrixParameter;
29 import dr.inference.operators.AdaptableMCMCOperator;
30 import dr.inference.operators.AdaptationMode;
31 import dr.inference.operators.MCMCOperator;
32 import dr.inference.operators.MVOUCovarianceOperator;
33 import dr.xml.*;
34
35 /**
36 *
37 */
38 public class MVOUCovarianceOperatorParser extends AbstractXMLObjectParser {
39
40 public static final String MVOU_OPERATOR = "mvouOperator";
41 public static final String MIXING_FACTOR = "mixingFactor";
42 public static final String VARIANCE_MATRIX = "varMatrix";
43 public static final String PRIOR_DF = "priorDf";
44
45 public String getParserName() {
46 return MVOU_OPERATOR;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 AdaptationMode mode = AdaptationMode.parseMode(xo);
52 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
53 double mixingFactor = xo.getDoubleAttribute(MIXING_FACTOR);
54 int priorDf = xo.getIntegerAttribute(PRIOR_DF);
55
56 if (mixingFactor <= 0.0 || mixingFactor >= 1.0) {
57 throw new XMLParseException("mixingFactor must be greater than 0.0 and less thatn 1.0");
58 }
59
60 // Parameter parameter = (Parameter) xo.getChild(Parameter.class);
61
62 // XMLObject cxo = (XMLObject) xo.getChild(VARIANCE_MATRIX);
63 MatrixParameter varMatrix = (MatrixParameter) xo.getChild(MatrixParameter.class);
64
65 // Make sure varMatrix is square and dim(varMatrix) = dim(parameter)
66
67 if (varMatrix.getColumnDimension() != varMatrix.getRowDimension())
68 throw new XMLParseException("The variance matrix is not square");
69
70 // if (varMatrix.getColumnDimension() != parameter.getDimension())
71 // throw new XMLParseException("The parameter and variance matrix have differing dimensions");
72
73 return new MVOUCovarianceOperator(mixingFactor, varMatrix, priorDf, weight, mode);
74 }
75
76 //************************************************************************
77 // AbstractXMLObjectParser implementation
78 //************************************************************************
79
80 public String getParserDescription() {
81 return "This element returns junk.";
82 }
83
84 public Class getReturnType() {
85 return MVOUCovarianceOperator.class;
86 }
87
88 public XMLSyntaxRule[] getSyntaxRules() {
89 return rules;
90 }
91
92 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
93 AttributeRule.newDoubleRule(MIXING_FACTOR),
94 AttributeRule.newIntegerRule(PRIOR_DF),
95 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
96 AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true),
97 // new ElementRule(Parameter.class),
98 // new ElementRule(VARIANCE_MATRIX,
99 // new XMLSyntaxRule[]{new ElementRule(MatrixParameter.class)}),
100
101 new ElementRule(MatrixParameter.class)
102
103 };
104
105 }