...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/distributions/logistic.hpp>
namespace boost{ namespace math{ template <class RealType = double, class Policy = policies::policy<> > class logistic_distribution; template <class RealType, class Policy> class logistic_distribution { public: typedef RealType value_type; typedef Policy policy_type; // Construct: BOOST_MATH_GPU_ENABLED logistic_distribution(RealType location = 0, RealType scale = 1); // Accessors: BOOST_MATH_GPU_ENABLED RealType location()const; // location. BOOST_MATH_GPU_ENABLED RealType scale()const; // scale. }; typedef logistic_distribution<> logistic; }} // namespaces
The logistic distribution is a continuous probability distribution. It has two parameters - location and scale. The cumulative distribution function of the logistic distribution appears in logistic regression and feedforward neural networks. Among other applications, United State Chess Federation and FIDE use it to calculate chess ratings.
The following graph shows how the distribution changes as the parameters change:
BOOST_MATH_GPU_ENABLED logistic_distribution(RealType u = 0, RealType s = 1);
Constructs a logistic distribution with location u and scale s.
Requires scale >
0
, otherwise a domain_error
is raised.
BOOST_MATH_GPU_ENABLED RealType location()const;
Returns the location of this distribution.
BOOST_MATH_GPU_ENABLED RealType scale()const;
Returns the scale of this distribution.
All the usual non-member accessor
functions that are generic to all distributions are supported:
Cumulative Distribution Function,
Probability Density Function,
Quantile, Hazard Function, Cumulative Hazard Function,
__logcdf, __logpdf, mean,
median, mode,
variance, standard deviation, skewness, kurtosis,
kurtosis_excess,
range and support. For this distribution
all non-member accessor functions are marked with BOOST_MATH_GPU_ENABLED
and can be run on both host and device.
The domain of the random variable is [-[max_value], +[min_value]]. However, the pdf and cdf support inputs of +∞ and -∞ as special cases if RealType permits.
At p=1
and p=0
, the quantile
function returns the result of +overflow_error
and -overflow_error,
while the complement quantile function returns the result of -overflow_error
and +overflow_error
respectively.
In this distribution the implementation of logcdf
is specialized to improve numerical accuracy.
The logistic distribution is implemented in terms of the std::exp
and the std::log
functions, so its accuracy is related to the accurate implementations of
those functions on a given platform. When calculating the quantile with
a non-zero position parameter catastrophic cancellation
errors can occur: in such cases, only a low absolute error
can be guaranteed.
Function |
Implementation Notes |
---|---|
|
Using the relation: pdf = e-(x-u)/s / (s*(1+e-(x-u)/s)2) |
cdf |
Using the relation: p = 1/(1+e-(x-u)/s) |
logcdf |
log(cdf) = -log1p(exp((u-x)/s)) |
cdf complement |
Using the relation: q = 1/(1+e(x-u)/s) |
quantile |
Using the relation: x = u - s*log(1/p-1) |
quantile from the complement |
Using the relation: x = u + s*log(p/1-p) |
mean |
u |
mode |
The same as the mean. |
skewness |
0 |
kurtosis excess |
6/5 |
variance |
(π*s)2 / 3 |