
Paul A. Bristow wrote:
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org]
On
Behalf Of Thijs van den Berg Sent: 28 November 2008 13:58 To: boost@lists.boost.org Subject: Re: [boost] [math distributions] Laplace distribution
I've done a first commit to the sandbox!
1) sandbox\math_toolkit\boost\math\distributions\laplace.cpp 2) sandbox\math_toolkit\libs\math\test\test_laplace.cpp
..more later! (doc's, equations, charts, discussion)
The unit test file was (is) quite a lot of work, ..there are *so many*
things to consider/check.
;-))
How about this: We could write some generic test based on the properties of
distributions...
General relations: 1) quantile(cdf(x)) == x 2) hazard(x) = pdf(x)/(1-cdf(x)) 3) pdf(x,location,scale) = pdf( (x-location)/scale, 0, 1)/scale 4) cdf(x,location,scale) = cdf( (x-location)/scale, 0, 1) 5) cdf(complement(N,x)) = cdf(N(-x)) 6) quantile(complement(N,p)) = quantile(N(-x,1-p))
perhaps some automatic checking (for all distribution) of error throwing 7) support <-> cdf, pdf 8) quantile <-> p=0, p=1
And some generic test for distributions with specific properties Symmetric distributions: pdf(x) = pdf(-x) cdf(x) = 1-cdf(-x)
etc. we could write template functions for that, that get passed a set of 'x'
values etc
That would indeed be neat - but our tests just grew like Topsy ;-)
And it would be quite a lot of work to change now.
I also worry that the acceptable tolerances vary widely, so you would have keep passing these as parameters anyway.
We also (still are) a bit schizophrenic about whether to allow infinity as parameter, so a uniform test to check throw would be difficult.
great idea. We could make an orthogonal unit test, testing all distributions for this specific case
I note you haven't tried to deal with the long double case. Even if your system like my MSVC only does double == long double 64 bit reals, we should have the hooks in place for systems that do proper long doubles.
This rather messy code does this, if appropriate.
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_spots(0.0L); // Test long double. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0582)) test_spots(boost::math::concepts::real_concept(0.)); // Test real concept. #endif #else std::cout << "<note>The long double tests have been disabled on this platform " "either because the long double overloads of the usual math functions are " "not available at all, or because they are too inaccurate for these tests " "to pass.</note>" << std::cout; #endif
thanks! I'll include this.
At least a few really accurate values could be calculated using the published formula using a 100 decimal digit calculator? But round tripping should test well and I don't expect any trouble for higher precision types (in the unlikely event that someone want them - no accounting for some peoples taste).
I found it quite difficult to find reference matireal. Enough references to equations, but very little reference to numerical values. The only benchmark tool I have that implements Laplace is GNU Octave. I found that Mathematica also has the Laplace distribution . Some high precision numerical values generated by Mathematics would be very welcome!
(I wonder if we can get rid of the Borland test yet?)
You might also check the convenience typedef works like this?
// Check that can generate lognormal distribution using the two convenience methods: boost::math::lognormal myf1(1., 2); // Using typedef lognormal_distribution<> myf2(1., 2); // Using default RealType double.
Yes, those should also be checked.
http://mathworld.wolfram.com/LaplaceDistribution.html is a good link for the doc? Weisstein, Eric W. "Laplace Distribution." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/LaplaceDistribution.html
<aside> (This looks rather amusing http://demonstrations.wolfram.com/SampleVersusTheoreticalDistribution/). </aside>
Looking good to me.
Paul
PS You can write
2. 1., , 0.5, 0.25... without the L because they can be exactly represented as float, double, long double (unlike 0.1, 0.01... )
nice!
static_cast<RealType>(0.5)
which saves some typing and clutter.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- SITMO Quantitative Financial Consultancy - Software Development M.A. (Thijs) van den Berg Tel.+31 (0)6 2411 0061 Fax.+31 (0)15 285 1984 thijs@sitmo.com <mailto:thijs@sitmo.com> - www.sitmo.com <http://www.sitmo.com>