Debian Codegraph @

src/dr/inference/operators/hmc/deprecated/LoadingsHamiltonianMCParser.java

raw symbols SCIP
1 /*
2 * LoadingsHamiltonianMCParser.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.inference.operators.hmc.deprecated;
27
28 import dr.inference.operators.AdaptationMode;
29 import dr.inference.distribution.MomentDistributionModel;
30 import dr.inference.model.LatentFactorModel;
31 import dr.inference.model.MatrixParameter;
32 import dr.xml.*;
33
34 /**
35 * Created by max on 1/11/16.
36 */
37 @Deprecated
38 public class LoadingsHamiltonianMCParser extends AbstractXMLObjectParser {
39 public static final String LOADINGS_HAMILTONIAN_MC="loadingsHamiltonianMC";
40 public static final String WEIGHT="weight";
41 public static final String STEP_SIZE="stepSize";
42 public static final String N_STEPS="nSteps";
43 public static final String MOMENTUM_SD="momentumSd";
44
45 @Override
46 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
47
48 LatentFactorModel lfm=(LatentFactorModel) xo.getChild(LatentFactorModel.class);
49 MomentDistributionModel prior=(MomentDistributionModel) xo.getChild(MomentDistributionModel.class);
50 double weight=xo.getDoubleAttribute(WEIGHT);
51 AdaptationMode mode= AdaptationMode.parseMode(xo);
52 int nSteps=xo.getIntegerAttribute(N_STEPS);
53 double stepSize=xo.getDoubleAttribute(STEP_SIZE);
54 double momentumSd= xo.getDoubleAttribute(MOMENTUM_SD);
55 MatrixParameter loadings=(MatrixParameter) xo.getChild(MatrixParameter.class);
56
57 return new LoadingsHamiltonianMC(lfm, prior, weight, mode, stepSize, nSteps, momentumSd, loadings);
58 }
59
60 @Override
61 public XMLSyntaxRule[] getSyntaxRules() {
62 return rules;
63 }
64
65 private static final XMLSyntaxRule[] rules = {
66 AttributeRule.newDoubleRule(WEIGHT),
67 AttributeRule.newDoubleRule(STEP_SIZE),
68 AttributeRule.newIntegerRule(N_STEPS),
69 AttributeRule.newDoubleRule(MOMENTUM_SD),
70 new ElementRule(LatentFactorModel.class),
71 new ElementRule(MomentDistributionModel.class),
72 new ElementRule(MatrixParameter.class),
73 };
74
75
76 @Override
77 public String getParserDescription() {
78 return "Hamiltonian Monte Carlo for loadings matrix in a latent factor model";
79 }
80
81 @Override
82 public Class getReturnType() {
83 return LoadingsHamiltonianMC.class;
84 }
85
86 @Override
87 public String getParserName() {
88 return LOADINGS_HAMILTONIAN_MC;
89 }
90 }