Subject: [Boost-bugs] [Boost C++ Libraries] #9672: PDF and CDF of a laplace distribution throwing domain_error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-02-17 06:36:01
#9672: PDF and CDF of a laplace distribution throwing domain_error
-------------------------------------+-------------------------
Reporter: HS <tan@â¦> | Owner: johnmaddock
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: math
Version: Boost Development Trunk | Severity: Showstopper
Keywords: |
-------------------------------------+-------------------------
Hello,
I would expect the following to behave just like a normal distribution (or
a cauchy distribution) at x=+-infinity:
{{{
// #define BOOST_MATH_DOMAIN_ERROR_POLICY ignore_error
#include <cstdlib>
#include <cstdio>
#include <limits>
#include <boost/math/distributions/cauchy.hpp>
#include <boost/math/distributions/laplace.hpp>
#include <boost/math/distributions/normal.hpp>
static const double INFTY = std::numeric_limits< double >::infinity();
template< typename T >
void TestBoundary( const char* distName, const T& t )
{
std::printf(
"%15s ---------------------\n"
"%15s %'*g %'*g\n",
distName,
"pdf",
boost::math::pdf( t, -INFTY ), 10,
boost::math::pdf( t, INFTY ), 10 );
std::printf(
"%15s %'*g %'*g\n",
"cdf",
boost::math::cdf( t, -INFTY ), 10,
boost::math::cdf( t, INFTY ), 10 );
std::printf(
"%15s %'*g %'*g\n",
"co-cdf",
boost::math::cdf( boost::math::complement( t, -INFTY ) ), 10,
boost::math::cdf( boost::math::complement( t, INFTY ) ), 10 );
};
int main()
{
std::printf(
"%15s %10s %10s\n",
"Distribution",
"x=-infty",
"x=+infty" );
double _location = 3.2;
double _scale = 0.7;
/*
TestBoundary(
"Normal",
boost::math::normal_distribution<>( _location, _scale ) );
TestBoundary(
"Cauchy",
boost::math::cauchy_distribution<>( _location, _scale ) );
*/
// To NOT throw domain_error exception at infinity?
TestBoundary(
"Laplace",
boost::math::laplace_distribution<>( _location, _scale ) );
return EXIT_SUCCESS;
}
}}}
Simply compile with "g++ filename.cpp" and obtain the following when the
resulting executable is ran:
{{{
terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::domain_error>
>'
what(): Error in function boost::math::pdf(const
laplace_distribution<d>&, d)): Random variate x is inf, but must be
finite!
Abort
}}}
If a random variable is documented to have a domain [-infty,
+infty]---notice the closed interval, does it mean that the implementation
will honor it (in that it would return the valid PDF or CDF at any value
of the domain)---see the line above the graph of the PDF on
http://www.boost.org/doc/libs/1_55_0/libs/math/doc/html/math_toolkit/dist_ref/dists/laplace_dist.html;
I assumed it meant to say the "domain of the random variable" instead of
"the range of the random variable" (the last expression under ''Non-member
Accessors'' paragraph has it right).
Thank you.[[br]]
HS
P.S. The following is from "git log -2" inside libs/math:
{{{
commit ec438ff39d855f810e236dbaf14b8755f7157869
Author: Beman <bdawes_at_[hidden]>
Date: Sun Dec 1 09:14:12 2013 -0500
End-of-line normalization. Most normalization was taken care of by
.gitattributes, but a few files originally committed to svn with incorrect
eol tags need explicit normalization. See .gitattributes man page and
extensive list discussion.
commit fb52d2de42ff7e1cbc61103a25fbc82c5e034a90
Author: John Maddock <john_at_[hidden]>
Date: Thu Oct 24 08:35:41 2013 +0000
Fix initialization of power series so that we don't get a spurious
overflow error from tgamma when the res
ult is actually zero.
[SVN r86415]
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9672> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC