Ticket #7177 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

Students t returns rubbihs values for undefined input instead of throw

Reported by: pbristow Owned by: pbristow
Milestone: Boost 1.52.0 Component: math
Version: Boost Development Trunk Severity: Problem
Keywords: math students t Cc:


Reported by Thomas Mang

According to the documentation, in boost 1-50 non-member functions of moments (e.g. mean, variance) which are not defined for a given distribution shall issue compile-time errors, or throw a domain_error at runtime otherwise. For the Cauchy Distribution, that's what it does. For the t-distribution, that's not what it does - the non-member functions happily return some complete rubbish values for mean and variance (and hence I'd also suppose standard deviation). For kurtosis and skewness it seems to work correctly but are subject to mathematical definitions. I have not tested other non-member functions.

typedef boost::math::students_t_distribution<double> t_distr;

this is ok std::cout << "mean(t(2)): " << boost::math::mean( t_distr(2) ) << std::endl;

this is NOT ok - first moment not defined for given distribution std::cout << "mean(t(1)): " << boost::math::mean( t_distr(1) ) << std::endl;

this is ok std::cout << "var(t(3)): " << boost::math::variance( t_distr(3) ) << std::endl;

this might be ok or not depending on point of view, either Inf or undefined std::cout << "var(t(2)): " << boost::math::variance( t_distr(2) ) << std::endl;

this is NOT ok - second moment not defined for the given distribution std::cout << "var(t(1)): " << boost::math::variance( t_distr(1) ) << std::endl;


Change History

comment:1 Changed 5 years ago by pbristow

  • Status changed from new to closed
  • Version changed from Boost 1.50.0 to Boost Development Trunk
  • Resolution set to fixed

After much discussion, we decided to make all moments when df =< moment index k throw domain error (and return NaN is the throw is ignored by a policy).

Sources are unclear on this, Wikipedia claiming variance should be ∞ for 1 < \nu ≤ 2, etc. but this probably only applies if df is integral and this package allows real values.

And no practical use of having a return of infinity rather than NaN was proposed.

So, in the absence of a good case, we have Kept It Simple Sirs and returned quiet_NaN.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.