Debian Codegraph @

src/dr/inferencexml/operators/LatentFactorModelPrecisionGibbsOperatorParser.java

raw symbols SCIP
1 /*
2 * LatentFactorModelPrecisionGibbsOperatorParser.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.distribution.DistributionLikelihood;
29 import dr.inference.model.LatentFactorModel;
30 import dr.inference.operators.LatentFactorModelPrecisionGibbsOperator;
31 import dr.xml.*;
32
33 /**
34 * Created by max on 6/12/14.
35 */
36 public class LatentFactorModelPrecisionGibbsOperatorParser extends AbstractXMLObjectParser {
37 public final String LATENT_FACTOR_MODEL_PRECISION_OPERATOR = "latentFactorModelPrecisionOperator";
38 public final String WEIGHT = "weight";
39 public final String RANDOM_SCAN = "randomScan";
40 public final String PATH_PARAMETER = "pathParameter";
41
42
43 @Override
44 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
45 String weightTemp = (String) xo.getAttribute(WEIGHT);
46 double weight = Double.parseDouble(weightTemp);
47 LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
48 DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
49 boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
50 LatentFactorModelPrecisionGibbsOperator lfmOp = new LatentFactorModelPrecisionGibbsOperator(LFM, prior, weight, randomScan);
51 if(xo.hasAttribute(PATH_PARAMETER)){
52 System.out.println("WARNING: Setting Path Parameter is intended for debugging purposes only!");
53 lfmOp.setPathParameter(xo.getDoubleAttribute(PATH_PARAMETER));
54 }
55
56 return lfmOp;
57
58
59 }
60
61 @Override
62 public XMLSyntaxRule[] getSyntaxRules() {
63 return rules;
64 }
65
66 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
67 new ElementRule(LatentFactorModel.class),
68 new ElementRule(DistributionLikelihood.class),
69 // new ElementRule(CompoundParameter.class),
70 AttributeRule.newDoubleRule(WEIGHT),
71 AttributeRule.newDoubleRule(PATH_PARAMETER, true),
72 };
73
74 @Override
75 public String getParserDescription() {
76 return "Gibbs sampler for the precision of a factor analysis model";
77 }
78
79 @Override
80 public Class getReturnType() {
81 return LatentFactorModelPrecisionGibbsOperator.class;
82 }
83
84 @Override
85 public String getParserName() {
86 return LATENT_FACTOR_MODEL_PRECISION_OPERATOR;
87 }
88 }