You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/10/21 23:36:38 UTC

svn commit: r1534389 - in /commons/proper/math/trunk/src/test: R/zipfTestCases java/org/apache/commons/math3/distribution/ZipfDistributionTest.java

Author: tn
Date: Mon Oct 21 21:36:37 2013
New Revision: 1534389

URL: http://svn.apache.org/r1534389
Log:
Add reference test values for ZipfDistribution.logProbability.

Added:
    commons/proper/math/trunk/src/test/R/zipfTestCases
Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java

Added: commons/proper/math/trunk/src/test/R/zipfTestCases
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/R/zipfTestCases?rev=1534389&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/R/zipfTestCases (added)
+++ commons/proper/math/trunk/src/test/R/zipfTestCases Mon Oct 21 21:36:37 2013
@@ -0,0 +1,89 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#------------------------------------------------------------------------------
+# R source file to validate Zipf distribution tests in
+# org.apache.commons.math.distribution.ZipfDistributionTest
+#
+# To run the test, install R, put this file and testFunctions
+# into the same directory, launch R from this directory and then enter
+# source("<name-of-this-file>")
+#
+# R functions used
+# dzipf(x, N, s, log = FALSE) <- density 
+# pzipf(q, N, s) <- distribution
+#------------------------------------------------------------------------------
+tol <- 1E-6                       # error tolerance for tests
+#------------------------------------------------------------------------------
+# Function definitions
+
+library(VGAM)
+source("testFunctions")           # utility test functions
+
+# function to verify density computations
+
+verifyDensity <- function(points, expected, N, s, tol, log = FALSE) {
+    rDensityValues <- rep(0, length(points))
+    i <- 0
+    for (point in points) {
+        i <- i + 1
+        rDensityValues[i] <- dzipf(point, N, s, log)
+    }
+    output <- c("Density test N = ", N, ", s = ", s)
+    if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
+        displayPadded(output, SUCCEEDED, WIDTH)
+    } else {
+        displayPadded(output, FAILED, WIDTH)
+    }       
+}
+
+# function to verify distribution computations
+
+verifyDistribution <- function(points, expected, N, s, tol) {
+    rDistValues <- rep(0, length(points))
+    i <- 0
+    for (point in points) {
+        i <- i + 1
+        rDistValues[i] <- pzipf(point, N, s)
+    }
+    output <- c("Distribution test N = ", N, ", s = ", s)
+    if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
+        displayPadded(output, SUCCEEDED, WIDTH)
+    } else {
+        displayPadded(output, FAILED, WIDTH)
+    }       
+}
+
+#--------------------------------------------------------------------------
+cat("Zipf test cases\n")
+
+N <- 10
+s <- 1
+
+densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
+densityValues <- c(0, 0, 0.341417152147406, 0.170708576073703, 0.113805717382469, 0.0853542880368514,
+                   0.0682834304294811, 0.0569028586912343, 0.0487738788782008, 0.0426771440184257,
+                   0.0379352391274895, 0.0341417152147406, 0)
+logDensityValues <- c(Inf, NaN, -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
+                      -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442, -3.2718748066008,
+                      -3.37723532225863, -Inf)
+distributionValues <- c(0, 0, 0.341417152147406, 0.512125728221108, 0.625931445603577, 0.711285733640428,
+                        0.779569164069909, 0.836472022761144, 0.885245901639344, 0.92792304565777,
+                        0.96585828478526, 1, 1)
+
+verifyDensity(densityPoints, densityValues, N, s, tol)
+verifyDensity(densityPoints, logDensityValues, N, s, tol, TRUE)
+verifyDistribution(densityPoints, distributionValues, N, s, tol)
+

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java?rev=1534389&r1=1534388&r2=1534389&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java Mon Oct 21 21:36:37 2013
@@ -80,8 +80,9 @@ public class ZipfDistributionTest extend
     @Override
     public double[] makeLogDensityTestValues() {
         return new double[] {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,
-        -1.0746d, -1.7678d, -2.1733d, -2.4609d, -2.6841d, -2.8664d, -3.0206d, -3.1541d,
-        -3.2719d, -3.3772d, Double.NEGATIVE_INFINITY};
+            -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
+            -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442,
+            -3.2718748066008, -3.37723532225863, Double.NEGATIVE_INFINITY};
     }
 
     /** Creates the default cumulative probability density test input values */



