1[section:cauchy_dist Cauchy-Lorentz Distribution] 2 3``#include <boost/math/distributions/cauchy.hpp>`` 4 5 template <class RealType = double, 6 class ``__Policy`` = ``__policy_class`` > 7 class cauchy_distribution; 8 9 typedef cauchy_distribution<> cauchy; 10 11 template <class RealType, class ``__Policy``> 12 class cauchy_distribution 13 { 14 public: 15 typedef RealType value_type; 16 typedef Policy policy_type; 17 18 cauchy_distribution(RealType location = 0, RealType scale = 1); 19 20 RealType location()const; 21 RealType scale()const; 22 }; 23 24The [@http://en.wikipedia.org/wiki/Cauchy_distribution Cauchy-Lorentz distribution] 25is named after Augustin Cauchy and Hendrik Lorentz. 26It is a [@http://en.wikipedia.org/wiki/Probability_distribution continuous probability distribution] 27with [@http://en.wikipedia.org/wiki/Probability_distribution probability distribution function PDF] 28given by: 29 30[equation cauchy_ref1] 31 32The location parameter ['x[sub 0]] is the location of the 33peak of the distribution (the mode of the distribution), 34while the scale parameter [gamma] specifies half the width 35of the PDF at half the maximum height. If the location is 36zero, and the scale 1, then the result is a standard Cauchy 37distribution. 38 39The distribution is important in physics as it is the solution 40to the differential equation describing forced resonance, 41while in spectroscopy it is the description of the line shape 42of spectral lines. 43 44The following graph shows how the distributions moves as the 45location parameter changes: 46 47[graph cauchy_pdf1] 48 49While the following graph shows how the shape (scale) parameter alters 50the distribution: 51 52[graph cauchy_pdf2] 53 54[h4 Member Functions] 55 56 cauchy_distribution(RealType location = 0, RealType scale = 1); 57 58Constructs a Cauchy distribution, with location parameter /location/ 59and scale parameter /scale/. When these parameters take their default 60values (location = 0, scale = 1) 61then the result is a Standard Cauchy Distribution. 62 63Requires scale > 0, otherwise calls __domain_error. 64 65 RealType location()const; 66 67Returns the location parameter of the distribution. 68 69 RealType scale()const; 70 71Returns the scale parameter of the distribution. 72 73[h4 Non-member Accessors] 74 75All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] 76that are generic to all distributions are supported: __usual_accessors. 77 78Note however that the Cauchy distribution does not have a mean, 79standard deviation, etc. See __math_undefined 80[/link math_toolkit.pol_ref.assert_undefined mathematically undefined function] 81to control whether these should fail to compile with a BOOST_STATIC_ASSERTION_FAILURE, 82which is the default. 83 84Alternately, the functions __mean, __sd, 85__variance, __skewness, __kurtosis and __kurtosis_excess will all 86return a __domain_error if called. 87 88The domain of the random variable is \[-[max_value], +[min_value]\]. 89 90[h4 Accuracy] 91 92The Cauchy distribution is implemented in terms of the 93standard library `tan` and `atan` functions, 94and as such should have very low error rates. 95 96[h4 Implementation] 97 98[def __x0 x[sub 0 ]] 99 100In the following table __x0 is the location parameter of the distribution, 101[gamma] is its scale parameter, 102/x/ is the random variate, /p/ is the probability and /q = 1-p/. 103 104[table 105[[Function][Implementation Notes]] 106[[pdf][Using the relation: ['pdf = 1 / ([pi] * [gamma] * (1 + ((x - __x0) / [gamma])[super 2]) ]]] 107[[cdf and its complement][ 108The cdf is normally given by: 109 110[expression p = 0.5 + atan(x)/[pi]] 111 112But that suffers from cancellation error as x -> -[infin]. 113So recall that for `x < 0`: 114 115[expression atan(x) = -[pi]/2 - atan(1/x)] 116 117Substituting into the above we get: 118 119[expression p = -atan(1/x) ; x < 0] 120 121So the procedure is to calculate the cdf for -fabs(x) 122using the above formula. Note that to factor in the location and scale 123parameters you must substitute (x - __x0) / [gamma] for x in the above. 124 125This procedure yields the smaller of /p/ and /q/, so the result 126may need subtracting from 1 depending on whether we want the complement 127or not, and whether /x/ is less than __x0 or not. 128]] 129[[quantile][The same procedure is used irrespective of whether we're starting 130 from the probability or its complement. First the argument /p/ is 131 reduced to the range \[-0.5, 0.5\], then the relation 132 133[expression x = __x0 [plusminus] [gamma] / tan([pi] * p)] 134 135is used to obtain the result. Whether we're adding 136 or subtracting from __x0 is determined by whether we're 137 starting from the complement or not.]] 138[[mode][The location parameter.]] 139] 140 141[h4 References] 142 143* [@http://en.wikipedia.org/wiki/Cauchy_distribution Cauchy-Lorentz distribution] 144* [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm NIST Exploratory Data Analysis] 145* [@http://mathworld.wolfram.com/CauchyDistribution.html Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A Wolfram Web Resource.] 146 147[endsect][/section:cauchy_dist Cauchy] 148 149[/ cauchy.qbk 150 Copyright 2006, 2007 John Maddock and Paul A. Bristow. 151 Distributed under the Boost Software License, Version 1.0. 152 (See accompanying file LICENSE_1_0.txt or copy at 153 http://www.boost.org/LICENSE_1_0.txt). 154] 155