| 1 |
package test.dr.math; |
| 2 |
|
| 3 |
import dr.math.EmpiricalBayesPoissonSmoother; |
| 4 |
import dr.math.MathUtils; |
| 5 |
import dr.stats.DiscreteStatistics; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
public class EmpiricalBayesPoissonSmootherTest extends MathTestCase { |
| 11 |
|
| 12 |
public void testSmootherMean() { |
| 13 |
|
| 14 |
MathUtils.setSeed(666); |
| 15 |
int length = 100; |
| 16 |
|
| 17 |
double[] in = new double[length]; |
| 18 |
for (int i = 0; i < length; ++i) { |
| 19 |
in[i] = MathUtils.nextDouble() * 100.0; |
| 20 |
} |
| 21 |
|
| 22 |
doSmoothing(in); |
| 23 |
} |
| 24 |
|
| 25 |
public void testUnstableMean() { |
| 26 |
double[] in = new double[] {0, 1}; |
| 27 |
doSmoothing(in); |
| 28 |
} |
| 29 |
|
| 30 |
private void doSmoothing(double[] in) { |
| 31 |
|
| 32 |
double meanX = DiscreteStatistics.mean(in); |
| 33 |
double varX = DiscreteStatistics.variance(in); |
| 34 |
System.err.println("Original mean: " + meanX); |
| 35 |
System.err.println("Original var : " + varX + "\n"); |
| 36 |
|
| 37 |
double[] out = EmpiricalBayesPoissonSmoother.smooth(in); |
| 38 |
|
| 39 |
double meanY = DiscreteStatistics.mean(out); |
| 40 |
double varY = DiscreteStatistics.variance(out); |
| 41 |
System.err.println("Smoothed mean: " + meanY); |
| 42 |
System.err.println("Smoothed var : " + varY); |
| 43 |
System.err.println(""); |
| 44 |
|
| 45 |
assertEquals(meanX, meanY, tolerance); |
| 46 |
assertTrue(varY <= varX); |
| 47 |
} |
| 48 |
|
| 49 |
private static final double tolerance = 10E-6; |
| 50 |
|
| 51 |
|
| 52 |
} |