Re: svn commit: r1534389 - in /commons/proper/math/trunk/src/test: R/zipfTestCases java/org/apache/commons/math3/distribution/ZipfDistributionTest.java

Posted by Thomas Neidhart <th...@gmail.com>.
On 10/21/2013 11:56 PM, Phil Steitz wrote:
> On 10/21/13 2:36 PM, tn@apache.org wrote:
>> Author: tn
>> Date: Mon Oct 21 21:36:37 2013
>> New Revision: 1534389
>>
>> URL: http://svn.apache.org/r1534389
>> Log:
>> Add reference test values for ZipfDistribution.logProbability.
>>
>> Added:
>>     commons/proper/math/trunk/src/test/R/zipfTestCases
>> Modified:
>>     commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
>>
>> Added: commons/proper/math/trunk/src/test/R/zipfTestCases
>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/R/zipfTestCases?rev=1534389&view=auto
>> ==============================================================================
>> --- commons/proper/math/trunk/src/test/R/zipfTestCases (added)
>> +++ commons/proper/math/trunk/src/test/R/zipfTestCases Mon Oct 21 21:36:37 2013
>> @@ -0,0 +1,89 @@
>> +# Licensed to the Apache Software Foundation (ASF) under one or more
>> +# contributor license agreements.  See the NOTICE file distributed with
>> +# this work for additional information regarding copyright ownership.
>> +# The ASF licenses this file to You under the Apache License, Version 2.0
>> +# (the "License"); you may not use this file except in compliance with
>> +# the License.  You may obtain a copy of the License at
>> +#
>> +#      http://www.apache.org/licenses/LICENSE-2.0
>> +#
>> +# Unless required by applicable law or agreed to in writing, software
>> +# distributed under the License is distributed on an "AS IS" BASIS,
>> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> +# See the License for the specific language governing permissions and
>> +# limitations under the License.
>> +#
>> +#------------------------------------------------------------------------------
>> +# R source file to validate Zipf distribution tests in
>> +# org.apache.commons.math.distribution.ZipfDistributionTest
>> +#
>> +# To run the test, install R, put this file and testFunctions
>> +# into the same directory, launch R from this directory and then enter
>> +# source("<name-of-this-file>")
>> +#
>> +# R functions used
>> +# dzipf(x, N, s, log = FALSE) <- density 
>> +# pzipf(q, N, s) <- distribution
>> +#------------------------------------------------------------------------------
>> +tol <- 1E-6                       # error tolerance for tests
>> +#------------------------------------------------------------------------------
>> +# Function definitions
>> +
>> +library(VGAM)
>> +source("testFunctions")           # utility test functions
>> +
>> +# function to verify density computations
>> +
>> +verifyDensity <- function(points, expected, N, s, tol, log = FALSE) {
>> +    rDensityValues <- rep(0, length(points))
>> +    i <- 0
>> +    for (point in points) {
>> +        i <- i + 1
>> +        rDensityValues[i] <- dzipf(point, N, s, log)
>> +    }
>> +    output <- c("Density test N = ", N, ", s = ", s)
>> +    if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
>> +        displayPadded(output, SUCCEEDED, WIDTH)
>> +    } else {
>> +        displayPadded(output, FAILED, WIDTH)
>> +    }       
>> +}
>> +
>> +# function to verify distribution computations
>> +
>> +verifyDistribution <- function(points, expected, N, s, tol) {
>> +    rDistValues <- rep(0, length(points))
>> +    i <- 0
>> +    for (point in points) {
>> +        i <- i + 1
>> +        rDistValues[i] <- pzipf(point, N, s)
>> +    }
>> +    output <- c("Distribution test N = ", N, ", s = ", s)
>> +    if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
>> +        displayPadded(output, SUCCEEDED, WIDTH)
>> +    } else {
>> +        displayPadded(output, FAILED, WIDTH)
>> +    }       
>> +}
>> +
>> +#--------------------------------------------------------------------------
>> +cat("Zipf test cases\n")
>> +
>> +N <- 10
>> +s <- 1
>> +
>> +densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
>> +densityValues <- c(0, 0, 0.341417152147406, 0.170708576073703, 0.113805717382469, 0.0853542880368514,
>> +                   0.0682834304294811, 0.0569028586912343, 0.0487738788782008, 0.0426771440184257,
>> +                   0.0379352391274895, 0.0341417152147406, 0)
>> +logDensityValues <- c(Inf, NaN, -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
>> +                      -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442, -3.2718748066008,
>> +                      -3.37723532225863, -Inf)
>> +distributionValues <- c(0, 0, 0.341417152147406, 0.512125728221108, 0.625931445603577, 0.711285733640428,
>> +                        0.779569164069909, 0.836472022761144, 0.885245901639344, 0.92792304565777,
>> +                        0.96585828478526, 1, 1)
>> +
>> +verifyDensity(densityPoints, densityValues, N, s, tol)
>> +verifyDensity(densityPoints, logDensityValues, N, s, tol, TRUE)
>> +verifyDistribution(densityPoints, distributionValues, N, s, tol)
>> +
>>
>> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java?rev=1534389&r1=1534388&r2=1534389&view=diff
>> ==============================================================================
>> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java (original)
>> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java Mon Oct 21 21:36:37 2013
>> @@ -80,8 +80,9 @@ public class ZipfDistributionTest extend
>>      @Override
>>      public double[] makeLogDensityTestValues() {
>>          return new double[] {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,
>> -        -1.0746d, -1.7678d, -2.1733d, -2.4609d, -2.6841d, -2.8664d, -3.0206d, -3.1541d,
>> -        -3.2719d, -3.3772d, Double.NEGATIVE_INFINITY};
>> +            -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
>> +            -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442,
>> +            -3.2718748066008, -3.37723532225863, Double.NEGATIVE_INFINITY};
>>      }
>>  
>>      /** Creates the default cumulative probability density test input values */
>>
>>
>>
> Thanks for fixing this, Thomas, and once again sorry I somehow
> missed the test failures.  Double thanks for adding the R tests :)

