• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Arcsine Distribution</title>
5<link rel="stylesheet" href="../../../math.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Math Toolkit 2.12.0">
8<link rel="up" href="../dists.html" title="Distributions">
9<link rel="prev" href="../dists.html" title="Distributions">
10<link rel="next" href="bernoulli_dist.html" title="Bernoulli Distribution">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../dists.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bernoulli_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="math_toolkit.dist_ref.dists.arcine_dist"></a><a class="link" href="arcine_dist.html" title="Arcsine Distribution">Arcsine Distribution</a>
28</h4></div></div></div>
29<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">arcsine</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
30<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
31
32 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
33           <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a>   <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy&lt;&gt;</a> <span class="special">&gt;</span>
34<span class="keyword">class</span> <span class="identifier">arcsine_distribution</span><span class="special">;</span>
35
36<span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span> <span class="comment">// double precision standard arcsine distribution [0,1].</span>
37
38<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
39<span class="keyword">class</span> <span class="identifier">arcsine_distribution</span>
40<span class="special">{</span>
41<span class="keyword">public</span><span class="special">:</span>
42   <span class="keyword">typedef</span> <span class="identifier">RealType</span>  <span class="identifier">value_type</span><span class="special">;</span>
43   <span class="keyword">typedef</span> <span class="identifier">Policy</span>    <span class="identifier">policy_type</span><span class="special">;</span>
44
45   <span class="comment">// Constructor from two range parameters, x_min and x_max:</span>
46   <span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">);</span>
47
48   <span class="comment">// Range Parameter accessors:</span>
49   <span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
50   <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
51<span class="special">};</span>
52<span class="special">}}</span> <span class="comment">// namespaces</span>
53</pre>
54<p>
55          The class type <code class="computeroutput"><span class="identifier">arcsine_distribution</span></code>
56          represents an <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine</a>
57          <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
58          distribution function</a>. The arcsine distribution is named because
59          its CDF uses the inverse sin<sup>-1</sup> or arcsine.
60        </p>
61<p>
62          This is implemented as a generalized version with support from <span class="emphasis"><em>x_min</em></span>
63          to <span class="emphasis"><em>x_max</em></span> providing the 'standard arcsine distribution'
64          as default with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max = 1</em></span>.
65          (A few make other choices for 'standard').
66        </p>
67<p>
68          The arcsine distribution is generalized to include any bounded support
69          <span class="emphasis"><em>a &lt;= x &lt;= b</em></span> by <a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram</a>
70          and <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia</a>,
71          but also using <span class="emphasis"><em>location</em></span> and <span class="emphasis"><em>scale</em></span>
72          parameters by <a href="http://www.math.uah.edu/stat/index.html" target="_top">Virtual
73          Laboratories in Probability and Statistics</a> <a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">Arcsine
74          distribution</a>. The end-point version is simpler and more obvious,
75          so we implement that. If desired, <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">this</a>
76          outlines how the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
77          Distribution</a> can be used to add a shape factor.
78        </p>
79<p>
80          The <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
81          density function PDF</a> for the <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine
82          distribution</a> defined on the interval [<span class="emphasis"><em>x_min, x_max</em></span>]
83          is given by:
84        </p>
85<div class="blockquote"><blockquote class="blockquote"><p>
86            <span class="serif_italic">f(x; x_min, x_max) = 1 /(π⋅√((x - x_min)⋅(x_max
87            - x_min))</span>
88          </p></blockquote></div>
89<p>
90          For example, <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
91          arcsine distribution, from input of
92        </p>
93<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
94</pre>
95<p>
96          computes the PDF value
97        </p>
98<pre class="programlisting"><span class="number">0.63661977236758134307553505349005744813783858296183</span>
99</pre>
100<p>
101          The Probability Density Functions (PDF) of generalized arcsine distributions
102          are symmetric U-shaped curves, centered on <span class="emphasis"><em>(x_max - x_min)/2</em></span>,
103          highest (infinite) near the two extrema, and quite flat over the central
104          region.
105        </p>
106<p>
107          If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span>
108          or <span class="emphasis"><em>x_max</em></span>, then the PDF is infinity. If random variate
109          <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span> then the CDF is zero.
110          If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_max</em></span>
111          then the CDF is unity.
112        </p>
113<p>
114          The 'Standard' (0, 1) arcsine distribution is shown in blue and some generalized
115          examples with other <span class="emphasis"><em>x</em></span> ranges.
116        </p>
117<div class="blockquote"><blockquote class="blockquote"><p>
118            <span class="inlinemediaobject"><img src="../../../../graphs/arcsine_pdf.svg" align="middle"></span>
119
120          </p></blockquote></div>
121<p>
122          The Cumulative Distribution Function CDF is defined as
123        </p>
124<div class="blockquote"><blockquote class="blockquote"><p>
125            <span class="serif_italic">F(x) = 2⋅arcsin(√((x-x_min)/(x_max - x))) /
126            π</span>
127          </p></blockquote></div>
128<div class="blockquote"><blockquote class="blockquote"><p>
129            <span class="inlinemediaobject"><img src="../../../../graphs/arcsine_cdf.svg" align="middle"></span>
130
131          </p></blockquote></div>
132<h6>
133<a name="math_toolkit.dist_ref.dists.arcine_dist.h0"></a>
134          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.constructor"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.constructor">Constructor</a>
135        </h6>
136<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">);</span>
137</pre>
138<p>
139          constructs an arcsine distribution with range parameters <span class="emphasis"><em>x_min</em></span>
140          and <span class="emphasis"><em>x_max</em></span>.
141        </p>
142<p>
143          Requires <span class="emphasis"><em>x_min &lt; x_max</em></span>, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
144          is called.
145        </p>
146<p>
147          For example:
148        </p>
149<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">myarcsine</span><span class="special">(-</span><span class="number">2</span><span class="special">,</span> <span class="number">4</span><span class="special">);</span>
150</pre>
151<p>
152          constructs an arcsine distribution with <span class="emphasis"><em>x_min = -2</em></span>
153          and <span class="emphasis"><em>x_max = 4</em></span>.
154        </p>
155<p>
156          Default values of <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max =
157          1</em></span> and a <code class="computeroutput"> <span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span></code>
158          mean that
159        </p>
160<pre class="programlisting"><span class="identifier">arcsine</span> <span class="identifier">as</span><span class="special">;</span>
161</pre>
162<p>
163          constructs a 'Standard 01' arcsine distribution.
164        </p>
165<h6>
166<a name="math_toolkit.dist_ref.dists.arcine_dist.h1"></a>
167          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors">Parameter
168          Accessors</a>
169        </h6>
170<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
171<span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
172</pre>
173<p>
174          Return the parameter <span class="emphasis"><em>x_min</em></span> or <span class="emphasis"><em>x_max</em></span>
175          from which this distribution was constructed.
176        </p>
177<p>
178          So, for example:
179        </p>
180<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">arcsine_distribution</span><span class="special">;</span>
181
182<span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">as</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span> <span class="comment">// Constructs a double arcsine distribution.</span>
183<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_min</span><span class="special">()</span> <span class="special">==</span> <span class="number">2.</span><span class="special">);</span>  <span class="comment">// as.x_min() returns 2.</span>
184<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_max</span><span class="special">()</span> <span class="special">==</span> <span class="number">5.</span><span class="special">);</span>   <span class="comment">// as.x_max()  returns 5.</span>
185</pre>
186<h5>
187<a name="math_toolkit.dist_ref.dists.arcine_dist.h2"></a>
188          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions">Non-member
189          Accessor Functions</a>
190        </h5>
191<p>
192          All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
193          functions</a> that are generic to all distributions are supported:
194          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
195          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
196          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
197          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>,
198          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
199          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
200          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
201          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
202        </p>
203<p>
204          The formulae for calculating these are shown in the table below, and at
205          <a href="http://mathworld.wolfram.com/arcsineDistribution.html" target="_top">Wolfram
206          Mathworld</a>.
207        </p>
208<div class="note"><table border="0" summary="Note">
209<tr>
210<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
211<th align="left">Note</th>
212</tr>
213<tr><td align="left" valign="top"><p>
214            There are always <span class="bold"><strong>two</strong></span> values for the
215            <span class="bold"><strong>mode</strong></span>, at <span class="emphasis"><em>x_min</em></span>
216            and at <span class="emphasis"><em>x_max</em></span>, default 0 and 1, so instead we raise
217            the exception <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
218            At these extrema, the PDFs are infinite, and the CDFs zero or unity.
219          </p></td></tr>
220</table></div>
221<h5>
222<a name="math_toolkit.dist_ref.dists.arcine_dist.h3"></a>
223          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.applications"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.applications">Applications</a>
224        </h5>
225<p>
226          The arcsine distribution is useful to describe <a href="http://en.wikipedia.org/wiki/Random_walk" target="_top">Random
227          walks</a>, (including drunken walks) <a href="http://en.wikipedia.org/wiki/Brownian_motion" target="_top">Brownian
228          motion</a>, <a href="http://en.wikipedia.org/wiki/Wiener_process" target="_top">Weiner
229          processes</a>, <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
230          trials</a>, and their application to solve stock market and other
231          <a href="http://en.wikipedia.org/wiki/Gambler%27s_ruin" target="_top">ruinous gambling
232          games</a>.
233        </p>
234<p>
235          The random variate <span class="emphasis"><em>x</em></span> is constrained to <span class="emphasis"><em>x_min</em></span>
236          and <span class="emphasis"><em>x_max</em></span>, (for our 'standard' distribution, 0 and
237          1), and is usually some fraction. For any other <span class="emphasis"><em>x_min</em></span>
238          and <span class="emphasis"><em>x_max</em></span> a fraction can be obtained from <span class="emphasis"><em>x</em></span>
239          using
240        </p>
241<div class="blockquote"><blockquote class="blockquote"><p>
242            <span class="serif_italic">fraction = (x - x_min) / (x_max - x_min)</span>
243          </p></blockquote></div>
244<p>
245          The simplest example is tossing heads and tails with a fair coin and modelling
246          the risk of losing, or winning. Walkers (molecules, drunks...) moving left
247          or right of a centre line are another common example.
248        </p>
249<p>
250          The random variate <span class="emphasis"><em>x</em></span> is the fraction of time spent
251          on the 'winning' side. If half the time is spent on the 'winning' side
252          (and so the other half on the 'losing' side) then <span class="emphasis"><em>x = 1/2</em></span>.
253        </p>
254<p>
255          For large numbers of tosses, this is modelled by the (standard [0,1]) arcsine
256          distribution, and the PDF can be calculated thus:
257        </p>
258<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.637</span>
259<span class="comment">// pdf has a minimum at x = 0.5</span>
260</pre>
261<p>
262          From the plot of PDF, it is clear that <span class="emphasis"><em>x</em></span> = ½ is the
263          <span class="bold"><strong>minimum</strong></span> of the curve, so this is the
264          <span class="bold"><strong>least likely</strong></span> scenario. (This is highly
265          counter-intuitive, considering that fair tosses must <span class="bold"><strong>eventually</strong></span>
266          become equal. It turns out that <span class="emphasis"><em>eventually</em></span> is not
267          just very long, but <span class="bold"><strong>infinite</strong></span>!).
268        </p>
269<p>
270          The <span class="bold"><strong>most likely</strong></span> scenarios are towards
271          the extrema where <span class="emphasis"><em>x</em></span> = 0 or <span class="emphasis"><em>x</em></span>
272          = 1.
273        </p>
274<p>
275          If fraction of time on the left is a ¼, it is only slightly more likely
276          because the curve is quite flat bottomed.
277        </p>
278<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">4</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.735</span>
279</pre>
280<p>
281          If we consider fair coin-tossing games being played for 100 days (hypothetically
282          continuously to be 'at-limit') the person winning after day 5 will not
283          change in fraction 0.144 of the cases.
284        </p>
285<p>
286          We can easily compute this setting <span class="emphasis"><em>x</em></span> = 5./100 = 0.05
287        </p>
288<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.05</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.144</span>
289</pre>
290<p>
291          Similarly, we can compute from a fraction of 0.05 /2 = 0.025 (halved because
292          we are considering both winners and losers) corresponding to 1 - 0.025
293          or 97.5% of the gamblers, (walkers, particles...) on the <span class="bold"><strong>same
294          side</strong></span> of the origin
295        </p>
296<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.975</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
297</pre>
298<p>
299          (use of the complement gives a bit more clarity, and avoids potential loss
300          of accuracy when <span class="emphasis"><em>x</em></span> is close to unity, see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
301          complements?</a>).
302        </p>
303<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.975</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
304</pre>
305<p>
306          or we can reverse the calculation by assuming a fraction of time on one
307          side, say fraction 0.2,
308        </p>
309<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">//  0.976</span>
310
311<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.976</span>
312</pre>
313<p>
314          <span class="bold"><strong>Summary</strong></span>: Every time we toss, the odds
315          are equal, so on average we have the same change of winning and losing.
316        </p>
317<p>
318          But this is <span class="bold"><strong>not true</strong></span> for an an individual
319          game where one will be <span class="bold"><strong>mostly in a bad or good patch</strong></span>.
320        </p>
321<p>
322          This is quite counter-intuitive to most people, but the mathematics is
323          clear, and gamblers continue to provide proof.
324        </p>
325<p>
326          <span class="bold"><strong>Moral</strong></span>: if you in a losing patch, leave
327          the game. (Because the odds to recover to a good patch are poor).
328        </p>
329<p>
330          <span class="bold"><strong>Corollary</strong></span>: Quit while you are ahead?
331        </p>
332<p>
333          A working example is at <a href="../../../../../example/arcsine_example.cpp" target="_top">arcsine_example.cpp</a>
334          including sample output .
335        </p>
336<h5>
337<a name="math_toolkit.dist_ref.dists.arcine_dist.h4"></a>
338          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.related_distributions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.related_distributions">Related
339          distributions</a>
340        </h5>
341<p>
342          The arcsine distribution with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max
343          = 1</em></span> is special case of the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
344          Distribution</a> with α = 1/2 and β = 1/2.
345        </p>
346<h5>
347<a name="math_toolkit.dist_ref.dists.arcine_dist.h5"></a>
348          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.accuracy"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.accuracy">Accuracy</a>
349        </h5>
350<p>
351          This distribution is implemented using sqrt, sine, cos and arc sine and
352          cos trigonometric functions which are normally accurate to a few <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">machine epsilon</a>.
353          But all values suffer from <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
354          of significance or cancellation error</a> for values of <span class="emphasis"><em>x</em></span>
355          close to <span class="emphasis"><em>x_max</em></span>. For example, for a standard [0, 1]
356          arcsine distribution <span class="emphasis"><em>as</em></span>, the pdf is symmetric about
357          random variate <span class="emphasis"><em>x = 0.5</em></span> so that one would expect <code class="computeroutput"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.01</span><span class="special">)</span> <span class="special">==</span>
358          <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.99</span><span class="special">)</span></code>. But
359          as <span class="emphasis"><em>x</em></span> nears unity, there is increasing <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
360          of significance</a>. To counteract this, the complement versions of
361          CDF and quantile are implemented with alternative expressions using <span class="emphasis"><em>cos<sup>-1</sup></em></span>
362          instead of <span class="emphasis"><em>sin<sup>-1</sup></em></span>. Users should see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
363          complements?</a> for guidance on when to avoid loss of accuracy by using
364          complements.
365        </p>
366<h5>
367<a name="math_toolkit.dist_ref.dists.arcine_dist.h6"></a>
368          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.testing"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.testing">Testing</a>
369        </h5>
370<p>
371          The results were tested against a few accurate spot values computed by
372          <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>, for example:
373        </p>
374<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
375<span class="number">0.63661977236758134307553505349005744813783858296183</span>
376</pre>
377<h5>
378<a name="math_toolkit.dist_ref.dists.arcine_dist.h7"></a>
379          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.implementation"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.implementation">Implementation</a>
380        </h5>
381<p>
382          In the following table <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
383          are the parameters <span class="emphasis"><em>x_min</em></span> and <span class="emphasis"><em>x_max</em></span>,
384          <span class="emphasis"><em>x</em></span> is the random variable, <span class="emphasis"><em>p</em></span> is
385          the probability and its complement <span class="emphasis"><em>q = 1-p</em></span>.
386        </p>
387<div class="informaltable"><table class="table">
388<colgroup>
389<col>
390<col>
391</colgroup>
392<thead><tr>
393<th>
394                  <p>
395                    Function
396                  </p>
397                </th>
398<th>
399                  <p>
400                    Implementation Notes
401                  </p>
402                </th>
403</tr></thead>
404<tbody>
405<tr>
406<td>
407                  <p>
408                    support
409                  </p>
410                </td>
411<td>
412                  <p>
413                    x ∈ [a, b], default x ∈ [0, 1]
414                  </p>
415                </td>
416</tr>
417<tr>
418<td>
419                  <p>
420                    pdf
421                  </p>
422                </td>
423<td>
424                  <p>
425                    f(x; a, b) = 1/(π⋅√(x - a)⋅(b - x))
426                  </p>
427                </td>
428</tr>
429<tr>
430<td>
431                  <p>
432                    cdf
433                  </p>
434                </td>
435<td>
436                  <p>
437                    F(x) = 2/π⋅sin<sup>-1</sup>(√(x - a) / (b - a) )
438                  </p>
439                </td>
440</tr>
441<tr>
442<td>
443                  <p>
444                    cdf of complement
445                  </p>
446                </td>
447<td>
448                  <p>
449                    2/(π⋅cos<sup>-1</sup>(√(x - a) / (b - a)))
450                  </p>
451                </td>
452</tr>
453<tr>
454<td>
455                  <p>
456                    quantile
457                  </p>
458                </td>
459<td>
460                  <p>
461                    -a⋅sin<sup>2</sup>(½π⋅p) + a + b⋅sin<sup>2</sup>(½π⋅p)
462                  </p>
463                </td>
464</tr>
465<tr>
466<td>
467                  <p>
468                    quantile from the complement
469                  </p>
470                </td>
471<td>
472                  <p>
473                    -a⋅cos<sup>2</sup>(½π⋅p) + a + b⋅cos<sup>2</sup>(½π⋅q)
474                  </p>
475                </td>
476</tr>
477<tr>
478<td>
479                  <p>
480                    mean
481                  </p>
482                </td>
483<td>
484                  <p>
485                    ½(a+b)
486                  </p>
487                </td>
488</tr>
489<tr>
490<td>
491                  <p>
492                    median
493                  </p>
494                </td>
495<td>
496                  <p>
497                    ½(a+b)
498                  </p>
499                </td>
500</tr>
501<tr>
502<td>
503                  <p>
504                    mode
505                  </p>
506                </td>
507<td>
508                  <p>
509                    x ∈ [a, b], so raises domain_error (returning NaN).
510                  </p>
511                </td>
512</tr>
513<tr>
514<td>
515                  <p>
516                    variance
517                  </p>
518                </td>
519<td>
520                  <p>
521                    (b - a)<sup>2</sup> / 8
522                  </p>
523                </td>
524</tr>
525<tr>
526<td>
527                  <p>
528                    skewness
529                  </p>
530                </td>
531<td>
532                  <p>
533                    0
534                  </p>
535                </td>
536</tr>
537<tr>
538<td>
539                  <p>
540                    kurtosis excess
541                  </p>
542                </td>
543<td>
544                  <p>
545                    -3/2
546                  </p>
547                </td>
548</tr>
549<tr>
550<td>
551                  <p>
552                    kurtosis
553                  </p>
554                </td>
555<td>
556                  <p>
557                    kurtosis_excess + 3
558                  </p>
559                </td>
560</tr>
561</tbody>
562</table></div>
563<p>
564          The quantile was calculated using an expression obtained by using <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a> to invert the
565          formula for the CDF thus
566        </p>
567<pre class="programlisting"><span class="identifier">solve</span> <span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="number">2</span><span class="special">/</span><span class="identifier">pi</span> <span class="identifier">sin</span><span class="special">^-</span><span class="number">1</span><span class="special">(</span><span class="identifier">sqrt</span><span class="special">((</span><span class="identifier">x</span><span class="special">-</span><span class="identifier">a</span><span class="special">)/(</span><span class="identifier">b</span><span class="special">-</span><span class="identifier">a</span><span class="special">)))</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">]</span>
568</pre>
569<p>
570          which was interpreted as
571        </p>
572<pre class="programlisting"><span class="identifier">Solve</span><span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="special">(</span><span class="number">2</span> <span class="identifier">ArcSin</span><span class="special">[</span><span class="identifier">Sqrt</span><span class="special">[(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">x</span><span class="special">)/(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">)]])/</span><span class="identifier">Pi</span> <span class="special">==</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">MaxExtraConditions</span> <span class="special">-&gt;</span> <span class="identifier">Automatic</span><span class="special">]</span>
573</pre>
574<p>
575          and produced the resulting expression
576        </p>
577<div class="blockquote"><blockquote class="blockquote"><p>
578            <span class="serif_italic">x = -a sin^2((pi p)/2)+a+b sin^2((pi p)/2)</span>
579          </p></blockquote></div>
580<p>
581          Thanks to Wolfram for providing this facility.
582        </p>
583<h5>
584<a name="math_toolkit.dist_ref.dists.arcine_dist.h8"></a>
585          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.references"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.references">References</a>
586        </h5>
587<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
588<li class="listitem">
589              <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia
590              arcsine distribution</a>
591            </li>
592<li class="listitem">
593              <a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia
594              Beta distribution</a>
595            </li>
596<li class="listitem">
597              <a href="http://mathworld.wolfram.com/BetaDistribution.html" target="_top">Wolfram
598              MathWorld</a>
599            </li>
600<li class="listitem">
601              <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
602            </li>
603</ul></div>
604<h5>
605<a name="math_toolkit.dist_ref.dists.arcine_dist.h9"></a>
606          <span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.sources"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.sources">Sources</a>
607        </h5>
608<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
609<li class="listitem">
610              <a href="http://estebanmoro.org/2009/04/the-probability-of-going-through-a-bad-patch" target="_top">The
611              probability of going through a bad patch</a> Esteban Moro's Blog.
612            </li>
613<li class="listitem">
614              <a href="http://www.gotohaggstrom.com/What%20do%20schmucks%20and%20the%20arc%20sine%20law%20have%20in%20common.pdf" target="_top">What
615              soschumcks and the arc sine have in common</a> Peter Haggstrom.
616            </li>
617<li class="listitem">
618              <a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">arcsine
619              distribution</a>.
620            </li>
621<li class="listitem">
622              <a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram
623              reference arcsine examples</a>.
624            </li>
625<li class="listitem">
626              <a href="http://www.math.harvard.edu/library/sternberg/slides/1180908.pdf" target="_top">Shlomo
627              Sternberg slides</a>.
628            </li>
629</ul></div>
630</div>
631<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
632<td align="left"></td>
633<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
634      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
635      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
636      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
637      Daryle Walker and Xiaogang Zhang<p>
638        Distributed under the Boost Software License, Version 1.0. (See accompanying
639        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
640      </p>
641</div></td>
642</tr></table>
643<hr>
644<div class="spirit-nav">
645<a accesskey="p" href="../dists.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bernoulli_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
646</div>
647</body>
648</html>
649