Boost logo

Boost Users :

Subject: Re: [Boost-users] [math/distributions] invalid values for undefined moments
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2012-07-26 04:16:24


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf
Of
> Thomas Mang
> Sent: Thursday, July 26, 2012 12:52 AM
> To: boost-users_at_[hidden]
> Subject: [Boost-users] [math/distributions] invalid values for undefined moments
>
> Hi,
>
> 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.
>
> Note that there are different definitions floating around as to when a given moment is defined.
The k-th
> moment is always defined if k < v, but in other cases opinions deviate. Wikipedia states it might
be infinity
> under some circumstances - obviously what boost seems to having taken over. In general however I
am
> used to - and my gut feeling the clear majority of people would have this perception; indeed I am
not
> aware of any other source than wikipedia stating these infinity things - that moments are
undefined if k >=
> v (see e.g. Probability and Statistics, DeGroot & Schervish 2002, for a professional textbooks and
heaps of
> other sources).
> So while the boost output for variance and a t-2 distribution (or alternatively also the kurtosis
of a t-4
> distribution) might be considered ok by some, I'd guess to most people it would be fairly
unexpected? It
> had been a surprise to me, at least.
>
>
> Code snippet:
>
>
> 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;

Looks like a buglet and will investigate soon.

https://svn.boost.org/trac/boost/ticket/7177

Paul


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net