| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 33 |
|
| 34 |
|
| 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 |
} |