np, reminds me that I still need to add the graphical overview of
supported distributions to the userguide ... ;-)

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1534389 - in /commons/proper/math/trunk/src/test: R/zipfTestCases java/org/apache/commons/math3/distribution/ZipfDistributionTest.java

Posted by Phil Steitz <ph...@gmail.com>.
On 10/21/13 2:36 PM, tn@apache.org wrote:
> Author: tn
> Date: Mon Oct 21 21:36:37 2013
> New Revision: 1534389
>
> URL: http://svn.apache.org/r1534389
> Log:
> Add reference test values for ZipfDistribution.logProbability.
>
> Added:
>     commons/proper/math/trunk/src/test/R/zipfTestCases
> Modified:
>     commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
>
> Added: commons/proper/math/trunk/src/test/R/zipfTestCases
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/R/zipfTestCases?rev=1534389&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/test/R/zipfTestCases (added)
> +++ commons/proper/math/trunk/src/test/R/zipfTestCases Mon Oct 21 21:36:37 2013
> @@ -0,0 +1,89 @@
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.
> +# The ASF licenses this file to You under the Apache License, Version 2.0
> +# (the "License"); you may not use this file except in compliance with
> +# the License.  You may obtain a copy of the License at
> +#
> +#      http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS,
> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +# See the License for the specific language governing permissions and
> +# limitations under the License.
> +#
> +#------------------------------------------------------------------------------
> +# R source file to validate Zipf distribution tests in
> +# org.apache.commons.math.distribution.ZipfDistributionTest
> +#
> +# To run the test, install R, put this file and testFunctions
> +# into the same directory, launch R from this directory and then enter
> +# source("<name-of-this-file>")
> +#
> +# R functions used
> +# dzipf(x, N, s, log = FALSE) <- density 
> +# pzipf(q, N, s) <- distribution
> +#------------------------------------------------------------------------------
> +tol <- 1E-6                       # error tolerance for tests
> +#------------------------------------------------------------------------------
> +# Function definitions
> +
> +library(VGAM)
> +source("testFunctions")           # utility test functions
> +
> +# function to verify density computations
> +
> +verifyDensity <- function(points, expected, N, s, tol, log = FALSE) {
> +    rDensityValues <- rep(0, length(points))
> +    i <- 0
> +    for (point in points) {
> +        i <- i + 1
> +        rDensityValues[i] <- dzipf(point, N, s, log)
> +    }
> +    output <- c("Density test N = ", N, ", s = ", s)
> +    if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
> +        displayPadded(output, SUCCEEDED, WIDTH)
> +    } else {
> +        displayPadded(output, FAILED, WIDTH)
> +    }       
> +}
> +
> +# function to verify distribution computations
> +
> +verifyDistribution <- function(points, expected, N, s, tol) {
> +    rDistValues <- rep(0, length(points))
> +    i <- 0
> +    for (point in points) {
> +        i <- i + 1
> +        rDistValues[i] <- pzipf(point, N, s)
> +    }
> +    output <- c("Distribution test N = ", N, ", s = ", s)
> +    if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
> +        displayPadded(output, SUCCEEDED, WIDTH)
> +    } else {
> +        displayPadded(output, FAILED, WIDTH)
> +    }       
> +}
> +
> +#--------------------------------------------------------------------------
> +cat("Zipf test cases\n")
> +
> +N <- 10
> +s <- 1
> +
> +densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
> +densityValues <- c(0, 0, 0.341417152147406, 0.170708576073703, 0.113805717382469, 0.0853542880368514,
> +                   0.0682834304294811, 0.0569028586912343, 0.0487738788782008, 0.0426771440184257,
> +                   0.0379352391274895, 0.0341417152147406, 0)
> +logDensityValues <- c(Inf, NaN, -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
> +                      -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442, -3.2718748066008,
> +                      -3.37723532225863, -Inf)
> +distributionValues <- c(0, 0, 0.341417152147406, 0.512125728221108, 0.625931445603577, 0.711285733640428,
> +                        0.779569164069909, 0.836472022761144, 0.885245901639344, 0.92792304565777,
> +                        0.96585828478526, 1, 1)
> +
> +verifyDensity(densityPoints, densityValues, N, s, tol)
> +verifyDensity(densityPoints, logDensityValues, N, s, tol, TRUE)
> +verifyDistribution(densityPoints, distributionValues, N, s, tol)
> +
>
> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java?rev=1534389&r1=1534388&r2=1534389&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java (original)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java Mon Oct 21 21:36:37 2013
> @@ -80,8 +80,9 @@ public class ZipfDistributionTest extend
>      @Override
>      public double[] makeLogDensityTestValues() {
>          return new double[] {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,
> -        -1.0746d, -1.7678d, -2.1733d, -2.4609d, -2.6841d, -2.8664d, -3.0206d, -3.1541d,
> -        -3.2719d, -3.3772d, Double.NEGATIVE_INFINITY};
> +            -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
> +            -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442,
> +            -3.2718748066008, -3.37723532225863, Double.NEGATIVE_INFINITY};
>      }
>  
>      /** Creates the default cumulative probability density test input values */
>
>
>
Thanks for fixing this, Thomas, and once again sorry I somehow
missed the test failures.  Double thanks for adding the R tests :)

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org