1
0

distributions.html 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
  6. <meta name="generator" content="pdoc 0.5.2" />
  7. <title>distributions API documentation</title>
  8. <meta name="description" content="" />
  9. <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
  10. <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
  11. <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
  12. <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}#index .two-column{column-count:2}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.name small{font-weight:normal}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase;cursor:pointer}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
  13. <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
  14. <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
  15. </head>
  16. <body>
  17. <main>
  18. <article id="content">
  19. <header>
  20. <h1 class="title"><code>distributions</code> module</h1>
  21. </header>
  22. <section id="section-intro">
  23. <details class="source">
  24. <summary>Source code</summary>
  25. <pre><code class="python">import numpy as np
  26. import scipy.stats as st
  27. # Bulge distributions
  28. class radialPlummer(st.rv_continuous):
  29. def _pdf(self, x):#(3M/4πa3)(1+(r/a)2)−5/2
  30. return 3/(4*np.pi**3) * (1 + x**2)**(-5/2) * 4*np.pi*x**2
  31. PLUMMER = radialPlummer(a=0, b=5, name=&#39;rPlummer&#39;)
  32. # [TODO: Check Hernquist. Not currently in use]
  33. class radialHernquist(st.rv_continuous):
  34. def _pdf(self, x):
  35. return 1/(2*np.pi) * 1/(x**4) * 4*np.pi*x**2
  36. HERNQUIST = radialHernquist(a=0, b=5, name=&#39;rHernquist&#39;)
  37. # Disk distributions
  38. class radialUniform(st.rv_continuous):
  39. def _pdf(self, x):
  40. return 2*x if x&lt;1 else 0
  41. UNIFORM = radialUniform(a=0, b=10, name=&#39;rUniform&#39;)
  42. class radialExp(st.rv_continuous):
  43. def _pdf(self, x):
  44. return x*np.exp(-x)
  45. EXP = radialExp(a=0, b=10, name=&#39;rExp&#39;)
  46. # Halo distributions
  47. class radialNFW(st.rv_continuous):
  48. def _pdf(self, x):
  49. y = 1 / (x * (1 + x)**2) * x**2
  50. # Normalize pdf in (0, 5) range
  51. y /= (-5/6 + np.log(6))
  52. NFW = radialNFW(a=0, b=5, name=&#39;rNFW&#39;)</code></pre>
  53. </details>
  54. </section>
  55. <section>
  56. </section>
  57. <section>
  58. </section>
  59. <section>
  60. </section>
  61. <section>
  62. <h2 class="section-title" id="header-classes">Classes</h2>
  63. <dl>
  64. <dt id="distributions.radialExp"><code class="flex name class">
  65. <span>class <span class="ident">radialExp</span></span>
  66. <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
  67. </code></dt>
  68. <dd>
  69. <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
  70. <p><code>rv_continuous</code> is a base class to construct specific distribution classes
  71. and instances for continuous random variables. It cannot be used
  72. directly as a distribution.</p>
  73. <h2 id="parameters">Parameters</h2>
  74. <dl>
  75. <dt><strong><code>momtype</code></strong> :&ensp;<code>int</code>, optional</dt>
  76. <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
  77. for ppf.</dd>
  78. <dt><strong><code>a</code></strong> :&ensp;<code>float</code>, optional</dt>
  79. <dd>Lower bound of the support of the distribution, default is minus
  80. infinity.</dd>
  81. <dt><strong><code>b</code></strong> :&ensp;<code>float</code>, optional</dt>
  82. <dd>Upper bound of the support of the distribution, default is plus
  83. infinity.</dd>
  84. <dt><strong><code>xtol</code></strong> :&ensp;<code>float</code>, optional</dt>
  85. <dd>The tolerance for fixed point calculation for generic ppf.</dd>
  86. <dt><strong><code>badvalue</code></strong> :&ensp;<code>float</code>, optional</dt>
  87. <dd>The value in a result arrays that indicates a value that for which
  88. some argument restriction is violated, default is np.nan.</dd>
  89. <dt><strong><code>name</code></strong> :&ensp;<code>str</code>, optional</dt>
  90. <dd>The name of the instance. This string is used to construct the default
  91. example for distributions.</dd>
  92. <dt><strong><code>longname</code></strong> :&ensp;<code>str</code>, optional</dt>
  93. <dd>This string is used as part of the first line of the docstring returned
  94. when a subclass has no docstring of its own. Note: <code>longname</code> exists
  95. for backwards compatibility, do not use for new subclasses.</dd>
  96. <dt><strong><code>shapes</code></strong> :&ensp;<code>str</code>, optional</dt>
  97. <dd>The shape of the distribution. For example <code>"m, n"</code> for a
  98. distribution that takes two integers as the two shape arguments for all
  99. its methods. If not provided, shape parameters will be inferred from
  100. the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
  101. instance.</dd>
  102. <dt><strong><code>extradoc</code></strong> :&ensp; <code>str</code>, optional, <code>deprecated</code></dt>
  103. <dd>This string is used as the last part of the docstring returned when a
  104. subclass has no docstring of its own. Note: <code>extradoc</code> exists for
  105. backwards compatibility, do not use for new subclasses.</dd>
  106. <dt><strong><code>seed</code></strong> :&ensp;<code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
  107. <dd>This parameter defines the RandomState object to use for drawing
  108. random variates.
  109. If None (or np.random), the global np.random state is used.
  110. If integer, it is used to seed the local RandomState instance.
  111. Default is None.</dd>
  112. </dl>
  113. <h2 id="methods">Methods</h2>
  114. <p>rvs
  115. pdf
  116. logpdf
  117. cdf
  118. logcdf
  119. sf
  120. logsf
  121. ppf
  122. isf
  123. moment
  124. stats
  125. entropy
  126. expect
  127. median
  128. mean
  129. std
  130. var
  131. interval
  132. <strong>call</strong>
  133. fit
  134. fit_loc_scale
  135. nnlf</p>
  136. <h2 id="notes">Notes</h2>
  137. <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
  138. <code>cdf</code>) check their arguments and pass valid arguments to private,
  139. computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
  140. if it is within the support of a distribution, <code>self.a &lt;= x &lt;= self.b</code>.
  141. Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
  142. (which defaults to checking that its arguments are strictly positive.)</p>
  143. <p><strong>Subclassing</strong></p>
  144. <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
  145. and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  146. to location 0 and scale 1).</p>
  147. <p>If positive argument checking is not correct for your RV
  148. then you will also need to re-define the <code>_argcheck</code> method.</p>
  149. <p>Correct, but potentially slow defaults exist for the remaining
  150. methods but for speed and/or accuracy you can over-ride::</p>
  151. <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
  152. <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
  153. <p><strong>Methods that can be overwritten by subclasses</strong>
  154. ::</p>
  155. <p>_rvs
  156. _pdf
  157. _cdf
  158. _sf
  159. _ppf
  160. _isf
  161. _stats
  162. _munp
  163. _entropy
  164. _argcheck</p>
  165. <p>There are additional (internal and private) generic methods that can
  166. be useful for cross-checking and for debugging, but might work in all
  167. cases when directly called.</p>
  168. <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
  169. case, <code>shapes</code> will be automatically deduced from the signatures of the
  170. overridden methods (<code>pdf</code>, <code>cdf</code> etc).
  171. If, for some reason, you prefer to avoid relying on introspection, you can
  172. specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
  173. <p><strong>Frozen Distributions</strong></p>
  174. <p>Normally, you must provide shape parameters (and, optionally, location and
  175. scale parameters to each call of a method of a distribution.</p>
  176. <p>Alternatively, the object may be called (as a function) to fix the shape,
  177. location, and scale parameters returning a "frozen" continuous RV object:</p>
  178. <p>rv = generic(<shape(s)>, loc=0, scale=1)
  179. frozen RV object with the same methods but holding the given shape,
  180. location, and scale fixed</p>
  181. <p><strong>Statistics</strong></p>
  182. <p>Statistics are computed using numerical integration by default.
  183. For speed you can redefine this using <code>_stats</code>:</p>
  184. <ul>
  185. <li>take shape parameters and return mu, mu2, g1, g2</li>
  186. <li>If you can't compute one of these, return it as None</li>
  187. <li>Can also be defined with a keyword argument <code>moments</code>, which is a
  188. string composed of "m", "v", "s", and/or "k".
  189. Only the components appearing in string should be computed and
  190. returned in the order "m", "v", "s", or "k"
  191. with missing values
  192. returned as None.</li>
  193. </ul>
  194. <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
  195. parameters and returns the n-th non-central moment of the distribution.</p>
  196. <h2 id="examples">Examples</h2>
  197. <p>To create a new Gaussian distribution, we would do the following:</p>
  198. <pre><code>&gt;&gt;&gt; from scipy.stats import rv_continuous
  199. &gt;&gt;&gt; class gaussian_gen(rv_continuous):
  200. ... "Gaussian distribution"
  201. ... def _pdf(self, x):
  202. ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
  203. &gt;&gt;&gt; gaussian = gaussian_gen(name='gaussian')
  204. </code></pre>
  205. <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
  206. <code>rv_continuous</code> and create an instance. With this, we now have
  207. a fully functional distribution with all relevant methods automagically
  208. generated by the framework.</p>
  209. <p>Note that above we defined a standard normal distribution, with zero mean
  210. and unit variance. Shifting and scaling of the distribution can be done
  211. by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
  212. essentially computes <code>y = (x - loc) / scale</code> and
  213. <code>gaussian._pdf(y) / scale</code>.</p></section>
  214. <details class="source">
  215. <summary>Source code</summary>
  216. <pre><code class="python">class radialExp(st.rv_continuous):
  217. def _pdf(self, x):
  218. return x*np.exp(-x)</code></pre>
  219. </details>
  220. </dd>
  221. <dt id="distributions.radialHernquist"><code class="flex name class">
  222. <span>class <span class="ident">radialHernquist</span></span>
  223. <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
  224. </code></dt>
  225. <dd>
  226. <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
  227. <p><code>rv_continuous</code> is a base class to construct specific distribution classes
  228. and instances for continuous random variables. It cannot be used
  229. directly as a distribution.</p>
  230. <h2 id="parameters">Parameters</h2>
  231. <dl>
  232. <dt><strong><code>momtype</code></strong> :&ensp;<code>int</code>, optional</dt>
  233. <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
  234. for ppf.</dd>
  235. <dt><strong><code>a</code></strong> :&ensp;<code>float</code>, optional</dt>
  236. <dd>Lower bound of the support of the distribution, default is minus
  237. infinity.</dd>
  238. <dt><strong><code>b</code></strong> :&ensp;<code>float</code>, optional</dt>
  239. <dd>Upper bound of the support of the distribution, default is plus
  240. infinity.</dd>
  241. <dt><strong><code>xtol</code></strong> :&ensp;<code>float</code>, optional</dt>
  242. <dd>The tolerance for fixed point calculation for generic ppf.</dd>
  243. <dt><strong><code>badvalue</code></strong> :&ensp;<code>float</code>, optional</dt>
  244. <dd>The value in a result arrays that indicates a value that for which
  245. some argument restriction is violated, default is np.nan.</dd>
  246. <dt><strong><code>name</code></strong> :&ensp;<code>str</code>, optional</dt>
  247. <dd>The name of the instance. This string is used to construct the default
  248. example for distributions.</dd>
  249. <dt><strong><code>longname</code></strong> :&ensp;<code>str</code>, optional</dt>
  250. <dd>This string is used as part of the first line of the docstring returned
  251. when a subclass has no docstring of its own. Note: <code>longname</code> exists
  252. for backwards compatibility, do not use for new subclasses.</dd>
  253. <dt><strong><code>shapes</code></strong> :&ensp;<code>str</code>, optional</dt>
  254. <dd>The shape of the distribution. For example <code>"m, n"</code> for a
  255. distribution that takes two integers as the two shape arguments for all
  256. its methods. If not provided, shape parameters will be inferred from
  257. the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
  258. instance.</dd>
  259. <dt><strong><code>extradoc</code></strong> :&ensp; <code>str</code>, optional, <code>deprecated</code></dt>
  260. <dd>This string is used as the last part of the docstring returned when a
  261. subclass has no docstring of its own. Note: <code>extradoc</code> exists for
  262. backwards compatibility, do not use for new subclasses.</dd>
  263. <dt><strong><code>seed</code></strong> :&ensp;<code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
  264. <dd>This parameter defines the RandomState object to use for drawing
  265. random variates.
  266. If None (or np.random), the global np.random state is used.
  267. If integer, it is used to seed the local RandomState instance.
  268. Default is None.</dd>
  269. </dl>
  270. <h2 id="methods">Methods</h2>
  271. <p>rvs
  272. pdf
  273. logpdf
  274. cdf
  275. logcdf
  276. sf
  277. logsf
  278. ppf
  279. isf
  280. moment
  281. stats
  282. entropy
  283. expect
  284. median
  285. mean
  286. std
  287. var
  288. interval
  289. <strong>call</strong>
  290. fit
  291. fit_loc_scale
  292. nnlf</p>
  293. <h2 id="notes">Notes</h2>
  294. <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
  295. <code>cdf</code>) check their arguments and pass valid arguments to private,
  296. computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
  297. if it is within the support of a distribution, <code>self.a &lt;= x &lt;= self.b</code>.
  298. Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
  299. (which defaults to checking that its arguments are strictly positive.)</p>
  300. <p><strong>Subclassing</strong></p>
  301. <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
  302. and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  303. to location 0 and scale 1).</p>
  304. <p>If positive argument checking is not correct for your RV
  305. then you will also need to re-define the <code>_argcheck</code> method.</p>
  306. <p>Correct, but potentially slow defaults exist for the remaining
  307. methods but for speed and/or accuracy you can over-ride::</p>
  308. <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
  309. <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
  310. <p><strong>Methods that can be overwritten by subclasses</strong>
  311. ::</p>
  312. <p>_rvs
  313. _pdf
  314. _cdf
  315. _sf
  316. _ppf
  317. _isf
  318. _stats
  319. _munp
  320. _entropy
  321. _argcheck</p>
  322. <p>There are additional (internal and private) generic methods that can
  323. be useful for cross-checking and for debugging, but might work in all
  324. cases when directly called.</p>
  325. <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
  326. case, <code>shapes</code> will be automatically deduced from the signatures of the
  327. overridden methods (<code>pdf</code>, <code>cdf</code> etc).
  328. If, for some reason, you prefer to avoid relying on introspection, you can
  329. specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
  330. <p><strong>Frozen Distributions</strong></p>
  331. <p>Normally, you must provide shape parameters (and, optionally, location and
  332. scale parameters to each call of a method of a distribution.</p>
  333. <p>Alternatively, the object may be called (as a function) to fix the shape,
  334. location, and scale parameters returning a "frozen" continuous RV object:</p>
  335. <p>rv = generic(<shape(s)>, loc=0, scale=1)
  336. frozen RV object with the same methods but holding the given shape,
  337. location, and scale fixed</p>
  338. <p><strong>Statistics</strong></p>
  339. <p>Statistics are computed using numerical integration by default.
  340. For speed you can redefine this using <code>_stats</code>:</p>
  341. <ul>
  342. <li>take shape parameters and return mu, mu2, g1, g2</li>
  343. <li>If you can't compute one of these, return it as None</li>
  344. <li>Can also be defined with a keyword argument <code>moments</code>, which is a
  345. string composed of "m", "v", "s", and/or "k".
  346. Only the components appearing in string should be computed and
  347. returned in the order "m", "v", "s", or "k"
  348. with missing values
  349. returned as None.</li>
  350. </ul>
  351. <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
  352. parameters and returns the n-th non-central moment of the distribution.</p>
  353. <h2 id="examples">Examples</h2>
  354. <p>To create a new Gaussian distribution, we would do the following:</p>
  355. <pre><code>&gt;&gt;&gt; from scipy.stats import rv_continuous
  356. &gt;&gt;&gt; class gaussian_gen(rv_continuous):
  357. ... "Gaussian distribution"
  358. ... def _pdf(self, x):
  359. ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
  360. &gt;&gt;&gt; gaussian = gaussian_gen(name='gaussian')
  361. </code></pre>
  362. <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
  363. <code>rv_continuous</code> and create an instance. With this, we now have
  364. a fully functional distribution with all relevant methods automagically
  365. generated by the framework.</p>
  366. <p>Note that above we defined a standard normal distribution, with zero mean
  367. and unit variance. Shifting and scaling of the distribution can be done
  368. by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
  369. essentially computes <code>y = (x - loc) / scale</code> and
  370. <code>gaussian._pdf(y) / scale</code>.</p></section>
  371. <details class="source">
  372. <summary>Source code</summary>
  373. <pre><code class="python">class radialHernquist(st.rv_continuous):
  374. def _pdf(self, x):
  375. return 1/(2*np.pi) * 1/(x**4) * 4*np.pi*x**2</code></pre>
  376. </details>
  377. </dd>
  378. <dt id="distributions.radialNFW"><code class="flex name class">
  379. <span>class <span class="ident">radialNFW</span></span>
  380. <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
  381. </code></dt>
  382. <dd>
  383. <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
  384. <p><code>rv_continuous</code> is a base class to construct specific distribution classes
  385. and instances for continuous random variables. It cannot be used
  386. directly as a distribution.</p>
  387. <h2 id="parameters">Parameters</h2>
  388. <dl>
  389. <dt><strong><code>momtype</code></strong> :&ensp;<code>int</code>, optional</dt>
  390. <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
  391. for ppf.</dd>
  392. <dt><strong><code>a</code></strong> :&ensp;<code>float</code>, optional</dt>
  393. <dd>Lower bound of the support of the distribution, default is minus
  394. infinity.</dd>
  395. <dt><strong><code>b</code></strong> :&ensp;<code>float</code>, optional</dt>
  396. <dd>Upper bound of the support of the distribution, default is plus
  397. infinity.</dd>
  398. <dt><strong><code>xtol</code></strong> :&ensp;<code>float</code>, optional</dt>
  399. <dd>The tolerance for fixed point calculation for generic ppf.</dd>
  400. <dt><strong><code>badvalue</code></strong> :&ensp;<code>float</code>, optional</dt>
  401. <dd>The value in a result arrays that indicates a value that for which
  402. some argument restriction is violated, default is np.nan.</dd>
  403. <dt><strong><code>name</code></strong> :&ensp;<code>str</code>, optional</dt>
  404. <dd>The name of the instance. This string is used to construct the default
  405. example for distributions.</dd>
  406. <dt><strong><code>longname</code></strong> :&ensp;<code>str</code>, optional</dt>
  407. <dd>This string is used as part of the first line of the docstring returned
  408. when a subclass has no docstring of its own. Note: <code>longname</code> exists
  409. for backwards compatibility, do not use for new subclasses.</dd>
  410. <dt><strong><code>shapes</code></strong> :&ensp;<code>str</code>, optional</dt>
  411. <dd>The shape of the distribution. For example <code>"m, n"</code> for a
  412. distribution that takes two integers as the two shape arguments for all
  413. its methods. If not provided, shape parameters will be inferred from
  414. the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
  415. instance.</dd>
  416. <dt><strong><code>extradoc</code></strong> :&ensp; <code>str</code>, optional, <code>deprecated</code></dt>
  417. <dd>This string is used as the last part of the docstring returned when a
  418. subclass has no docstring of its own. Note: <code>extradoc</code> exists for
  419. backwards compatibility, do not use for new subclasses.</dd>
  420. <dt><strong><code>seed</code></strong> :&ensp;<code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
  421. <dd>This parameter defines the RandomState object to use for drawing
  422. random variates.
  423. If None (or np.random), the global np.random state is used.
  424. If integer, it is used to seed the local RandomState instance.
  425. Default is None.</dd>
  426. </dl>
  427. <h2 id="methods">Methods</h2>
  428. <p>rvs
  429. pdf
  430. logpdf
  431. cdf
  432. logcdf
  433. sf
  434. logsf
  435. ppf
  436. isf
  437. moment
  438. stats
  439. entropy
  440. expect
  441. median
  442. mean
  443. std
  444. var
  445. interval
  446. <strong>call</strong>
  447. fit
  448. fit_loc_scale
  449. nnlf</p>
  450. <h2 id="notes">Notes</h2>
  451. <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
  452. <code>cdf</code>) check their arguments and pass valid arguments to private,
  453. computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
  454. if it is within the support of a distribution, <code>self.a &lt;= x &lt;= self.b</code>.
  455. Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
  456. (which defaults to checking that its arguments are strictly positive.)</p>
  457. <p><strong>Subclassing</strong></p>
  458. <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
  459. and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  460. to location 0 and scale 1).</p>
  461. <p>If positive argument checking is not correct for your RV
  462. then you will also need to re-define the <code>_argcheck</code> method.</p>
  463. <p>Correct, but potentially slow defaults exist for the remaining
  464. methods but for speed and/or accuracy you can over-ride::</p>
  465. <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
  466. <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
  467. <p><strong>Methods that can be overwritten by subclasses</strong>
  468. ::</p>
  469. <p>_rvs
  470. _pdf
  471. _cdf
  472. _sf
  473. _ppf
  474. _isf
  475. _stats
  476. _munp
  477. _entropy
  478. _argcheck</p>
  479. <p>There are additional (internal and private) generic methods that can
  480. be useful for cross-checking and for debugging, but might work in all
  481. cases when directly called.</p>
  482. <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
  483. case, <code>shapes</code> will be automatically deduced from the signatures of the
  484. overridden methods (<code>pdf</code>, <code>cdf</code> etc).
  485. If, for some reason, you prefer to avoid relying on introspection, you can
  486. specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
  487. <p><strong>Frozen Distributions</strong></p>
  488. <p>Normally, you must provide shape parameters (and, optionally, location and
  489. scale parameters to each call of a method of a distribution.</p>
  490. <p>Alternatively, the object may be called (as a function) to fix the shape,
  491. location, and scale parameters returning a "frozen" continuous RV object:</p>
  492. <p>rv = generic(<shape(s)>, loc=0, scale=1)
  493. frozen RV object with the same methods but holding the given shape,
  494. location, and scale fixed</p>
  495. <p><strong>Statistics</strong></p>
  496. <p>Statistics are computed using numerical integration by default.
  497. For speed you can redefine this using <code>_stats</code>:</p>
  498. <ul>
  499. <li>take shape parameters and return mu, mu2, g1, g2</li>
  500. <li>If you can't compute one of these, return it as None</li>
  501. <li>Can also be defined with a keyword argument <code>moments</code>, which is a
  502. string composed of "m", "v", "s", and/or "k".
  503. Only the components appearing in string should be computed and
  504. returned in the order "m", "v", "s", or "k"
  505. with missing values
  506. returned as None.</li>
  507. </ul>
  508. <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
  509. parameters and returns the n-th non-central moment of the distribution.</p>
  510. <h2 id="examples">Examples</h2>
  511. <p>To create a new Gaussian distribution, we would do the following:</p>
  512. <pre><code>&gt;&gt;&gt; from scipy.stats import rv_continuous
  513. &gt;&gt;&gt; class gaussian_gen(rv_continuous):
  514. ... "Gaussian distribution"
  515. ... def _pdf(self, x):
  516. ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
  517. &gt;&gt;&gt; gaussian = gaussian_gen(name='gaussian')
  518. </code></pre>
  519. <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
  520. <code>rv_continuous</code> and create an instance. With this, we now have
  521. a fully functional distribution with all relevant methods automagically
  522. generated by the framework.</p>
  523. <p>Note that above we defined a standard normal distribution, with zero mean
  524. and unit variance. Shifting and scaling of the distribution can be done
  525. by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
  526. essentially computes <code>y = (x - loc) / scale</code> and
  527. <code>gaussian._pdf(y) / scale</code>.</p></section>
  528. <details class="source">
  529. <summary>Source code</summary>
  530. <pre><code class="python">class radialNFW(st.rv_continuous):
  531. def _pdf(self, x):
  532. y = 1 / (x * (1 + x)**2) * x**2
  533. # Normalize pdf in (0, 5) range
  534. y /= (-5/6 + np.log(6))</code></pre>
  535. </details>
  536. </dd>
  537. <dt id="distributions.radialPlummer"><code class="flex name class">
  538. <span>class <span class="ident">radialPlummer</span></span>
  539. <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
  540. </code></dt>
  541. <dd>
  542. <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
  543. <p><code>rv_continuous</code> is a base class to construct specific distribution classes
  544. and instances for continuous random variables. It cannot be used
  545. directly as a distribution.</p>
  546. <h2 id="parameters">Parameters</h2>
  547. <dl>
  548. <dt><strong><code>momtype</code></strong> :&ensp;<code>int</code>, optional</dt>
  549. <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
  550. for ppf.</dd>
  551. <dt><strong><code>a</code></strong> :&ensp;<code>float</code>, optional</dt>
  552. <dd>Lower bound of the support of the distribution, default is minus
  553. infinity.</dd>
  554. <dt><strong><code>b</code></strong> :&ensp;<code>float</code>, optional</dt>
  555. <dd>Upper bound of the support of the distribution, default is plus
  556. infinity.</dd>
  557. <dt><strong><code>xtol</code></strong> :&ensp;<code>float</code>, optional</dt>
  558. <dd>The tolerance for fixed point calculation for generic ppf.</dd>
  559. <dt><strong><code>badvalue</code></strong> :&ensp;<code>float</code>, optional</dt>
  560. <dd>The value in a result arrays that indicates a value that for which
  561. some argument restriction is violated, default is np.nan.</dd>
  562. <dt><strong><code>name</code></strong> :&ensp;<code>str</code>, optional</dt>
  563. <dd>The name of the instance. This string is used to construct the default
  564. example for distributions.</dd>
  565. <dt><strong><code>longname</code></strong> :&ensp;<code>str</code>, optional</dt>
  566. <dd>This string is used as part of the first line of the docstring returned
  567. when a subclass has no docstring of its own. Note: <code>longname</code> exists
  568. for backwards compatibility, do not use for new subclasses.</dd>
  569. <dt><strong><code>shapes</code></strong> :&ensp;<code>str</code>, optional</dt>
  570. <dd>The shape of the distribution. For example <code>"m, n"</code> for a
  571. distribution that takes two integers as the two shape arguments for all
  572. its methods. If not provided, shape parameters will be inferred from
  573. the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
  574. instance.</dd>
  575. <dt><strong><code>extradoc</code></strong> :&ensp; <code>str</code>, optional, <code>deprecated</code></dt>
  576. <dd>This string is used as the last part of the docstring returned when a
  577. subclass has no docstring of its own. Note: <code>extradoc</code> exists for
  578. backwards compatibility, do not use for new subclasses.</dd>
  579. <dt><strong><code>seed</code></strong> :&ensp;<code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
  580. <dd>This parameter defines the RandomState object to use for drawing
  581. random variates.
  582. If None (or np.random), the global np.random state is used.
  583. If integer, it is used to seed the local RandomState instance.
  584. Default is None.</dd>
  585. </dl>
  586. <h2 id="methods">Methods</h2>
  587. <p>rvs
  588. pdf
  589. logpdf
  590. cdf
  591. logcdf
  592. sf
  593. logsf
  594. ppf
  595. isf
  596. moment
  597. stats
  598. entropy
  599. expect
  600. median
  601. mean
  602. std
  603. var
  604. interval
  605. <strong>call</strong>
  606. fit
  607. fit_loc_scale
  608. nnlf</p>
  609. <h2 id="notes">Notes</h2>
  610. <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
  611. <code>cdf</code>) check their arguments and pass valid arguments to private,
  612. computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
  613. if it is within the support of a distribution, <code>self.a &lt;= x &lt;= self.b</code>.
  614. Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
  615. (which defaults to checking that its arguments are strictly positive.)</p>
  616. <p><strong>Subclassing</strong></p>
  617. <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
  618. and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  619. to location 0 and scale 1).</p>
  620. <p>If positive argument checking is not correct for your RV
  621. then you will also need to re-define the <code>_argcheck</code> method.</p>
  622. <p>Correct, but potentially slow defaults exist for the remaining
  623. methods but for speed and/or accuracy you can over-ride::</p>
  624. <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
  625. <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
  626. <p><strong>Methods that can be overwritten by subclasses</strong>
  627. ::</p>
  628. <p>_rvs
  629. _pdf
  630. _cdf
  631. _sf
  632. _ppf
  633. _isf
  634. _stats
  635. _munp
  636. _entropy
  637. _argcheck</p>
  638. <p>There are additional (internal and private) generic methods that can
  639. be useful for cross-checking and for debugging, but might work in all
  640. cases when directly called.</p>
  641. <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
  642. case, <code>shapes</code> will be automatically deduced from the signatures of the
  643. overridden methods (<code>pdf</code>, <code>cdf</code> etc).
  644. If, for some reason, you prefer to avoid relying on introspection, you can
  645. specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
  646. <p><strong>Frozen Distributions</strong></p>
  647. <p>Normally, you must provide shape parameters (and, optionally, location and
  648. scale parameters to each call of a method of a distribution.</p>
  649. <p>Alternatively, the object may be called (as a function) to fix the shape,
  650. location, and scale parameters returning a "frozen" continuous RV object:</p>
  651. <p>rv = generic(<shape(s)>, loc=0, scale=1)
  652. frozen RV object with the same methods but holding the given shape,
  653. location, and scale fixed</p>
  654. <p><strong>Statistics</strong></p>
  655. <p>Statistics are computed using numerical integration by default.
  656. For speed you can redefine this using <code>_stats</code>:</p>
  657. <ul>
  658. <li>take shape parameters and return mu, mu2, g1, g2</li>
  659. <li>If you can't compute one of these, return it as None</li>
  660. <li>Can also be defined with a keyword argument <code>moments</code>, which is a
  661. string composed of "m", "v", "s", and/or "k".
  662. Only the components appearing in string should be computed and
  663. returned in the order "m", "v", "s", or "k"
  664. with missing values
  665. returned as None.</li>
  666. </ul>
  667. <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
  668. parameters and returns the n-th non-central moment of the distribution.</p>
  669. <h2 id="examples">Examples</h2>
  670. <p>To create a new Gaussian distribution, we would do the following:</p>
  671. <pre><code>&gt;&gt;&gt; from scipy.stats import rv_continuous
  672. &gt;&gt;&gt; class gaussian_gen(rv_continuous):
  673. ... "Gaussian distribution"
  674. ... def _pdf(self, x):
  675. ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
  676. &gt;&gt;&gt; gaussian = gaussian_gen(name='gaussian')
  677. </code></pre>
  678. <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
  679. <code>rv_continuous</code> and create an instance. With this, we now have
  680. a fully functional distribution with all relevant methods automagically
  681. generated by the framework.</p>
  682. <p>Note that above we defined a standard normal distribution, with zero mean
  683. and unit variance. Shifting and scaling of the distribution can be done
  684. by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
  685. essentially computes <code>y = (x - loc) / scale</code> and
  686. <code>gaussian._pdf(y) / scale</code>.</p></section>
  687. <details class="source">
  688. <summary>Source code</summary>
  689. <pre><code class="python">class radialPlummer(st.rv_continuous):
  690. def _pdf(self, x):#(3M/4πa3)(1+(r/a)2)−5/2
  691. return 3/(4*np.pi**3) * (1 + x**2)**(-5/2) * 4*np.pi*x**2</code></pre>
  692. </details>
  693. </dd>
  694. <dt id="distributions.radialUniform"><code class="flex name class">
  695. <span>class <span class="ident">radialUniform</span></span>
  696. <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
  697. </code></dt>
  698. <dd>
  699. <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
  700. <p><code>rv_continuous</code> is a base class to construct specific distribution classes
  701. and instances for continuous random variables. It cannot be used
  702. directly as a distribution.</p>
  703. <h2 id="parameters">Parameters</h2>
  704. <dl>
  705. <dt><strong><code>momtype</code></strong> :&ensp;<code>int</code>, optional</dt>
  706. <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
  707. for ppf.</dd>
  708. <dt><strong><code>a</code></strong> :&ensp;<code>float</code>, optional</dt>
  709. <dd>Lower bound of the support of the distribution, default is minus
  710. infinity.</dd>
  711. <dt><strong><code>b</code></strong> :&ensp;<code>float</code>, optional</dt>
  712. <dd>Upper bound of the support of the distribution, default is plus
  713. infinity.</dd>
  714. <dt><strong><code>xtol</code></strong> :&ensp;<code>float</code>, optional</dt>
  715. <dd>The tolerance for fixed point calculation for generic ppf.</dd>
  716. <dt><strong><code>badvalue</code></strong> :&ensp;<code>float</code>, optional</dt>
  717. <dd>The value in a result arrays that indicates a value that for which
  718. some argument restriction is violated, default is np.nan.</dd>
  719. <dt><strong><code>name</code></strong> :&ensp;<code>str</code>, optional</dt>
  720. <dd>The name of the instance. This string is used to construct the default
  721. example for distributions.</dd>
  722. <dt><strong><code>longname</code></strong> :&ensp;<code>str</code>, optional</dt>
  723. <dd>This string is used as part of the first line of the docstring returned
  724. when a subclass has no docstring of its own. Note: <code>longname</code> exists
  725. for backwards compatibility, do not use for new subclasses.</dd>
  726. <dt><strong><code>shapes</code></strong> :&ensp;<code>str</code>, optional</dt>
  727. <dd>The shape of the distribution. For example <code>"m, n"</code> for a
  728. distribution that takes two integers as the two shape arguments for all
  729. its methods. If not provided, shape parameters will be inferred from
  730. the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
  731. instance.</dd>
  732. <dt><strong><code>extradoc</code></strong> :&ensp; <code>str</code>, optional, <code>deprecated</code></dt>
  733. <dd>This string is used as the last part of the docstring returned when a
  734. subclass has no docstring of its own. Note: <code>extradoc</code> exists for
  735. backwards compatibility, do not use for new subclasses.</dd>
  736. <dt><strong><code>seed</code></strong> :&ensp;<code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
  737. <dd>This parameter defines the RandomState object to use for drawing
  738. random variates.
  739. If None (or np.random), the global np.random state is used.
  740. If integer, it is used to seed the local RandomState instance.
  741. Default is None.</dd>
  742. </dl>
  743. <h2 id="methods">Methods</h2>
  744. <p>rvs
  745. pdf
  746. logpdf
  747. cdf
  748. logcdf
  749. sf
  750. logsf
  751. ppf
  752. isf
  753. moment
  754. stats
  755. entropy
  756. expect
  757. median
  758. mean
  759. std
  760. var
  761. interval
  762. <strong>call</strong>
  763. fit
  764. fit_loc_scale
  765. nnlf</p>
  766. <h2 id="notes">Notes</h2>
  767. <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
  768. <code>cdf</code>) check their arguments and pass valid arguments to private,
  769. computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
  770. if it is within the support of a distribution, <code>self.a &lt;= x &lt;= self.b</code>.
  771. Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
  772. (which defaults to checking that its arguments are strictly positive.)</p>
  773. <p><strong>Subclassing</strong></p>
  774. <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
  775. and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  776. to location 0 and scale 1).</p>
  777. <p>If positive argument checking is not correct for your RV
  778. then you will also need to re-define the <code>_argcheck</code> method.</p>
  779. <p>Correct, but potentially slow defaults exist for the remaining
  780. methods but for speed and/or accuracy you can over-ride::</p>
  781. <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
  782. <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
  783. <p><strong>Methods that can be overwritten by subclasses</strong>
  784. ::</p>
  785. <p>_rvs
  786. _pdf
  787. _cdf
  788. _sf
  789. _ppf
  790. _isf
  791. _stats
  792. _munp
  793. _entropy
  794. _argcheck</p>
  795. <p>There are additional (internal and private) generic methods that can
  796. be useful for cross-checking and for debugging, but might work in all
  797. cases when directly called.</p>
  798. <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
  799. case, <code>shapes</code> will be automatically deduced from the signatures of the
  800. overridden methods (<code>pdf</code>, <code>cdf</code> etc).
  801. If, for some reason, you prefer to avoid relying on introspection, you can
  802. specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
  803. <p><strong>Frozen Distributions</strong></p>
  804. <p>Normally, you must provide shape parameters (and, optionally, location and
  805. scale parameters to each call of a method of a distribution.</p>
  806. <p>Alternatively, the object may be called (as a function) to fix the shape,
  807. location, and scale parameters returning a "frozen" continuous RV object:</p>
  808. <p>rv = generic(<shape(s)>, loc=0, scale=1)
  809. frozen RV object with the same methods but holding the given shape,
  810. location, and scale fixed</p>
  811. <p><strong>Statistics</strong></p>
  812. <p>Statistics are computed using numerical integration by default.
  813. For speed you can redefine this using <code>_stats</code>:</p>
  814. <ul>
  815. <li>take shape parameters and return mu, mu2, g1, g2</li>
  816. <li>If you can't compute one of these, return it as None</li>
  817. <li>Can also be defined with a keyword argument <code>moments</code>, which is a
  818. string composed of "m", "v", "s", and/or "k".
  819. Only the components appearing in string should be computed and
  820. returned in the order "m", "v", "s", or "k"
  821. with missing values
  822. returned as None.</li>
  823. </ul>
  824. <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
  825. parameters and returns the n-th non-central moment of the distribution.</p>
  826. <h2 id="examples">Examples</h2>
  827. <p>To create a new Gaussian distribution, we would do the following:</p>
  828. <pre><code>&gt;&gt;&gt; from scipy.stats import rv_continuous
  829. &gt;&gt;&gt; class gaussian_gen(rv_continuous):
  830. ... "Gaussian distribution"
  831. ... def _pdf(self, x):
  832. ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
  833. &gt;&gt;&gt; gaussian = gaussian_gen(name='gaussian')
  834. </code></pre>
  835. <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
  836. <code>rv_continuous</code> and create an instance. With this, we now have
  837. a fully functional distribution with all relevant methods automagically
  838. generated by the framework.</p>
  839. <p>Note that above we defined a standard normal distribution, with zero mean
  840. and unit variance. Shifting and scaling of the distribution can be done
  841. by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
  842. essentially computes <code>y = (x - loc) / scale</code> and
  843. <code>gaussian._pdf(y) / scale</code>.</p></section>
  844. <details class="source">
  845. <summary>Source code</summary>
  846. <pre><code class="python">class radialUniform(st.rv_continuous):
  847. def _pdf(self, x):
  848. return 2*x if x&lt;1 else 0</code></pre>
  849. </details>
  850. </dd>
  851. </dl>
  852. </section>
  853. </article>
  854. <nav id="sidebar">
  855. <h1>Index</h1>
  856. <div class="toc">
  857. <ul></ul>
  858. </div>
  859. <ul id="index">
  860. <li><h3><a href="#header-classes">Classes</a></h3>
  861. <ul>
  862. <li>
  863. <h4><code><a title="distributions.radialExp" href="#distributions.radialExp">radialExp</a></code></h4>
  864. </li>
  865. <li>
  866. <h4><code><a title="distributions.radialHernquist" href="#distributions.radialHernquist">radialHernquist</a></code></h4>
  867. </li>
  868. <li>
  869. <h4><code><a title="distributions.radialNFW" href="#distributions.radialNFW">radialNFW</a></code></h4>
  870. </li>
  871. <li>
  872. <h4><code><a title="distributions.radialPlummer" href="#distributions.radialPlummer">radialPlummer</a></code></h4>
  873. </li>
  874. <li>
  875. <h4><code><a title="distributions.radialUniform" href="#distributions.radialUniform">radialUniform</a></code></h4>
  876. </li>
  877. </ul>
  878. </li>
  879. </ul>
  880. </nav>
  881. </main>
  882. <footer id="footer">
  883. <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.5.2</a>.</p>
  884. </footer>
  885. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  886. <script>hljs.initHighlightingOnLoad()</script>
  887. </body>
  888. </html>