diff --git a/src/test/R/hypergeometricTestCases b/src/test/R/hypergeometricTestCases index a912fa5b1..a1d4ee983 100644 --- a/src/test/R/hypergeometricTestCases +++ b/src/test/R/hypergeometricTestCases @@ -34,12 +34,12 @@ source("testFunctions") # utility test functions # function to verify density computations -verifyDensity <- function(points, expected, good, bad, selected, tol) { +verifyDensity <- function(points, expected, good, bad, selected, tol, log = FALSE) { rDensityValues <- rep(0, length(points)) i <- 0 for (point in points) { i <- i + 1 - rDensityValues[i] <- dhyper(point, good, bad, selected) + rDensityValues[i] <- dhyper(point, good, bad, selected, log) } output <- c("Density test good = ", good, ", bad = ", bad, ", selected = ",selected) @@ -76,8 +76,10 @@ bad <- 5 selected <- 5 densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 10) -densityValues <- c(0, 0.003968, 0.099206, 0.396825, 0.396825, 0.099206, - 0.003968, 0) +densityValues <- c(0, 0.00396825396825397, 0.0992063492063492, 0.396825396825397, 0.396825396825397, + 0.0992063492063492, 0.00396825396825397, 0) +logDensityValues <- c(-Inf, -5.52942908751142, -2.31055326264322, -0.924258901523332, + -0.924258901523332, -2.31055326264322, -5.52942908751142, -Inf) distributionValues <- c(0, .003968, .103175, .50000, .896825, .996032, 1.00000, 1) #Eliminate p=1 case because it will mess up adjustement below @@ -86,6 +88,7 @@ inverseCumPoints <- c(0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999, inverseCumValues <- c(-1, -1, 0, 0, 0, 0, 4, 3, 3, 3, 3) verifyDensity(densityPoints, densityValues, good, bad, selected, tol) +verifyDensity(densityPoints, logDensityValues, good, bad, selected, tol, TRUE) verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol) i <- 0 diff --git a/src/test/R/testFunctions b/src/test/R/testFunctions index c95277485..92f62ea5b 100644 --- a/src/test/R/testFunctions +++ b/src/test/R/testFunctions @@ -23,7 +23,7 @@ WIDTH <- 80 # screen size constant for display functions SUCCEEDED <- "SUCCEEDED" FAILED <- "FAILED" -options(digits=12) # display 12 digits throughout +options(digits=15) # display 12 digits throughout #------------------------------------------------------------------------------ # Comparison functions #------------------------------------------------------------------------------ diff --git a/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java b/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java index 796737eac..49577bcb4 100644 --- a/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java +++ b/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java @@ -65,6 +65,17 @@ public class HypergeometricDistributionTest extends IntegerDistributionAbstractT 0.0992063492063, 0.00396825396825, 0d}; } + /** + * Creates the default probability log density test expected values + * Reference values are from R, version 2.14.1. + */ + @Override + public double[] makeLogDensityTestValues() { + //-Inf -Inf + return new double[] {Double.NEGATIVE_INFINITY, -5.52942908751142, -2.31055326264322, -0.924258901523332, + -0.924258901523332, -2.31055326264322, -5.52942908751142, Double.NEGATIVE_INFINITY}; + } + /** Creates the default cumulative probability density test input values */ @Override public int[] makeCumulativeTestPoints() {