Debian Codegraph @

src/dr/evomodel/epidemiology/casetocase/periodpriors/OneOverStDevPeriodPriorDistribution.java

raw symbols SCIP
1 /*
2 * OneOverStDevPeriodPriorDistribution.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.evomodel.epidemiology.casetocase.periodpriors;
27
28 import dr.xml.*;
29 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
30
31 /**
32 * This is effectively the Jeffreys prior on the set of periods assuming that they are normally (or lognormally)
33 * distributed; the probability is proportional to the reciprocal of their standard deviation (or the standard deviation
34 * of their logarithms).
35 */
36 public class OneOverStDevPeriodPriorDistribution extends AbstractPeriodPriorDistribution {
37
38 public static final String ONE_OVER_STDEV = "oneOverStDevPeriodPriorDistribution";
39 public static final String LOG = "log";
40 public static final String ID = "id";
41
42 public OneOverStDevPeriodPriorDistribution(String name, boolean log){
43 super(name, log);
44 }
45
46 @Override
47 public void reset() {
48
49 }
50
51 @Override
52 public double calculateLogPosteriorProbability(double newValue, double minValue) {
53 return 0;
54 }
55
56 @Override
57 public double calculateLogPosteriorCDF(double limit, boolean upper) {
58 return 0;
59 }
60
61 public double calculateLogLikelihood(double[] values){
62
63 DescriptiveStatistics stats = new DescriptiveStatistics(values);
64
65 logL = -Math.log(stats.getStandardDeviation());
66
67 return logL;
68
69 }
70
71 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
72
73 public String getParserName() {
74 return ONE_OVER_STDEV;
75 }
76
77 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
78 String id = (String) xo.getAttribute(ID);
79
80 boolean log;
81 log = xo.hasAttribute(LOG) ? xo.getBooleanAttribute(LOG) : false;
82
83 return new OneOverStDevPeriodPriorDistribution(id, log);
84
85 }
86
87 public XMLSyntaxRule[] getSyntaxRules() {
88 return rules;
89 }
90
91 private final XMLSyntaxRule[] rules = {
92 AttributeRule.newBooleanRule(LOG, true),
93 AttributeRule.newStringRule(ID, false)
94 };
95
96 public String getParserDescription() {
97 return "Calculates the probability of observing a list of doubles with probability proportional to" +
98 "1 over their standard deviation (the Jeffreys prior for normally distributed data)";
99 }
100
101 public Class getReturnType() {
102 return OneOverStDevPeriodPriorDistribution.class;
103 }
104 };
105
106 }