| 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.inference.distribution; |
| 27 |
|
| 28 |
import dr.inference.model.AbstractModelLikelihood; |
| 29 |
import dr.inference.model.Model; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.model.Variable; |
| 32 |
import dr.math.distributions.GammaDistribution; |
| 33 |
import org.w3c.dom.Document; |
| 34 |
import org.w3c.dom.Element; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public class ExponentialMarkovModel extends AbstractModelLikelihood { |
| 46 |
|
| 47 |
public static final String EXPONENTIAL_MARKOV_MODEL = "exponentialMarkovLikelihood"; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public ExponentialMarkovModel(Parameter chainParameter, boolean jeffreys, boolean reverse, double shape) { |
| 53 |
|
| 54 |
super(EXPONENTIAL_MARKOV_MODEL); |
| 55 |
|
| 56 |
this.chainParameter = chainParameter; |
| 57 |
this.jeffreys = jeffreys; |
| 58 |
this.reverse = reverse; |
| 59 |
this.shape = shape; |
| 60 |
|
| 61 |
addVariable(chainParameter); |
| 62 |
chainParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, chainParameter.getDimension())); |
| 63 |
} |
| 64 |
|
| 65 |
public Parameter getChainParameter() { |
| 66 |
return (Parameter)getVariable(0); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
protected void storeState() { |
| 82 |
} |
| 83 |
|
| 84 |
protected void restoreState() { |
| 85 |
} |
| 86 |
|
| 87 |
protected void acceptState() { |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public Element createElement(Document document) { |
| 95 |
throw new RuntimeException("Not implemented!"); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public Model getModel() { |
| 108 |
return this; |
| 109 |
} |
| 110 |
|
| 111 |
private int index(int i) { |
| 112 |
if (reverse) |
| 113 |
return chainParameter.getDimension() - i - 1; |
| 114 |
else |
| 115 |
return i; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public double getLogLikelihood() { |
| 124 |
|
| 125 |
double logL = 0.0; |
| 126 |
|
| 127 |
if (jeffreys) { |
| 128 |
logL += -Math.log(chainParameter.getParameterValue(index(0))); |
| 129 |
} |
| 130 |
for (int i = 1; i < chainParameter.getDimension(); i++) { |
| 131 |
final double mean = chainParameter.getParameterValue(index(i - 1)); |
| 132 |
final double x = chainParameter.getParameterValue(index(i)); |
| 133 |
|
| 134 |
|
| 135 |
final double scale = mean / shape; |
| 136 |
logL += GammaDistribution.logPdf(x, shape, scale); |
| 137 |
} |
| 138 |
return logL; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public void makeDirty() { |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
private String id = null; |
| 152 |
|
| 153 |
public void setId(String id) { |
| 154 |
this.id = id; |
| 155 |
} |
| 156 |
|
| 157 |
public String getId() { |
| 158 |
return id; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
private Parameter chainParameter = null; |
| 166 |
private boolean jeffreys = false; |
| 167 |
private boolean reverse = false; |
| 168 |
private double shape = 1.0; |
| 169 |
|
| 170 |
} |
| 171 |
|