Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50067 - sandbox/math_toolkit/libs/math/test
From: pbristow_at_[hidden]
Date: 2008-12-02 07:46:59


Author: pbristow
Date: 2008-12-02 07:46:59 EST (Tue, 02 Dec 2008)
New Revision: 50067
URL: http://svn.boost.org/trac/boost/changeset/50067

Log:
Added 50 decimal digit NTL test values - and some TODOs - need a few more values tested, and long double test, and test on convenience typedef
Text files modified:
   sandbox/math_toolkit/libs/math/test/test_laplace.cpp | 223 +++++++++++++++++++++++++++++++++------
   1 files changed, 188 insertions(+), 35 deletions(-)

Modified: sandbox/math_toolkit/libs/math/test/test_laplace.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_laplace.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_laplace.cpp 2008-12-02 07:46:59 EST (Tue, 02 Dec 2008)
@@ -1,4 +1,17 @@
-// Copyright Thijs van den Berg 2007.
+// Copyright Thijs van den Berg, 2008.
+// Copyright John Maddock 2008.
+// Copyright Paul A. Bristow 2008.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// TODO ?? PAB 2 Dec 2008
+
+// add few more tests for farther out than 2??
+// long double test
+// add test for convenience typedef laplace.
+
 /*
 
 This module tests the Laplace distribution.
@@ -37,7 +50,7 @@
          quantile(L,p) == quantile(complement(l,1-p))
 
 Test 7: test_bad_dist_parameters()
- Test invalid dustribution construction.
+ Test invalid distribution construction.
 
 Test 8: test_extreme_function_arguments()
          Test x = +/- inf. for cdf(), pdf()
@@ -51,7 +64,6 @@
 #include <boost/math/distributions/laplace.hpp>
 using boost::math::laplace_distribution;
 
-
 /*
 #include <iostream>
    using std::cout;
@@ -90,6 +102,99 @@
 endfor
 
 fclose(f);
+
+
+Laplace distribution values version 2.0
+
+Using NTL version 5.4 and the formula in Wikipedia Paul A. Bristow
+NTL class RR precision 150 bits.
+NTL class RR output precision 50 decimal digits OK.
+Laplace pdf
+-10 0.22699964881242425767795757780275305118959044437696e-4
+-9.5 0.37425914943850295735594659677277583056493449453316e-4
+-9 0.61704902043339774748818345365016913036076416123496e-4
+-8.5 0.00010173418450532208718446671524353319364865576338509
+-8 0.00016773131395125591941069456289043050965545006686111
+-7.5 0.00027654218507391679155100004426517859890566829114007
+-7 0.00045594098277725810400156804220464131323686226383407
+-6.5 0.00075171959648878622369145166608382691500025647887521
+-6 0.0012393760883331792115225837154083339457532397924584
+-5.5 0.0020433857192320334967323513423603842041953283241185
+-5 0.0033689734995427335483180242115742121244247925136568
+-4.5 0.0055544982691211532480715671434652638857696337503689
+-4 0.0091578194443670901468590106366206211059560337810038
+-3.5 0.015098691711159250369893146181809922535830266119032
+-3 0.024893534183931971489671207825030888315849796096331
+-2.5 0.041042499311949397584764337233579903918902060509316
+-2 0.067667641618306345946999747486242201703815772944649
+-1.5 0.11156508007421491446664023538200626067108581471131
+-1 0.18393972058572116079776188508073043372290556554506
+-0.5 0.30326532985631671180189976749559022672095906778368
+0 0.5
+0.5 0.30326532985631671180189976749559022672095906778368
+1 0.18393972058572116079776188508073043372290556554506
+1.5 0.11156508007421491446664023538200626067108581471131
+2 0.067667641618306345946999747486242201703815772944649
+2.5 0.041042499311949397584764337233579903918902060509316
+3 0.024893534183931971489671207825030888315849796096331
+3.5 0.015098691711159250369893146181809922535830266119032
+4 0.0091578194443670901468590106366206211059560337810038
+4.5 0.0055544982691211532480715671434652638857696337503689
+5 0.0033689734995427335483180242115742121244247925136568
+5.5 0.0020433857192320334967323513423603842041953283241185
+6 0.0012393760883331792115225837154083339457532397924584
+6.5 0.00075171959648878622369145166608382691500025647887521
+7 0.00045594098277725810400156804220464131323686226383407
+7.5 0.00027654218507391679155100004426517859890566829114007
+8 0.00016773131395125591941069456289043050965545006686111
+8.5 0.00010173418450532208718446671524353319364865576338509
+9 0.61704902043339774748818345365016913036076416123496e-4
+9.5 0.37425914943850295735594659677277583056493449453316e-4
+10 0.22699964881242425767795757780275305118959044437696e-4
+
+Laplace cdf
+-10 0.9999773000351187575742322042422197246948810411152
+-9.5 0.99996257408505614970426440534032272241694350636029
+-9 0.99993829509795666022525118165463498308696392404693
+-8.5 0.99989826581549467791281553328475646680635134420916
+-8 0.99983226868604874408058930543710956949034454956485
+-7.5 0.9997234578149260832084489999557348214010943317417
+-7 0.99954405901722274189599843195779535868676313746042
+-6.5 0.99924828040351121377630854833391617308499974328643
+-6 0.99876062391166682078847741628459166605424676032523
+-5.5 0.99795661428076796650326764865763961579580467117776
+-5 0.99663102650045726645168197578842578787557520756024
+-4.5 0.9944455017308788467519284328565347361142303666328
+-4 0.99084218055563290985314098936337937889404396651458
+-3.5 0.98490130828884074963010685381819007746416973359633
+-3 0.9751064658160680285103287921749691116841502037504
+-2.5 0.95895750068805060241523566276642009608109793962206
+-2 0.93233235838169365405300025251375779829618422688019
+-1.5 0.8884349199257850855333597646179937393289141857266
+-1 0.81606027941427883920223811491926956627709443427977
+-0.5 0.69673467014368328819810023250440977327904093221632
+0 0.5
+0.5 0.30326532985631671180189976749559022672095906778368
+1 0.18393972058572116079776188508073043372290556572023
+1.5 0.11156508007421491446664023538200626067108581462372
+2 0.067667641618306345946999747486242201703815773119812
+2.5 0.041042499311949397584764337233579903918902060377944
+3 0.024893534183931971489671207825030888315849796249598
+3.5 0.015098691711159250369893146181809922535830266053346
+4 0.009157819444367090146859010636620621105956033835742
+4.5 0.005554498269121153248071567143465263885769633717526
+5 0.0033689734995427335483180242115742121244247924397602
+5.5 0.0020433857192320334967323513423603842041953284719117
+6 0.0012393760883331792115225837154083339457532396747712
+6.5 0.00075171959648878622369145166608382691500025636324071
+7 0.00045594098277725810400156804220464131323686218925325
+7.5 0.00027654218507391679155100004426517859890566825829713
+8 0.00016773131395125591941069456289043050965545008482209
+8.5 0.00010173418450532208718446671524353319364865579083973
+9 0.61704902043339774748818345365016913036076303396971e-4
+9.5 0.37425914943850295735594659677277583056493289386783e-4
+10 0.22699964881242425767795757780275305118958884798806e-4
+
 */
 template <class RealType>
 void test_pdf_cdf_ocatave()
@@ -97,73 +202,84 @@
    RealType tolerance(1e-10f);
    
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.00000000000000L)),
- static_cast<RealType>(0.06766764161831L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.L)),
+ // static_cast<RealType>(0.06766764161831L),
+ static_cast<RealType>(0.067667641618306345946999747486242201703815773119812L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.00000000000000L)),
- static_cast<RealType>(0.06766764161831L),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(-2.L)),
+ //static_cast<RealType>(0.06766764161831L),
+ static_cast<RealType>(0.067667641618306345946999747486242201703815773119812L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.00000000000000L)),
- static_cast<RealType>(0.18393972058572L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.L)),
+ //static_cast<RealType>(0.18393972058572L),
+ static_cast<RealType>(0.18393972058572116079776188508073043372290556554506L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.00000000000000L)),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(-1.L)),
       static_cast<RealType>(0.18393972058572L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.50000000000000L)),
- static_cast<RealType>(0.30326532985632L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.5L)),
+ // static_cast<RealType>(0.30326532985632L),
+ static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.50000000000000L)),
- static_cast<RealType>(0.30326532985632L),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(-0.5L)),
+ //static_cast<RealType>(0.30326532985632L),
+ static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.00000000000000L)),
- static_cast<RealType>(0.50000000000000L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.0L)),
+ static_cast<RealType>(0.5L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.00000000000000L)),
- static_cast<RealType>(0.50000000000000L),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.0L)),
+ static_cast<RealType>(0.5L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.50000000000000L)),
- static_cast<RealType>(0.30326532985632L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(0.5L)),
+ //static_cast<RealType>(0.30326532985632L),
+ static_cast<RealType>(0.30326532985631671180189976749559022672095906778368L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.50000000000000L)),
- static_cast<RealType>(0.69673467014368L),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(0.5L)),
+ // static_cast<RealType>(0.69673467014368L),
+ static_cast<RealType>(0.69673467014368328819810023250440977327904093221632L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(1.00000000000000L)),
- static_cast<RealType>(0.18393972058572L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(1.0L)),
+ // static_cast<RealType>(0.18393972058572L),
+ static_cast<RealType>(0.18393972058572116079776188508073043372290556554506L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
       cdf(laplace_distribution<RealType>(), static_cast<RealType>(1.00000000000000L)),
- static_cast<RealType>(0.81606027941428L),
+ // static_cast<RealType>(0.81606027941428L),
+ static_cast<RealType>(0.81606027941427883920223811491926956627709443427977L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- pdf(laplace_distribution<RealType>(), static_cast<RealType>(2.00000000000000L)),
- static_cast<RealType>(0.06766764161831L),
+ pdf(laplace_distribution<RealType>(), static_cast<RealType>(2.0L)),
+ // static_cast<RealType>(0.06766764161831L),
+ static_cast<RealType>(0.067667641618306345946999747486242201703815772944649L),
    tolerance);
 
    BOOST_CHECK_CLOSE(
- cdf(laplace_distribution<RealType>(), static_cast<RealType>(2.00000000000000L)),
- static_cast<RealType>(0.93233235838169L),
+ cdf(laplace_distribution<RealType>(), static_cast<RealType>(2.0L)),
+ // static_cast<RealType>(0.93233235838169L),
+ static_cast<RealType>(0.93233235838169365405300025251375779829618422688019L),
    tolerance);
 }
 
