Debian Codegraph @

src/dr/evomodel/treedatalikelihood/continuous/ConjugateRootTraitPrior.java

raw symbols SCIP
1 /*
2 * ConjugateRootTraitPrior.java
3 *
4 * Copyright (c) 2002-2016 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.evomodel.treedatalikelihood.continuous;
27
28 import dr.evomodel.continuous.AbstractMultivariateTraitLikelihood;
29 import dr.inference.distribution.MultivariateDistributionLikelihood;
30 import dr.inference.model.Parameter;
31 import dr.xml.ElementRule;
32 import dr.xml.XMLObject;
33 import dr.xml.XMLParseException;
34 import dr.xml.XMLSyntaxRule;
35
36 import static dr.evomodelxml.treedatalikelihood.ContinuousDataLikelihoodParser.CONJUGATE_ROOT_PRIOR;
37
38 /**
39 * @author Marc A. Suchard
40 */
41 public class ConjugateRootTraitPrior {
42
43
44 private static final String PRIOR_SAMPLE_SIZE = AbstractMultivariateTraitLikelihood.PRIOR_SAMPLE_SIZE;
45
46 private final double[] mean;
47 private final double pseudoObservations;
48
49 private ConjugateRootTraitPrior(double[] mean, double pseudoObservations) {
50 this.mean = mean;
51 this.pseudoObservations = pseudoObservations;
52 }
53
54 public double[] getMean() { return mean; }
55 public double getPseudoObservations() { return pseudoObservations; }
56
57 public static ConjugateRootTraitPrior parseConjugateRootTraitPrior(XMLObject xo,
58 final int dim) throws XMLParseException {
59
60 XMLObject cxo = xo.getChild(CONJUGATE_ROOT_PRIOR);
61
62 Parameter meanParameter = (Parameter) cxo.getChild(MultivariateDistributionLikelihood.MVN_MEAN)
63 .getChild(Parameter.class);
64
65 if (meanParameter.getDimension() != dim) {
66 throw new XMLParseException("Root prior mean dimension (" + meanParameter.getDimension() +
67 ") does not match trait diffusion dimension (" + dim + ")");
68 }
69
70 Parameter sampleSizeParameter = (Parameter) cxo.getChild(PRIOR_SAMPLE_SIZE).getChild(Parameter.class);
71
72 return new ConjugateRootTraitPrior(meanParameter.getParameterValues(),
73 sampleSizeParameter.getParameterValue(0));
74 }
75
76 public static final XMLSyntaxRule[] rules = {
77 new ElementRule(MultivariateDistributionLikelihood.MVN_MEAN,
78 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
79 new ElementRule(PRIOR_SAMPLE_SIZE,
80 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
81 };
82 }