Opened 5 years ago

Closed 5 years ago

## #7177 closed Bugs (fixed)

# Students t returns rubbihs values for undefined input instead of throw

Reported by: | Paul A. Bristow | Owned by: | Paul A. Bristow |
---|---|---|---|

Milestone: | Boost 1.52.0 | Component: | math |

Version: | Boost Development Trunk | Severity: | Problem |

Keywords: | math students t | Cc: |

### Description

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;
*

### Attachments (0)

### Change History (1)

### comment:1 Changed 5 years ago by

Resolution: | → fixed |
---|---|

Status: | new → closed |

Version: | Boost 1.50.0 → Boost Development Trunk |

**Note:**See TracTickets for help on using tickets.

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.