@@ -237,7 +353,7 @@
 {
    RealType tolerance(boost::math::tools::epsilon<RealType>() * 500); // 5 eps as a percentage
 
- const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
+ // const float xtest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
    const float ltest[7] = { -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0 };
    const float stest[3] = { 0.5, 1.0, 2.0 };
 
@@ -245,7 +361,7 @@
       for (int li=0; li<7; ++li)
               for (int si=0; si<3; ++si)
          {
- RealType x( static_cast<RealType>(xtest[xi]) );
+ //RealType x( static_cast<RealType>(xtest[xi]) );
             RealType l( static_cast<RealType>(ltest[li]) );
             RealType s( static_cast<RealType>(stest[si]) );
 
@@ -362,9 +478,6 @@
 }
 
 
-
-
-
 BOOST_AUTO_TEST_CASE( vs_GNU_Octave )
 {
    test_pdf_cdf_ocatave<float>();
@@ -415,4 +528,44 @@
 {
    test_extreme_function_arguments<float>();
    test_extreme_function_arguments<double>();
-}
\ No newline at end of file
+}
+
+/*
+
+Output:
+
+Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM
+
+Debug Multi-threaded Debug (/MTd)
+
+Running 8 test cases...
+
+*** No errors detected
+Detected memory leaks!
+Dumping objects ->
+{286} normal block at 0x001E92D8, 7 bytes long.
+ Data: <double > 64 6F 75 62 6C 65 00
+{285} normal block at 0x001E92A0, 8 bytes long.
+ Data: < 0 > D8 92 1E 00 30 92 1E 00
+{230} normal block at 0x001E9268, 6 bytes long.
+ Data: <float > 66 6C 6F 61 74 00
+{229} normal block at 0x001E9230, 8 bytes long.
+ Data: <h > 68 92 1E 00 00 00 00 00
+Object dump complete.
+Press any key to continue . . .
+
+// Why does debug cause memory leak? Problem in Boost.Test - no - MS debug VC9 runtime
+// http://www.nabble.com/Re%3A--Boost.Test--Problem-with-vc9-runtime-library-p17864724.html
+// so we can ignore this.
+
+
+Release Multi-threaded (/MT)
+
+Running 8 test cases...
+
+*** No errors detected
+Press any key to continue . . .
+
+
+*/
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk