You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2022/01/24 15:22:31 UTC

[commons-statistics] branch master updated (d86ee09 -> 443ceaa)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git.


    from d86ee09  STATISTICS-25: Use beta function for the PDF
     new 65123f8  Add t distribution test cases for more degrees of freedom
     new f9db4a8  Remove trailing whitespace
     new 443ceaa  Add a t-distribution sampler

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../statistics/distribution/TDistribution.java     | 101 +++++++++++++++++++++
 .../statistics/distribution/test.t.10.properties   |  45 +++++++++
 .../statistics/distribution/test.t.11.properties   |  39 ++++++++
 .../statistics/distribution/test.t.12.properties   |  39 ++++++++
 .../statistics/distribution/test.t.5.properties    |  43 +++++++++
 .../statistics/distribution/test.t.6.properties    |  45 +++++++++
 .../statistics/distribution/test.t.7.properties    |  45 +++++++++
 .../statistics/distribution/test.t.8.properties    |  45 +++++++++
 .../statistics/distribution/test.t.9.properties    |  45 +++++++++
 src/main/resources/checkstyle/checkstyle.xml       |   2 +-
 src/site/site.xml                                  |   6 +-
 src/site/xdoc/developers.xml                       |  28 +++---
 src/site/xdoc/download_statistics.xml              |   4 +-
 src/site/xdoc/index.xml                            |   2 +-
 src/site/xdoc/userguide/distribution.xml           |   2 +-
 src/site/xdoc/userguide/index.xml                  |   8 +-
 16 files changed, 473 insertions(+), 26 deletions(-)
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.10.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.11.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.12.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.5.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.6.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.7.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.8.properties
 create mode 100644 commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.9.properties

[commons-statistics] 02/03: Remove trailing whitespace

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit f9db4a8ecb0429c28b9ab24d0e1b59ac17e853c1
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Jan 24 13:38:53 2022 +0000

    Remove trailing whitespace
---
 src/main/resources/checkstyle/checkstyle.xml |  2 +-
 src/site/site.xml                            |  6 +++---
 src/site/xdoc/developers.xml                 | 28 ++++++++++++++--------------
 src/site/xdoc/download_statistics.xml        |  4 ++--
 src/site/xdoc/index.xml                      |  2 +-
 src/site/xdoc/userguide/distribution.xml     |  2 +-
 src/site/xdoc/userguide/index.xml            |  8 ++++----
 7 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/main/resources/checkstyle/checkstyle.xml b/src/main/resources/checkstyle/checkstyle.xml
index 1ea69b4..a80195b 100644
--- a/src/main/resources/checkstyle/checkstyle.xml
+++ b/src/main/resources/checkstyle/checkstyle.xml
@@ -21,7 +21,7 @@
           "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
           "https://checkstyle.org/dtds/configuration_1_3.dtd">
 
-<!-- 
+<!--
   Commons Statitics customization of default Checkstyle behavior:
   https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml
 -->
diff --git a/src/site/site.xml b/src/site/site.xml
index cd1ff46..b4270e4 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -27,17 +27,17 @@
       <item name="Overview" href="/index.html"/>
       <item name="Downloads" href="https://commons.apache.org/statistics/download_statistics.cgi"/>
       <item name="Issue Tracking" href="/issue-tracking.html"/>
-      <item name="Source Repository (current)" 
+      <item name="Source Repository (current)"
          href="http://gitbox.apache.org/repos/asf/commons-statistics.git"/>
       <!-- <item name="Wiki"   -->
       <!--       href="http://wiki.apache.org/commons/Statistics"/> -->
       <item name="Developers Guide" href="/developers.html"/>
     </menu>
-    
+
     <menu name="User Guide">
       <item name="Contents" href="/userguide/index.html"/>
     </menu>
-    
+
     <head>
       <![CDATA[<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
       </script>]]>
diff --git a/src/site/xdoc/developers.xml b/src/site/xdoc/developers.xml
index e86258c..b495a88 100644
--- a/src/site/xdoc/developers.xml
+++ b/src/site/xdoc/developers.xml
@@ -15,12 +15,12 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-  
+
 <document>
   <properties>
     <title>Developers Guide</title>
   </properties>
-  
+
   <body>
 
     <section name="Aims">
@@ -30,7 +30,7 @@
         to ensure that the code they create can be successfully maintained by others.
       </p>
     </section>
-    
+
     <section name='Guidelines'>
       <p>
         Developers are asked to comply with the following development guidelines.
@@ -55,8 +55,8 @@
             </li>
             <li>
               Like most commons components, Commons Statistics uses Apache Maven as our
-              build tool. The sources can also be built using Ant (a working 
-              Ant build.xml is included in the top level project directory). 
+              build tool. The sources can also be built using Ant (a working
+              Ant build.xml is included in the top level project directory).
               To build Commons Statistics using Maven, you can follow the instructions for
               <a href="http://maven.apache.org/run-maven/index.html">Building a
               project with Maven</a>.
@@ -73,7 +73,7 @@
               Statistics Wish List Wiki Page.</a>
             </li>
             <li>
-              Be sure to join the commons-dev and commons-user 
+              Be sure to join the commons-dev and commons-user
               <a href="mail-lists.html">
                 email lists</a> and use them appropriately (make sure the string
                 "[Statistics]" starts the Subject line of all your postings).
@@ -84,11 +84,11 @@
                 Setup an account on JIRA
               </a>
               and use it to submit patches and
-              identify bugs. Read the 
+              identify bugs. Read the
               <a href="https://issues.apache.org/bugwritinghelp.html">
               directions</a>
               for submitting bugs and search the database to
-              determine if an issue exists or has already been dealt with.        
+              determine if an issue exists or has already been dealt with.
               <p>
                 See the <a href="https://commons.apache.org/statistics/issue-tracking.html">
                 Commons Statistics Issue Tracking Page</a>
@@ -110,7 +110,7 @@
         <p>
           Follow the steps below when making suggestions for additions or
           enhancements to Commons Statistics. This will make it easier for the community
-          to comment on your ideas and for the committers to keep track of them. 
+          to comment on your ideas and for the committers to keep track of them.
           Thanks in advance!
           <ol>
             <li>Start with a post to the commons-dev mailing list, with [Statistics] at
@@ -128,7 +128,7 @@
               useful</li>
             </ul></li>
             <li>Assuming a generally favorable response to the idea on commons-dev,
-            the next step is to add an entry to the 
+            the next step is to add an entry to the
             <a href="http://wiki.apache.org/commons/StatisticsWishList">Statistics Wish
             List</a> corresponding to the idea.  Include a reference to the
             discussion thread. </li>
@@ -145,7 +145,7 @@
             ticket if a patch goes more than a few days with no comment or commit.
             </li>
           </ol>
-        </p>   
+        </p>
       </subsection>
 
       <subsection name='Coding Style'>
@@ -206,7 +206,7 @@
           </li>
           <li>
             Implementations <i>should</i> use standard algorithms and
-            references or full descriptions of all algorithms <i>should</i> be 
+            references or full descriptions of all algorithms <i>should</i> be
             provided.
           </li>
           <li>
@@ -251,7 +251,7 @@
             License in a comment that begins the file.
           </li>
           <li>
-            All contributions must comply with the terms of the Apache 
+            All contributions must comply with the terms of the Apache
             <a href="http://www.apache.org/licenses/cla.pdf">Contributor License
             Agreement (CLA)</a>.
           </li>
@@ -265,7 +265,7 @@
           <li>
             References to source materials covered by restrictive proprietary
             licenses should be avoided.  In particular, contributions should not
-            implement or include references to algorithms in 
+            implement or include references to algorithms in
             <a href="http://www.nr.com/">Numerical Recipes (NR)</a>.
             Any questions about copyright or patent issues should be raised on
             the commons-dev mailing list before contributing or committing code.
diff --git a/src/site/xdoc/download_statistics.xml b/src/site/xdoc/download_statistics.xml
index 3ad0a49..2e63998 100644
--- a/src/site/xdoc/download_statistics.xml
+++ b/src/site/xdoc/download_statistics.xml
@@ -27,9 +27,9 @@ limitations under the License.
  +======================================================================+
  |                                                                      |
  | 1) Re-generate using: mvn commons:download-page                      |
- 
+
  Do NOT re-generate before an actual release can be downloaded.
- 
+
  |                                                                      |
  | 2) Set the following properties in the component's pom:              |
  |    - commons.componentid (required, alphabetic, lower case)          |
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index 0fbbbc7..93a071b 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -16,7 +16,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-  
+
 <document>
 
   <properties>
diff --git a/src/site/xdoc/userguide/distribution.xml b/src/site/xdoc/userguide/distribution.xml
index da6ea75..c8d99ff 100644
--- a/src/site/xdoc/userguide/distribution.xml
+++ b/src/site/xdoc/userguide/distribution.xml
@@ -16,7 +16,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-  
+
 <?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
 <document url="distribution.html">
   <properties>
diff --git a/src/site/xdoc/userguide/index.xml b/src/site/xdoc/userguide/index.xml
index 3999aca..a845ec0 100644
--- a/src/site/xdoc/userguide/index.xml
+++ b/src/site/xdoc/userguide/index.xml
@@ -16,7 +16,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-  
+
 <?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
 <document url="index.html">
   <properties>
@@ -25,7 +25,7 @@
 
   <body>
     <section name="Table of Contents" href="toc">
-        
+
       <ul>
 
         <li>
@@ -35,7 +35,7 @@
       </ul>
 
     </section>
-    
+
   </body>
-  
+
 </document>

[commons-statistics] 01/03: Add t distribution test cases for more degrees of freedom

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit 65123f8f64c10545b7df50a3df208a70f5380d75
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Jan 24 13:37:19 2022 +0000

    Add t distribution test cases for more degrees of freedom
    
    Add df=0.25, 0.5, 10, 1e2, 1e4, 1e6, 1e10, 1e14
---
 .../statistics/distribution/test.t.10.properties   | 45 ++++++++++++++++++++++
 .../statistics/distribution/test.t.11.properties   | 39 +++++++++++++++++++
 .../statistics/distribution/test.t.12.properties   | 39 +++++++++++++++++++
 .../statistics/distribution/test.t.5.properties    | 43 +++++++++++++++++++++
 .../statistics/distribution/test.t.6.properties    | 45 ++++++++++++++++++++++
 .../statistics/distribution/test.t.7.properties    | 45 ++++++++++++++++++++++
 .../statistics/distribution/test.t.8.properties    | 45 ++++++++++++++++++++++
 .../statistics/distribution/test.t.9.properties    | 45 ++++++++++++++++++++++
 8 files changed, 346 insertions(+)

diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.10.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.10.properties
new file mode 100644
index 0000000..a16cb02
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.10.properties
@@ -0,0 +1,45 @@
+# 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.
+
+parameters = 1e14
+# Limited by density values
+tolerance.relative = 2e-15
+mean = 0
+variance = 1.00000000000002
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.022750131948180554731 0.158655253931458378736 0.308537538725987658950 \
+  0.500000000000000000000 0.524917669029247191403 0.549738224830112809371 \
+  0.598706325682923479192 0.691462461274012341050 0.841344746068541593509 \
+  0.977249868051819459147 0.998650101968369563465 0.999968328758166880021 \
+  0.999999713348428187487
+pdf.values = \
+  5.3990966513189013465e-02 2.4197072451914214408e-01 \
+  3.5206532676429824757e-01 3.9894228040143170366e-01 \
+  3.9816385668688558663e-01 3.9583768694474846805e-01 \
+  3.8666811680284818298e-01 3.5206532676429824757e-01 \
+  2.4197072451914214408e-01 5.3990966513189013465e-02 \
+  4.4318484119386936104e-03 1.3383022576495998785e-04 \
+  1.4867195147364332597e-06
+sf.values = \
+  9.7724986805181945915e-01 8.4134474606854159351e-01 \
+  6.9146246127401234105e-01 5.0000000000000000000e-01 \
+  4.7508233097075286411e-01 4.5026177516988719063e-01 \
+  4.0129367431707657632e-01 3.0853753872598765895e-01 \
+  1.5865525393145837874e-01 2.2750131948180554731e-02 \
+  1.3498980316304252589e-03 3.1671241833142672244e-05 \
+  2.8665157187967719709e-07
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.11.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.11.properties
new file mode 100644
index 0000000..ea43314
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.11.properties
@@ -0,0 +1,39 @@
+# 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.
+
+parameters = 0.25
+mean = NaN
+variance = NaN
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.30256179221838608306 0.35565187103704398730 0.40809998934200636400 \
+  0.50000000000000000000 0.51338485776113285119 0.52651704176623193021 \
+  0.55121099071545742731 0.59190001065799369151 0.64434812896295601270 \
+  0.69743820778161391694 0.72596719894069106083 0.74477206090794523252 \
+  0.75852695602285835630
+pdf.values = \
+  0.036568613378051513518 0.078574715291670857442 0.139314179499834794873 \
+  0.214851835757470216448 0.212779951034929082354 0.206863315985674645070 \
+  0.186883220968336150047 0.139314179499834794873 0.078574715291670857442 \
+  0.036568613378051513518 0.022491218837614151971 0.015814964481291767656 \
+  0.012007102281802888716
+sf.values = \
+  0.69743820778161391694 0.64434812896295601270 0.59190001065799369151 \
+  0.50000000000000000000 0.48661514223886714881 0.47348295823376806979 \
+  0.44878900928454257269 0.40809998934200636400 0.35565187103704398730 \
+  0.30256179221838608306 0.27403280105930888366 0.25522793909205476748 \
+  0.24147304397714164370
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.12.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.12.properties
new file mode 100644
index 0000000..d831e7f
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.12.properties
@@ -0,0 +1,39 @@
+# 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.
+
+parameters = 0.5
+mean = NaN
+variance = NaN
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.22275744509156564233 0.30112161084132205158 0.37865903646471832378 \
+  0.50000000000000000000 0.51682198365134712770 0.53345041605242404792 \
+  0.56544011515757452990 0.62134096353528167622 0.69887838915867794842 \
+  0.77724255490843430216 0.81634592200702826847 0.84038995850566422519 \
+  0.85700429842057057606
+pdf.values = \
+  0.051899228247372600209 0.118304657040392585676 0.198963924026172522819 \
+  0.269676300594189677362 0.268106890928048624545 0.263523779599922125527 \
+  0.246875725979702836943 0.198963924026172522819 0.118304657040392585676 \
+  0.051899228247372600209 0.029633133748884075281 0.019586522104539767775 \
+  0.014130747946566201215
+sf.values = \
+  0.77724255490843430216 0.69887838915867794842 0.62134096353528167622 \
+  0.50000000000000000000 0.48317801634865287230 0.46654958394757600759 \
+  0.43455988484242547010 0.37865903646471832378 0.30112161084132205158 \
+  0.22275744509156564233 0.18365407799297175928 0.15961004149433577481 \
+  0.14299570157942942394
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.5.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.5.properties
new file mode 100644
index 0000000..0945346
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.5.properties
@@ -0,0 +1,43 @@
+# 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.
+
+parameters = 10.0
+# Limited by SF inverse mapping
+tolerance.relative = 2e-15
+mean = 0
+variance = 1.25
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.036694017385370196471 0.170446566151030043379 0.313946802871486463360 \
+  0.500000000000000000000 0.524301871108091344098 0.548499642158953415461 \
+  0.596175897131692944519 0.686053197128513536640 0.829553433848969956621 \
+  0.963305982614629741079 0.993328172488715188670 0.998740833687631668347 \
+  0.999731333198621729963
+pdf.values = \
+  0.0611457663212181812273 0.2303619892291386972438 0.3396951363520777644744 \
+  0.3891083839660310905728 0.3882734691832335771622 0.3857813984229577219942 \
+  0.3760002856897183276530 0.3396951363520777644744 0.2303619892291386972438 \
+  0.0611457663212181812273 0.0114005494645425288491 0.0020310339110412166559 \
+  0.0003960010564637987977
+sf.values = \
+  0.96330598261462974107872 0.82955343384896995662103 \
+  0.68605319712851353664007 0.50000000000000000000000 \
+  0.47569812889190860039079 0.45150035784104658453941 \
+  0.40382410286830705548056 0.31394680287148646335993 \
+  0.17044656615103004337897 0.03669401738537019647124 \
+  0.00667182751128479398228 0.00125916631236834509686 \
+  0.00026866680137822623528
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.6.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.6.properties
new file mode 100644
index 0000000..22e0aee
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.6.properties
@@ -0,0 +1,45 @@
+# 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.
+
+parameters = 100.0
+# Limited by SF values
+tolerance.relative = 3e-15
+mean = 0
+variance = 1.0204081632653061
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.024106089365566834432 0.159862077892061860140 0.309086782915443336606 \
+  0.500000000000000000000 0.524855292152292651764 0.549612753423250222085 \
+  0.598449893923389764083 0.690913217084556663394 0.840137922107938139860 \
+  0.975893910634433092710 0.998296042328335353488 0.999939238177849576417 \
+  0.999998774913293253519
+pdf.values = \
+  5.4908643295409689800e-02 2.4076589692854596936e-01 \
+  3.5080283339233037099e-01 3.9794618693589384195e-01 \
+  3.9716196497428690737e-01 3.9481874210251571844e-01 \
+  3.8558595819834484697e-01 3.5080283339233037099e-01 \
+  2.4076589692854596936e-01 5.4908643295409689800e-02 \
+  5.1260897023202561112e-03 2.2115455654062911046e-04 \
+  5.0800582347272749576e-06
+sf.values = \
+  9.7589391063443309271e-01 8.4013792210793813986e-01 \
+  6.9091321708455666339e-01 5.0000000000000000000e-01 \
+  4.7514470784770734824e-01 4.5038724657674977792e-01 \
+  4.0155010607661023592e-01 3.0908678291544333661e-01 \
+  1.5986207789206186014e-01 2.4106089365566834432e-02 \
+  1.7039576716647252246e-03 6.0761822150380825143e-05 \
+  1.2250867067518980009e-06
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.7.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.7.properties
new file mode 100644
index 0000000..9213c6e
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.7.properties
@@ -0,0 +1,45 @@
+# 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.
+
+parameters = 1e4
+# Limited by SF values
+tolerance.relative = 4e-15
+mean = 0
+variance = 1.0002000400080016
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.022763630330717734424 0.158667352165214714521 0.308543039661616669278 \
+  0.500000000000000000000 0.524917044475850413932 0.549736968525204927616 \
+  0.598703757998587549061 0.691456960338383330722 0.841332647834785340990 \
+  0.977236369669282289863 0.998646775905001171658 0.999968100665588499609 \
+  0.999999708483669369485
+pdf.values = \
+  5.4000412160239041892e-02 2.4195862648700797171e-01 \
+  3.5205267468981715773e-01 3.9893230696910769728e-01 \
+  3.9815382510238345182e-01 3.9582748430212794100e-01 \
+  3.8665727967812585364e-01 3.5205267468981715773e-01 \
+  2.4195862648700797171e-01 5.4000412160239041892e-02 \
+  4.4387186123801547488e-03 1.3457758132743024041e-04 \
+  1.5081708994681568206e-06
+sf.values = \
+  9.7723636966928228986e-01 8.4133264783478534099e-01 \
+  6.9145696033838333072e-01 5.0000000000000000000e-01 \
+  4.7508295552414964158e-01 4.5026303147479507238e-01 \
+  4.0129624200141245094e-01 3.0854303966161666928e-01 \
+  1.5866735216521471452e-01 2.2763630330717734424e-02 \
+  1.3532240949988326786e-03 3.1899334411569732234e-05 \
+  2.9151633068313210561e-07
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.8.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.8.properties
new file mode 100644
index 0000000..2e212f6
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.8.properties
@@ -0,0 +1,45 @@
+# 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.
+
+parameters = 1e6
+# Limited by SF values
+tolerance.relative = 4e-15
+mean = 0
+variance = 1.000002000004
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.022750266925659592271 0.158655374916789077000 0.308537593736185833393 \
+  0.500000000000000000000 0.524917662783635718959 0.549738212266906667303 \
+  0.598706300005747316106 0.691462406263814166607 0.841344625083210950756 \
+  0.977249733074340376504 0.998650068729289186464 0.999968326482995051308 \
+  0.999999713300106396474
+pdf.values = \
+  5.3991060997102185981e-02 2.4197060353383154085e-01 \
+  3.5206520024085002918e-01 3.9894218066587505689e-01 \
+  3.9816375636979017827e-01 3.9583758491701903637e-01 \
+  3.8666800843006249311e-01 3.5206520024085002918e-01 \
+  2.4197060353383154085e-01 5.3991060997102185981e-02 \
+  4.4319171056720427920e-03 1.3383768692515205434e-04 \
+  1.4869328706530258966e-06
+sf.values = \
+  9.7724973307434037650e-01 8.4134462508321095076e-01 \
+  6.9146240626381416661e-01 5.0000000000000000000e-01 \
+  4.7508233721636428104e-01 4.5026178773309333270e-01 \
+  4.0129369999425268389e-01 3.0853759373618583339e-01 \
+  1.5865537491678907700e-01 2.2750266925659592271e-02 \
+  1.3499312707108961518e-03 3.1673517005023936119e-05 \
+  2.8669989354453675792e-07
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.9.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.9.properties
new file mode 100644
index 0000000..55c49aa
--- /dev/null
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.9.properties
@@ -0,0 +1,45 @@
+# 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.
+
+parameters = 1e10
+# Limited by SF values
+tolerance.relative = 4e-15
+mean = 0
+variance = 1.0000000002
+# computed using R
+cdf.points = \
+  -2, -1, -0.5, 0, 0.0625, 0.125, 0.25, 0.5, 1, 2, 3, 4, 5
+cdf.values = \
+  0.022750131961676897663 0.158655253943555396567 0.308537538731488258925                                                          \
+  0.500000000000000000000 0.524917669028622579930 0.549738224828856480997                                                          \
+  0.598706325680355866403 0.691462461268511741075 0.841344746056444603433                                                          \
+  0.977249868038323032948 0.998650101965045999819 0.999968328757939395324                                                          \
+  0.999999713348423302506
+pdf.values = \
+  5.3990966522636477110e-02 2.4197072450704482094e-01                                                                              \
+  3.5206532675164714519e-01 3.9894228039145912534e-01                                                                              \
+  3.9816385667685488814e-01 3.9583768693454673970e-01                                                                              \
+  3.8666811679201196217e-01 3.5206532675164714519e-01                                                                              \
+  2.4197072450704482094e-01 5.3990966522636477110e-02                                                                              \
+  4.4318484188073728469e-03 1.3383022651098887756e-04                                                                              \
+  1.4867195360687223494e-06
+sf.values = \
+  9.7724986803832303295e-01 8.4134474605644460343e-01 \
+  6.9146246126851174107e-01 5.0000000000000000000e-01 \
+  4.7508233097137742007e-01 4.5026177517114351900e-01 \
+  4.0129367431964413360e-01 3.0853753873148825893e-01 \
+  1.5865525394355539657e-01 2.2750131961676897663e-02 \
+  1.3498980349539761118e-03 3.1671242060631252789e-05 \
+  2.8665157671103194958e-07

[commons-statistics] 03/03: Add a t-distribution sampler

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit 443ceaa67d48b57c9459c593758ae92a6fdbf8fd
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Jan 24 12:53:10 2022 +0000

    Add a t-distribution sampler
---
 .../statistics/distribution/TDistribution.java     | 101 +++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
index f3b58ca..cd3c2b2 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
@@ -18,6 +18,7 @@ package org.apache.commons.statistics.distribution;
 
 import org.apache.commons.numbers.gamma.RegularizedBeta;
 import org.apache.commons.rng.UniformRandomProvider;
+import java.util.function.DoubleUnaryOperator;
 import org.apache.commons.numbers.gamma.Beta;
 import org.apache.commons.numbers.gamma.LogBeta;
 
@@ -52,6 +53,7 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
      * allowed to provide access to the degrees of freedom used during construction.
      */
     private static class NormalTDistribution extends TDistribution {
+
         /**
          * @param degreesOfFreedom Degrees of freedom.
          */
@@ -226,6 +228,104 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
             // This is intentionally not a public method.
             return 0;
         }
+
+        @Override
+        public Sampler createSampler(UniformRandomProvider rng) {
+            // TODO: Move sampler to Commons RNG
+            return new TSampler(rng, getDegreesOfFreedom());
+        }
+
+        /**
+         * Sampling from a T-distribution.
+         * <blockquote>
+         * Bailey, R. W. (1994)
+         * Polar Generation of Random Variates with the t-Distribution.
+         * Mathematics of Computation 62, 779-781.
+         * </blockquote>
+         * @see <a href="https://doi.org/10.2307/2153537">Mathematics of Computation, 62, 779-781</a>
+         */
+        private static class TSampler implements Sampler {
+            /** Threshold for large degrees of freedom. */
+            private static final double LARGE_DF = 25;
+            /** The multiplier to convert the least significant 53-bits of a {@code long} to a
+             * uniform {@code double}. */
+            private static final double DOUBLE_MULTIPLIER = 0x1.0p-53;
+
+            /** Source of randomness. */
+            private final UniformRandomProvider rng;
+            /** Degrees of freedom. */
+            private final double df;
+            /** Function to compute pow(x, -2/v) - 1, where v = degrees of freedom. */
+            private final DoubleUnaryOperator powm1;
+
+            /**
+             * @param rng Source of randomness.
+             * @param v Degrees of freedom.
+             */
+            TSampler(UniformRandomProvider rng, double v) {
+                this.rng = rng;
+                df = v;
+
+                // The sampler requires pow(w, -2/v) - 1 with
+                // 0 <= w <= 1; Expected(w) = sqrt(0.5).
+                // When the exponent is small then pow(x, y) -> 1.
+                // This affects large degrees of freedom.
+                final double exponent = -2 / v;
+                powm1 = v > LARGE_DF ?
+                    x -> Math.expm1(Math.log(x) * exponent) :
+                    x -> Math.pow(x, exponent) - 1;
+            }
+
+            @Override
+            public double sample() {
+                // Require u and v in [0, 1] and a random sign.
+                // Create u in (0, 1] to avoid generating nan
+                // from u*u/w (0/0) or r2*c2 (inf*0).
+                final double u = makeNonZeroDouble(rng.nextLong());
+                final double v = makeSignedDouble(rng.nextLong());
+                final double w = u * u + v * v;
+                if (w > 1) {
+                    // Rejection frequency = 1 - pi/4 = 0.215.
+                    // Recursion will generate stack overflow given a broken RNG
+                    // and avoids an infinite loop.
+                    return sample();
+                }
+                // Sidestep a square-root calculation.
+                final double c2 = u * u / w;
+                final double r2 = df * powm1.applyAsDouble(w);
+                // Choose sign at random from the sign of v.
+                return Math.copySign(Math.sqrt(r2 * c2), v);
+            }
+
+            /**
+             * Creates a {@code double} in the interval {@code (0, 1]} from a {@code long} value.
+             *
+             * @param v Number.
+             * @return {@code (0, 1]}.
+             */
+            private static double makeNonZeroDouble(long v) {
+                // This matches the method in o.a.c.rng.core.util.NumberFactory.makeDouble(long)
+                // but shifts the range from [0, 1) to (0, 1].
+                return ((v >>> 11) + 1L) * DOUBLE_MULTIPLIER;
+            }
+
+            /**
+             * Creates a signed double in the range {@code [-1, 1)}.
+             *
+             * <p>Note: This method will not return samples for both -0.0 and 0.0.
+             *
+             * @param bits the bits
+             * @return {@code [-1, 1)}.
+             */
+            private static double makeSignedDouble(long bits) {
+                // As per o.a.c.rng.core.utils.NumberFactory.makeDouble(long) but using a signed
+                // shift of 10 in place of an unsigned shift of 11.
+                // Use the upper 54 bits on the assumption they are more random.
+                // The sign bit is maintained by the signed shift.
+                // The next 53 bits generates a magnitude in the range [0, 2^53) or [-2^53, 0).
+                return (bits >> 10) * DOUBLE_MULTIPLIER;
+            }
+        }
     }
 
     /**
@@ -278,6 +378,7 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
         // Exploit symmetry
         return -inverseCumulativeProbability(p);
     }
+
     /**
      * {@inheritDoc}
      *