| 1 |
package dr.inference.model; |
| 2 |
|
| 3 |
|
| 4 |
import dr.inference.distribution.DistributionLikelihood; |
| 5 |
import dr.util.Attribute; |
| 6 |
|
| 7 |
import java.util.ArrayList; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public class TruncatedDistributionLikelihood extends DistributionLikelihood { |
| 14 |
public TruncatedDistributionLikelihood(DistributionLikelihood distribution, Parameter low, Parameter high){ |
| 15 |
super(distribution.getDistribution()); |
| 16 |
this.dataList = (ArrayList<Attribute<double[]>>) distribution.getDataList(); |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
this.low = low; |
| 22 |
this.high = high; |
| 23 |
} |
| 24 |
|
| 25 |
@Override |
| 26 |
protected double getLogPDF(double value, int i){ |
| 27 |
if(high.getParameterValue(i % high.getDimension()) == low.getParameterValue(i % low.getDimension())) |
| 28 |
return 0; |
| 29 |
if(value > low.getParameterValue(i % low.getDimension()) && value < high.getParameterValue(i % high.getDimension())){ |
| 30 |
double p1 = getDistribution().logPdf(value); |
| 31 |
|
| 32 |
double p2 = 0; |
| 33 |
if(!Double.isInfinite(low.getParameterValue(i % low.getDimension()))) |
| 34 |
p2 = getDistribution().cdf(low.getParameterValue(i % low.getDimension())); |
| 35 |
|
| 36 |
double p3 = 0; |
| 37 |
if(!Double.isInfinite(high.getParameterValue(i % high.getDimension()))) |
| 38 |
p3 = 1 - getDistribution().cdf(high.getParameterValue(i % high.getDimension())); |
| 39 |
|
| 40 |
return p1 - Math.log(1 - (p3 + p2)); |
| 41 |
} |
| 42 |
else{ |
| 43 |
|
| 44 |
|
| 45 |
return Double.NEGATIVE_INFINITY; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
Parameter low; |
| 50 |
Parameter high; |
| 51 |
} |