| 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.AbstractModel; |
| 29 |
import dr.inference.model.Model; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.model.Variable; |
| 32 |
import dr.math.UnivariateFunction; |
| 33 |
import dr.math.distributions.NormalDistribution; |
| 34 |
import org.w3c.dom.Document; |
| 35 |
import org.w3c.dom.Element; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class SkewNormalDistributionModel extends AbstractModel implements ParametricDistributionModel { |
| 44 |
|
| 45 |
public static final String SKEW_NORMAL_DISTRIBUTION_MODEL = "skewNormalDistributionModel"; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public SkewNormalDistributionModel(Variable<Double> location, Variable<Double> scale, Variable<Double> shape) { |
| 51 |
|
| 52 |
super(SKEW_NORMAL_DISTRIBUTION_MODEL); |
| 53 |
|
| 54 |
this.location = location; |
| 55 |
this.scale = scale; |
| 56 |
this.shape = shape; |
| 57 |
|
| 58 |
addVariable(location); |
| 59 |
location.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1)); |
| 60 |
addVariable(scale); |
| 61 |
scale.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 62 |
addVariable(shape); |
| 63 |
shape.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1)); |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
private double shift(double x) { |
| 68 |
return (x - location.getValue(0)) / scale.getValue(0); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public double pdf(double x) { |
| 77 |
double delta = shift(x); |
| 78 |
return 2.0 / scale.getValue(0) * NormalDistribution.pdf(delta, 0, 1) * NormalDistribution.cdf(shape.getValue(0) * delta, 0, 1); |
| 79 |
} |
| 80 |
|
| 81 |
public double logPdf(double x) { |
| 82 |
return Math.log(pdf(x)); |
| 83 |
} |
| 84 |
|
| 85 |
public double cdf(double x) { |
| 86 |
throw new IllegalArgumentException("Not yet implement"); |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
public double quantile(double y) { |
| 91 |
throw new IllegalArgumentException("Not yet implement"); |
| 92 |
} |
| 93 |
|
| 94 |
public double mean() { |
| 95 |
throw new IllegalArgumentException("Not yet implement"); |
| 96 |
} |
| 97 |
|
| 98 |
public double variance() { |
| 99 |
throw new IllegalArgumentException("Not yet implement"); |
| 100 |
} |
| 101 |
|
| 102 |
public final UnivariateFunction getProbabilityDensityFunction() { |
| 103 |
return pdfFunction; |
| 104 |
} |
| 105 |
|
| 106 |
private final UnivariateFunction pdfFunction = new UnivariateFunction() { |
| 107 |
public final double evaluate(double x) { |
| 108 |
return pdf(x); |
| 109 |
} |
| 110 |
|
| 111 |
public final double getLowerBound() { |
| 112 |
return Double.NEGATIVE_INFINITY; |
| 113 |
} |
| 114 |
|
| 115 |
public final double getUpperBound() { |
| 116 |
return Double.POSITIVE_INFINITY; |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
protected void storeState() { |
| 133 |
} |
| 134 |
|
| 135 |
protected void restoreState() { |
| 136 |
} |
| 137 |
|
| 138 |
protected void acceptState() { |
| 139 |
} |
| 140 |
|
| 141 |
public Element createElement(Document document) { |
| 142 |
throw new RuntimeException("Not implemented!"); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
@Override |
| 150 |
public double logPdf(double[] x) { |
| 151 |
return logPdf(x[0]); |
| 152 |
} |
| 153 |
|
| 154 |
@Override |
| 155 |
public Variable<Double> getLocationVariable() { |
| 156 |
return location; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
private final Variable<Double> location; |
| 164 |
private final Variable<Double> scale; |
| 165 |
private final Variable<Double> shape; |
| 166 |
} |