Skip to content

Commit

Permalink
Fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Aug 10, 2023
1 parent 9f4cdad commit b75d0bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private static class RateExponentialDistribution implements ContinuousDistributi
private final double logRate;

/**
* Create an instance.
*
* @param rate Rate of this distribution.
*/
private RateExponentialDistribution(double rate) {
Expand Down Expand Up @@ -181,7 +183,7 @@ private Distributions() {}
*
* <p>The probability density function of X is:
*
* <p> f(x; lambda) = lambda e^{-x * lambda}
* <p>f(x; lambda) = lambda e^{-x * lambda}
*
* <p>This implementation uses the rate parameter {@code lambda} which is the inverse scale of the
* distribution. A common alternative parameterization uses the scale parameter {@code mu} which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class DistributionsTest {
@ParameterizedTest
@ValueSource(doubles = {0.5, 1, 4})
void canComputeExponentialDistribution(double mean) {
double rate = 1 / mean;
ExponentialDistribution ed = ExponentialDistribution.of(mean);
ContinuousDistribution d = Distributions.exponential(rate);
DoubleDoubleBiPredicate test = Predicates.doublesAreUlpClose(5);
final double rate = 1 / mean;
final ExponentialDistribution ed = ExponentialDistribution.of(mean);
final ContinuousDistribution d = Distributions.exponential(rate);
final DoubleDoubleBiPredicate test = Predicates.doublesAreUlpClose(5);
Assertions.assertEquals(ed.getSupportLowerBound(), d.getSupportLowerBound(), "lower bound");
Assertions.assertEquals(ed.getSupportUpperBound(), d.getSupportUpperBound(), "upper bound");
TestAssertions.assertTest(ed.getMean(), d.getMean(), test, "mean");
TestAssertions.assertTest(ed.getVariance(), d.getVariance(), test, "variance");

double[] x = SimpleArrayUtils.newArray(10, mean / 5, mean / 2);
final double[] x = SimpleArrayUtils.newArray(10, mean / 5, mean / 2);
for (int i = 0; i < x.length; i++) {
TestAssertions.assertTest(ed.density(x[i]), d.density(x[i]), test, "density");
TestAssertions.assertTest(ed.logDensity(x[i]), d.logDensity(x[i]), test, "logDensity");
Expand All @@ -72,7 +72,7 @@ void canComputeExponentialDistribution(double mean) {
"survivalProbability");
}

double[] p = SimpleArrayUtils.newArray(9, 0, 1 / 8.0);
final double[] p = SimpleArrayUtils.newArray(9, 0, 1 / 8.0);
for (int i = 0; i < p.length; i++) {
TestAssertions.assertTest(ed.inverseCumulativeProbability(p[i]),
d.inverseCumulativeProbability(p[i]), test, "inverseCumulativeProbability");
Expand All @@ -82,8 +82,8 @@ void canComputeExponentialDistribution(double mean) {

// Requires rate to be exactly invertible
if (mean == 1 / rate) {
Sampler s1 = ed.createSampler(RngFactory.createWithFixedSeed());
Sampler s2 = d.createSampler(RngFactory.createWithFixedSeed());
final Sampler s1 = ed.createSampler(RngFactory.createWithFixedSeed());
final Sampler s2 = d.createSampler(RngFactory.createWithFixedSeed());
for (int i = 0; i < 10; i++) {
Assertions.assertEquals(s1.sample(), s2.sample());
}
Expand All @@ -92,9 +92,9 @@ void canComputeExponentialDistribution(double mean) {

@Test
void canComputeExponentialDistributionEdgeCases() {
ExponentialDistribution ed = ExponentialDistribution.of(1);
ContinuousDistribution d = Distributions.exponential(1);
for (double x : new double[] {-1, 0}) {
final ExponentialDistribution ed = ExponentialDistribution.of(1);
final ContinuousDistribution d = Distributions.exponential(1);
for (final double x : new double[] {-1, 0}) {
Assertions.assertEquals(ed.density(x), d.density(x), "density");
// Allow -0.0 == 0.0
Assertions.assertEquals(ed.logDensity(x), d.logDensity(x), 0.0, "logDensity");
Expand All @@ -117,11 +117,12 @@ void canComputeExponentialDistributionEdgeCases() {

@Test
void canComputeExponentialDistributionSamplesWithInfiniteMean() {
double rate = Double.MIN_NORMAL / 4;
ContinuousDistribution d = Distributions.exponential(rate);
final double rate = Double.MIN_NORMAL / 4;
final ContinuousDistribution d = Distributions.exponential(rate);
Assertions.assertEquals(Double.POSITIVE_INFINITY, d.getMean(), "mean");
Sampler s1 = ExponentialDistribution.of(1).createSampler(RngFactory.createWithFixedSeed());
Sampler s2 = d.createSampler(RngFactory.createWithFixedSeed());
final Sampler s1 =
ExponentialDistribution.of(1).createSampler(RngFactory.createWithFixedSeed());
final Sampler s2 = d.createSampler(RngFactory.createWithFixedSeed());
for (int i = 0; i < 10; i++) {
Assertions.assertEquals(s1.sample() / rate, s2.sample());
}
Expand Down

0 comments on commit b75d0bc

Please sign in to comment.