Debian Codegraph @

src/dr/inferencexml/hmc/MaskedGradientParser.java

raw symbols SCIP
1 /*
2 * MaskedGradientParser.java
3 *
4 * Copyright (c) 2002-2017 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.hmc;
27
28 import dr.inference.hmc.GradientWrtParameterProvider;
29 import dr.inference.hmc.MaskedGradient;
30 import dr.inference.model.Parameter;
31 import dr.inferencexml.model.MaskedParameterParser;
32 import dr.xml.*;
33
34 /**
35 * @author Marc A. Suchard
36 */
37 public class MaskedGradientParser extends AbstractXMLObjectParser {
38
39 public final static String MASKED_GRADIENT = "maskedGradient";
40
41 @Override
42 public String getParserName() {
43 return MASKED_GRADIENT;
44 }
45
46 @Override
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48
49 GradientWrtParameterProvider gradient = (GradientWrtParameterProvider)
50 xo.getChild(GradientWrtParameterProvider.class);
51 Parameter mask = (Parameter) xo.getElementFirstChild(MaskedParameterParser.MASKING);
52
53 if (gradient.getDimension() != mask.getDimension()) {
54 throw new XMLParseException("Unmatched dimensions");
55 }
56
57 return new MaskedGradient(gradient, mask);
58 }
59
60 @Override
61 public XMLSyntaxRule[] getSyntaxRules() {
62 return rules;
63 }
64
65 private final XMLSyntaxRule[] rules = {
66 new ElementRule(GradientWrtParameterProvider.class),
67 new ElementRule(MaskedParameterParser.MASKING,
68 new XMLSyntaxRule[]{
69 new ElementRule(Parameter.class)
70 }),
71 };
72
73 @Override
74 public String getParserDescription() {
75 return null;
76 }
77
78 @Override
79 public Class getReturnType() {
80 return MaskedGradient.class;
81 }
82 }