Debian Codegraph @

src/dr/evomodelxml/coalescent/operators/GMRFSkyrideFixedEffectsGibbsOperatorParser.java

raw symbols SCIP
1 /*
2 * GMRFSkyrideFixedEffectsGibbsOperatorParser.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.evomodelxml.coalescent.operators;
27
28 import dr.evomodel.coalescent.GMRFSkyrideLikelihood;
29 import dr.evomodel.coalescent.operators.GMRFSkyrideFixedEffectsGibbsOperator;
30 import dr.inference.distribution.MultivariateDistributionLikelihood;
31 import dr.inference.model.Parameter;
32 import dr.inference.operators.MCMCOperator;
33 import dr.math.distributions.MultivariateDistribution;
34 import dr.math.distributions.MultivariateNormalDistribution;
35 import dr.xml.*;
36
37 /**
38 *
39 */
40 public class GMRFSkyrideFixedEffectsGibbsOperatorParser extends AbstractXMLObjectParser {
41
42 public static final String GMRF_GIBBS_OPERATOR = "gmrfFixedEffectsGibbsOperator";
43
44 public String getParserName() {
45 return GMRF_GIBBS_OPERATOR;
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50
51 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
52
53 GMRFSkyrideLikelihood gmrfLikelihood = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.class);
54
55 MultivariateDistributionLikelihood likelihood =
56 (MultivariateDistributionLikelihood) xo.getChild(MultivariateDistributionLikelihood.class);
57
58 MultivariateDistribution prior = likelihood.getDistribution();
59
60 if (prior.getType().compareTo(MultivariateNormalDistribution.TYPE) != 0)
61 throw new XMLParseException("Only a multivariate normal distribution is conjugate for the regression coefficients in a GMRF");
62
63 Parameter param = (Parameter) xo.getChild(Parameter.class);
64
65 return new GMRFSkyrideFixedEffectsGibbsOperator(param,
66 gmrfLikelihood, prior, weight);
67
68 }
69
70 //************************************************************************
71 // AbstractXMLObjectParser implementation
72 //************************************************************************
73
74 public String getParserDescription() {
75 return "This element returns a Gibbs operator for regression coefficients in a GMRF.";
76 }
77
78 public Class getReturnType() {
79 return GMRFSkyrideFixedEffectsGibbsOperator.class;
80 }
81
82 public XMLSyntaxRule[] getSyntaxRules() {
83 return rules;
84 // return null;
85 }
86
87 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
88 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
89 new ElementRule(MultivariateDistributionLikelihood.class),
90 new ElementRule(Parameter.class),
91 new ElementRule(GMRFSkyrideLikelihood.class)
92 };
93 }