1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Log Normal 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="logistic_dist.html" title="Logistic Distribution"> 10<link rel="next" href="negative_binomial_dist.html" title="Negative Binomial 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="logistic_dist.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="negative_binomial_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.lognormal_dist"></a><a class="link" href="lognormal_dist.html" title="Log Normal Distribution">Log Normal 28 Distribution</a> 29</h4></div></div></div> 30<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">lognormal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre> 31<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> 32 33<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span> 34 <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<></a> <span class="special">></span> 35<span class="keyword">class</span> <span class="identifier">lognormal_distribution</span><span class="special">;</span> 36 37<span class="keyword">typedef</span> <span class="identifier">lognormal_distribution</span><span class="special"><></span> <span class="identifier">lognormal</span><span class="special">;</span> 38 39<span class="keyword">template</span> <span class="special"><</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">></span> 40<span class="keyword">class</span> <span class="identifier">lognormal_distribution</span> 41<span class="special">{</span> 42<span class="keyword">public</span><span class="special">:</span> 43 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span> 44 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span> 45 <span class="comment">// Construct:</span> 46 <span class="identifier">lognormal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> 47 <span class="comment">// Accessors:</span> 48 <span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 49 <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 50<span class="special">};</span> 51 52<span class="special">}}</span> <span class="comment">// namespaces</span> 53</pre> 54<p> 55 The lognormal distribution is the distribution that arises when the logarithm 56 of the random variable is normally distributed. A lognormal distribution 57 results when the variable is the product of a large number of independent, 58 identically-distributed variables. 59 </p> 60<p> 61 For location and scale parameters <span class="emphasis"><em>m</em></span> and <span class="emphasis"><em>s</em></span> 62 it is defined by the probability density function: 63 </p> 64<div class="blockquote"><blockquote class="blockquote"><p> 65 <span class="inlinemediaobject"><img src="../../../../equations/lognormal_ref.svg"></span> 66 67 </p></blockquote></div> 68<p> 69 The location and scale parameters are equivalent to the mean and standard 70 deviation of the logarithm of the random variable. 71 </p> 72<p> 73 The following graph illustrates the effect of the location parameter on 74 the PDF, note that the range of the random variable remains [0,+∞] irrespective 75 of the value of the location parameter: 76 </p> 77<div class="blockquote"><blockquote class="blockquote"><p> 78 <span class="inlinemediaobject"><img src="../../../../graphs/lognormal_pdf1.svg" align="middle"></span> 79 80 </p></blockquote></div> 81<p> 82 The next graph illustrates the effect of the scale parameter on the PDF: 83 </p> 84<div class="blockquote"><blockquote class="blockquote"><p> 85 <span class="inlinemediaobject"><img src="../../../../graphs/lognormal_pdf2.svg" align="middle"></span> 86 87 </p></blockquote></div> 88<h5> 89<a name="math_toolkit.dist_ref.dists.lognormal_dist.h0"></a> 90 <span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.member_functions"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.member_functions">Member 91 Functions</a> 92 </h5> 93<pre class="programlisting"><span class="identifier">lognormal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> 94</pre> 95<p> 96 Constructs a lognormal distribution with location <span class="emphasis"><em>location</em></span> 97 and scale <span class="emphasis"><em>scale</em></span>. 98 </p> 99<p> 100 The location parameter is the same as the mean of the logarithm of the 101 random variate. 102 </p> 103<p> 104 The scale parameter is the same as the standard deviation of the logarithm 105 of the random variate. 106 </p> 107<p> 108 Requires that the scale parameter is greater than zero, otherwise calls 109 <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>. 110 </p> 111<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 112</pre> 113<p> 114 Returns the <span class="emphasis"><em>location</em></span> parameter of this distribution. 115 </p> 116<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 117</pre> 118<p> 119 Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution. 120 </p> 121<h5> 122<a name="math_toolkit.dist_ref.dists.lognormal_dist.h1"></a> 123 <span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.non_member_accessors"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.non_member_accessors">Non-member 124 Accessors</a> 125 </h5> 126<p> 127 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor 128 functions</a> that are generic to all distributions are supported: 129 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>, 130 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>, 131 <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>, 132 <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>, 133 <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>, 134 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>, 135 <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>, 136 <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>. 137 </p> 138<p> 139 The domain of the random variable is [0,+∞]. 140 </p> 141<h5> 142<a name="math_toolkit.dist_ref.dists.lognormal_dist.h2"></a> 143 <span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.accuracy"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.accuracy">Accuracy</a> 144 </h5> 145<p> 146 The lognormal distribution is implemented in terms of the standard library 147 log and exp functions, plus the <a class="link" href="../../sf_erf/error_function.html" title="Error Function erf and complement erfc">error 148 function</a>, and as such should have very low error rates. 149 </p> 150<h5> 151<a name="math_toolkit.dist_ref.dists.lognormal_dist.h3"></a> 152 <span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.implementation"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.implementation">Implementation</a> 153 </h5> 154<p> 155 In the following table <span class="emphasis"><em>m</em></span> is the location parameter 156 of the distribution, <span class="emphasis"><em>s</em></span> is its scale parameter, <span class="emphasis"><em>x</em></span> 157 is the random variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q 158 = 1-p</em></span>. 159 </p> 160<div class="informaltable"><table class="table"> 161<colgroup> 162<col> 163<col> 164</colgroup> 165<thead><tr> 166<th> 167 <p> 168 Function 169 </p> 170 </th> 171<th> 172 <p> 173 Implementation Notes 174 </p> 175 </th> 176</tr></thead> 177<tbody> 178<tr> 179<td> 180 <p> 181 pdf 182 </p> 183 </td> 184<td> 185 <p> 186 Using the relation: pdf = e<sup>-(ln(x) - m)<sup>2 </sup> / 2s<sup>2 </sup> </sup> / (x * s * sqrt(2pi)) 187 </p> 188 </td> 189</tr> 190<tr> 191<td> 192 <p> 193 cdf 194 </p> 195 </td> 196<td> 197 <p> 198 Using the relation: p = cdf(normal_distribtion<RealType>(m, 199 s), log(x)) 200 </p> 201 </td> 202</tr> 203<tr> 204<td> 205 <p> 206 cdf complement 207 </p> 208 </td> 209<td> 210 <p> 211 Using the relation: q = cdf(complement(normal_distribtion<RealType>(m, 212 s), log(x))) 213 </p> 214 </td> 215</tr> 216<tr> 217<td> 218 <p> 219 quantile 220 </p> 221 </td> 222<td> 223 <p> 224 Using the relation: x = exp(quantile(normal_distribtion<RealType>(m, 225 s), p)) 226 </p> 227 </td> 228</tr> 229<tr> 230<td> 231 <p> 232 quantile from the complement 233 </p> 234 </td> 235<td> 236 <p> 237 Using the relation: x = exp(quantile(complement(normal_distribtion<RealType>(m, 238 s), q))) 239 </p> 240 </td> 241</tr> 242<tr> 243<td> 244 <p> 245 mean 246 </p> 247 </td> 248<td> 249 <p> 250 e<sup>m + s<sup>2 </sup> / 2 </sup> 251 </p> 252 </td> 253</tr> 254<tr> 255<td> 256 <p> 257 variance 258 </p> 259 </td> 260<td> 261 <p> 262 (e<sup>s<sup>2</sup> </sup> - 1) * e<sup>2m + s<sup>2 </sup> </sup> 263 </p> 264 </td> 265</tr> 266<tr> 267<td> 268 <p> 269 mode 270 </p> 271 </td> 272<td> 273 <p> 274 e<sup>m - s<sup>2 </sup> </sup> 275 </p> 276 </td> 277</tr> 278<tr> 279<td> 280 <p> 281 skewness 282 </p> 283 </td> 284<td> 285 <p> 286 sqrt(e<sup>s<sup>2</sup> </sup> - 1) * (2 + e<sup>s<sup>2</sup> </sup>) 287 </p> 288 </td> 289</tr> 290<tr> 291<td> 292 <p> 293 kurtosis 294 </p> 295 </td> 296<td> 297 <p> 298 e<sup>4s<sup>2</sup> </sup> + 2e<sup>3s<sup>2</sup> </sup> + 3e<sup>2s<sup>2</sup> </sup> - 3 299 </p> 300 </td> 301</tr> 302<tr> 303<td> 304 <p> 305 kurtosis excess 306 </p> 307 </td> 308<td> 309 <p> 310 e<sup>4s<sup>2</sup> </sup> + 2e<sup>3s<sup>2</sup> </sup> + 3e<sup>2s<sup>2</sup> </sup> - 6 311 </p> 312 </td> 313</tr> 314</tbody> 315</table></div> 316</div> 317<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 318<td align="left"></td> 319<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 320 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 321 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 322 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 323 Daryle Walker and Xiaogang Zhang<p> 324 Distributed under the Boost Software License, Version 1.0. (See accompanying 325 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>) 326 </p> 327</div></td> 328</tr></table> 329<hr> 330<div class="spirit-nav"> 331<a accesskey="p" href="logistic_dist.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="negative_binomial_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 332</div> 333</body> 334</html> 335