| 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.inference.loggers.LogColumn; |
| 29 |
import dr.inference.loggers.Loggable; |
| 30 |
import dr.inference.model.AbstractModel; |
| 31 |
import dr.inference.model.Model; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.inference.model.Variable; |
| 34 |
|
| 35 |
import java.util.ArrayList; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public abstract class AbstractPeriodPriorDistribution extends AbstractModel implements Loggable { |
| 44 |
|
| 45 |
|
| 46 |
protected boolean log; |
| 47 |
|
| 48 |
protected double logL; |
| 49 |
protected double storedLogL; |
| 50 |
|
| 51 |
public AbstractPeriodPriorDistribution(String name, boolean log) { |
| 52 |
super(name); |
| 53 |
this.log = log; |
| 54 |
} |
| 55 |
|
| 56 |
public double getLogLikelihood(double[] values){ |
| 57 |
if(!log){ |
| 58 |
return calculateLogLikelihood(values); |
| 59 |
} else { |
| 60 |
double[] logValues = new double[values.length]; |
| 61 |
for(int i=0; i<values.length; i++){ |
| 62 |
logValues[i] = Math.log(values[i]); |
| 63 |
} |
| 64 |
return calculateLogLikelihood(logValues); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
public double getLogPosteriorProbability(double newValue, double minValue){ |
| 69 |
if(!log){ |
| 70 |
return calculateLogPosteriorProbability(newValue, minValue); |
| 71 |
} else { |
| 72 |
return calculateLogPosteriorProbability(Math.log(newValue), Math.log(minValue)); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public double getLogPosteriorCDF(double limit, boolean upper){ |
| 77 |
if(!log){ |
| 78 |
return calculateLogPosteriorCDF(limit, upper); |
| 79 |
} else { |
| 80 |
return calculateLogPosteriorCDF(Math.log(limit), upper); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
protected void storeState() { |
| 93 |
storedLogL = logL; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
protected void restoreState() { |
| 98 |
logL = storedLogL; |
| 99 |
} |
| 100 |
|
| 101 |
protected void acceptState() { |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
public LogColumn[] getColumns() { |
| 107 |
ArrayList<LogColumn> columns = new ArrayList<LogColumn>(); |
| 108 |
|
| 109 |
columns.add(new LogColumn.Abstract(getModelName()+"_LL"){ |
| 110 |
protected String getFormattedValue() { |
| 111 |
return String.valueOf(logL); |
| 112 |
} |
| 113 |
}); |
| 114 |
return columns.toArray(new LogColumn[columns.size()]); |
| 115 |
} |
| 116 |
|
| 117 |
public abstract void reset(); |
| 118 |
|
| 119 |
public abstract double calculateLogPosteriorProbability(double newValue, double minValue); |
| 120 |
|
| 121 |
public abstract double calculateLogPosteriorCDF(double limit, boolean upper); |
| 122 |
|
| 123 |
public abstract double calculateLogLikelihood(double[] values); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
} |