123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
- <meta name="generator" content="pdoc 0.5.2" />
- <title>distributions API documentation</title>
- <meta name="description" content="" />
- <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
- <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
- <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
- <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>
- <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>
- <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>
- </head>
- <body>
- <main>
- <article id="content">
- <header>
- <h1 class="title"><code>distributions</code> module</h1>
- </header>
- <section id="section-intro">
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">import numpy as np
- import scipy.stats as st
- # Bulge distributions
- class radialPlummer(st.rv_continuous):
- def _pdf(self, x):#(3M/4πa3)(1+(r/a)2)−5/2
- return 3/(4*np.pi**3) * (1 + x**2)**(-5/2) * 4*np.pi*x**2
- PLUMMER = radialPlummer(a=0, b=5, name='rPlummer')
- # [TODO: Check Hernquist. Not currently in use]
- class radialHernquist(st.rv_continuous):
- def _pdf(self, x):
- return 1/(2*np.pi) * 1/(x**4) * 4*np.pi*x**2
- HERNQUIST = radialHernquist(a=0, b=5, name='rHernquist')
- # Disk distributions
- class radialUniform(st.rv_continuous):
- def _pdf(self, x):
- return 2*x if x<1 else 0
- UNIFORM = radialUniform(a=0, b=10, name='rUniform')
- class radialExp(st.rv_continuous):
- def _pdf(self, x):
- return x*np.exp(-x)
- EXP = radialExp(a=0, b=10, name='rExp')
- # Halo distributions
- class radialNFW(st.rv_continuous):
- def _pdf(self, x):
- y = 1 / (x * (1 + x)**2) * x**2
- # Normalize pdf in (0, 5) range
- y /= (-5/6 + np.log(6))
- NFW = radialNFW(a=0, b=5, name='rNFW')</code></pre>
- </details>
- </section>
- <section>
- </section>
- <section>
- </section>
- <section>
- </section>
- <section>
- <h2 class="section-title" id="header-classes">Classes</h2>
- <dl>
- <dt id="distributions.radialExp"><code class="flex name class">
- <span>class <span class="ident">radialExp</span></span>
- <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
- </code></dt>
- <dd>
- <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
- <p><code>rv_continuous</code> is a base class to construct specific distribution classes
- and instances for continuous random variables. It cannot be used
- directly as a distribution.</p>
- <h2 id="parameters">Parameters</h2>
- <dl>
- <dt><strong><code>momtype</code></strong> : <code>int</code>, optional</dt>
- <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
- for ppf.</dd>
- <dt><strong><code>a</code></strong> : <code>float</code>, optional</dt>
- <dd>Lower bound of the support of the distribution, default is minus
- infinity.</dd>
- <dt><strong><code>b</code></strong> : <code>float</code>, optional</dt>
- <dd>Upper bound of the support of the distribution, default is plus
- infinity.</dd>
- <dt><strong><code>xtol</code></strong> : <code>float</code>, optional</dt>
- <dd>The tolerance for fixed point calculation for generic ppf.</dd>
- <dt><strong><code>badvalue</code></strong> : <code>float</code>, optional</dt>
- <dd>The value in a result arrays that indicates a value that for which
- some argument restriction is violated, default is np.nan.</dd>
- <dt><strong><code>name</code></strong> : <code>str</code>, optional</dt>
- <dd>The name of the instance. This string is used to construct the default
- example for distributions.</dd>
- <dt><strong><code>longname</code></strong> : <code>str</code>, optional</dt>
- <dd>This string is used as part of the first line of the docstring returned
- when a subclass has no docstring of its own. Note: <code>longname</code> exists
- for backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>shapes</code></strong> : <code>str</code>, optional</dt>
- <dd>The shape of the distribution. For example <code>"m, n"</code> for a
- distribution that takes two integers as the two shape arguments for all
- its methods. If not provided, shape parameters will be inferred from
- the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
- instance.</dd>
- <dt><strong><code>extradoc</code></strong> :  <code>str</code>, optional, <code>deprecated</code></dt>
- <dd>This string is used as the last part of the docstring returned when a
- subclass has no docstring of its own. Note: <code>extradoc</code> exists for
- backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>seed</code></strong> : <code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
- <dd>This parameter defines the RandomState object to use for drawing
- random variates.
- If None (or np.random), the global np.random state is used.
- If integer, it is used to seed the local RandomState instance.
- Default is None.</dd>
- </dl>
- <h2 id="methods">Methods</h2>
- <p>rvs
- pdf
- logpdf
- cdf
- logcdf
- sf
- logsf
- ppf
- isf
- moment
- stats
- entropy
- expect
- median
- mean
- std
- var
- interval
- <strong>call</strong>
- fit
- fit_loc_scale
- nnlf</p>
- <h2 id="notes">Notes</h2>
- <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
- <code>cdf</code>) check their arguments and pass valid arguments to private,
- computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
- if it is within the support of a distribution, <code>self.a <= x <= self.b</code>.
- Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
- (which defaults to checking that its arguments are strictly positive.)</p>
- <p><strong>Subclassing</strong></p>
- <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
- and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
- to location 0 and scale 1).</p>
- <p>If positive argument checking is not correct for your RV
- then you will also need to re-define the <code>_argcheck</code> method.</p>
- <p>Correct, but potentially slow defaults exist for the remaining
- methods but for speed and/or accuracy you can over-ride::</p>
- <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
- <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
- <p><strong>Methods that can be overwritten by subclasses</strong>
- ::</p>
- <p>_rvs
- _pdf
- _cdf
- _sf
- _ppf
- _isf
- _stats
- _munp
- _entropy
- _argcheck</p>
- <p>There are additional (internal and private) generic methods that can
- be useful for cross-checking and for debugging, but might work in all
- cases when directly called.</p>
- <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
- case, <code>shapes</code> will be automatically deduced from the signatures of the
- overridden methods (<code>pdf</code>, <code>cdf</code> etc).
- If, for some reason, you prefer to avoid relying on introspection, you can
- specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
- <p><strong>Frozen Distributions</strong></p>
- <p>Normally, you must provide shape parameters (and, optionally, location and
- scale parameters to each call of a method of a distribution.</p>
- <p>Alternatively, the object may be called (as a function) to fix the shape,
- location, and scale parameters returning a "frozen" continuous RV object:</p>
- <p>rv = generic(<shape(s)>, loc=0, scale=1)
- frozen RV object with the same methods but holding the given shape,
- location, and scale fixed</p>
- <p><strong>Statistics</strong></p>
- <p>Statistics are computed using numerical integration by default.
- For speed you can redefine this using <code>_stats</code>:</p>
- <ul>
- <li>take shape parameters and return mu, mu2, g1, g2</li>
- <li>If you can't compute one of these, return it as None</li>
- <li>Can also be defined with a keyword argument <code>moments</code>, which is a
- string composed of "m", "v", "s", and/or "k".
- Only the components appearing in string should be computed and
- returned in the order "m", "v", "s", or "k"
- with missing values
- returned as None.</li>
- </ul>
- <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
- parameters and returns the n-th non-central moment of the distribution.</p>
- <h2 id="examples">Examples</h2>
- <p>To create a new Gaussian distribution, we would do the following:</p>
- <pre><code>>>> from scipy.stats import rv_continuous
- >>> class gaussian_gen(rv_continuous):
- ... "Gaussian distribution"
- ... def _pdf(self, x):
- ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
- >>> gaussian = gaussian_gen(name='gaussian')
- </code></pre>
- <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
- <code>rv_continuous</code> and create an instance. With this, we now have
- a fully functional distribution with all relevant methods automagically
- generated by the framework.</p>
- <p>Note that above we defined a standard normal distribution, with zero mean
- and unit variance. Shifting and scaling of the distribution can be done
- by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
- essentially computes <code>y = (x - loc) / scale</code> and
- <code>gaussian._pdf(y) / scale</code>.</p></section>
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">class radialExp(st.rv_continuous):
- def _pdf(self, x):
- return x*np.exp(-x)</code></pre>
- </details>
- </dd>
- <dt id="distributions.radialHernquist"><code class="flex name class">
- <span>class <span class="ident">radialHernquist</span></span>
- <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
- </code></dt>
- <dd>
- <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
- <p><code>rv_continuous</code> is a base class to construct specific distribution classes
- and instances for continuous random variables. It cannot be used
- directly as a distribution.</p>
- <h2 id="parameters">Parameters</h2>
- <dl>
- <dt><strong><code>momtype</code></strong> : <code>int</code>, optional</dt>
- <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
- for ppf.</dd>
- <dt><strong><code>a</code></strong> : <code>float</code>, optional</dt>
- <dd>Lower bound of the support of the distribution, default is minus
- infinity.</dd>
- <dt><strong><code>b</code></strong> : <code>float</code>, optional</dt>
- <dd>Upper bound of the support of the distribution, default is plus
- infinity.</dd>
- <dt><strong><code>xtol</code></strong> : <code>float</code>, optional</dt>
- <dd>The tolerance for fixed point calculation for generic ppf.</dd>
- <dt><strong><code>badvalue</code></strong> : <code>float</code>, optional</dt>
- <dd>The value in a result arrays that indicates a value that for which
- some argument restriction is violated, default is np.nan.</dd>
- <dt><strong><code>name</code></strong> : <code>str</code>, optional</dt>
- <dd>The name of the instance. This string is used to construct the default
- example for distributions.</dd>
- <dt><strong><code>longname</code></strong> : <code>str</code>, optional</dt>
- <dd>This string is used as part of the first line of the docstring returned
- when a subclass has no docstring of its own. Note: <code>longname</code> exists
- for backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>shapes</code></strong> : <code>str</code>, optional</dt>
- <dd>The shape of the distribution. For example <code>"m, n"</code> for a
- distribution that takes two integers as the two shape arguments for all
- its methods. If not provided, shape parameters will be inferred from
- the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
- instance.</dd>
- <dt><strong><code>extradoc</code></strong> :  <code>str</code>, optional, <code>deprecated</code></dt>
- <dd>This string is used as the last part of the docstring returned when a
- subclass has no docstring of its own. Note: <code>extradoc</code> exists for
- backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>seed</code></strong> : <code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
- <dd>This parameter defines the RandomState object to use for drawing
- random variates.
- If None (or np.random), the global np.random state is used.
- If integer, it is used to seed the local RandomState instance.
- Default is None.</dd>
- </dl>
- <h2 id="methods">Methods</h2>
- <p>rvs
- pdf
- logpdf
- cdf
- logcdf
- sf
- logsf
- ppf
- isf
- moment
- stats
- entropy
- expect
- median
- mean
- std
- var
- interval
- <strong>call</strong>
- fit
- fit_loc_scale
- nnlf</p>
- <h2 id="notes">Notes</h2>
- <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
- <code>cdf</code>) check their arguments and pass valid arguments to private,
- computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
- if it is within the support of a distribution, <code>self.a <= x <= self.b</code>.
- Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
- (which defaults to checking that its arguments are strictly positive.)</p>
- <p><strong>Subclassing</strong></p>
- <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
- and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
- to location 0 and scale 1).</p>
- <p>If positive argument checking is not correct for your RV
- then you will also need to re-define the <code>_argcheck</code> method.</p>
- <p>Correct, but potentially slow defaults exist for the remaining
- methods but for speed and/or accuracy you can over-ride::</p>
- <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
- <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
- <p><strong>Methods that can be overwritten by subclasses</strong>
- ::</p>
- <p>_rvs
- _pdf
- _cdf
- _sf
- _ppf
- _isf
- _stats
- _munp
- _entropy
- _argcheck</p>
- <p>There are additional (internal and private) generic methods that can
- be useful for cross-checking and for debugging, but might work in all
- cases when directly called.</p>
- <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
- case, <code>shapes</code> will be automatically deduced from the signatures of the
- overridden methods (<code>pdf</code>, <code>cdf</code> etc).
- If, for some reason, you prefer to avoid relying on introspection, you can
- specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
- <p><strong>Frozen Distributions</strong></p>
- <p>Normally, you must provide shape parameters (and, optionally, location and
- scale parameters to each call of a method of a distribution.</p>
- <p>Alternatively, the object may be called (as a function) to fix the shape,
- location, and scale parameters returning a "frozen" continuous RV object:</p>
- <p>rv = generic(<shape(s)>, loc=0, scale=1)
- frozen RV object with the same methods but holding the given shape,
- location, and scale fixed</p>
- <p><strong>Statistics</strong></p>
- <p>Statistics are computed using numerical integration by default.
- For speed you can redefine this using <code>_stats</code>:</p>
- <ul>
- <li>take shape parameters and return mu, mu2, g1, g2</li>
- <li>If you can't compute one of these, return it as None</li>
- <li>Can also be defined with a keyword argument <code>moments</code>, which is a
- string composed of "m", "v", "s", and/or "k".
- Only the components appearing in string should be computed and
- returned in the order "m", "v", "s", or "k"
- with missing values
- returned as None.</li>
- </ul>
- <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
- parameters and returns the n-th non-central moment of the distribution.</p>
- <h2 id="examples">Examples</h2>
- <p>To create a new Gaussian distribution, we would do the following:</p>
- <pre><code>>>> from scipy.stats import rv_continuous
- >>> class gaussian_gen(rv_continuous):
- ... "Gaussian distribution"
- ... def _pdf(self, x):
- ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
- >>> gaussian = gaussian_gen(name='gaussian')
- </code></pre>
- <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
- <code>rv_continuous</code> and create an instance. With this, we now have
- a fully functional distribution with all relevant methods automagically
- generated by the framework.</p>
- <p>Note that above we defined a standard normal distribution, with zero mean
- and unit variance. Shifting and scaling of the distribution can be done
- by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
- essentially computes <code>y = (x - loc) / scale</code> and
- <code>gaussian._pdf(y) / scale</code>.</p></section>
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">class radialHernquist(st.rv_continuous):
- def _pdf(self, x):
- return 1/(2*np.pi) * 1/(x**4) * 4*np.pi*x**2</code></pre>
- </details>
- </dd>
- <dt id="distributions.radialNFW"><code class="flex name class">
- <span>class <span class="ident">radialNFW</span></span>
- <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
- </code></dt>
- <dd>
- <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
- <p><code>rv_continuous</code> is a base class to construct specific distribution classes
- and instances for continuous random variables. It cannot be used
- directly as a distribution.</p>
- <h2 id="parameters">Parameters</h2>
- <dl>
- <dt><strong><code>momtype</code></strong> : <code>int</code>, optional</dt>
- <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
- for ppf.</dd>
- <dt><strong><code>a</code></strong> : <code>float</code>, optional</dt>
- <dd>Lower bound of the support of the distribution, default is minus
- infinity.</dd>
- <dt><strong><code>b</code></strong> : <code>float</code>, optional</dt>
- <dd>Upper bound of the support of the distribution, default is plus
- infinity.</dd>
- <dt><strong><code>xtol</code></strong> : <code>float</code>, optional</dt>
- <dd>The tolerance for fixed point calculation for generic ppf.</dd>
- <dt><strong><code>badvalue</code></strong> : <code>float</code>, optional</dt>
- <dd>The value in a result arrays that indicates a value that for which
- some argument restriction is violated, default is np.nan.</dd>
- <dt><strong><code>name</code></strong> : <code>str</code>, optional</dt>
- <dd>The name of the instance. This string is used to construct the default
- example for distributions.</dd>
- <dt><strong><code>longname</code></strong> : <code>str</code>, optional</dt>
- <dd>This string is used as part of the first line of the docstring returned
- when a subclass has no docstring of its own. Note: <code>longname</code> exists
- for backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>shapes</code></strong> : <code>str</code>, optional</dt>
- <dd>The shape of the distribution. For example <code>"m, n"</code> for a
- distribution that takes two integers as the two shape arguments for all
- its methods. If not provided, shape parameters will be inferred from
- the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
- instance.</dd>
- <dt><strong><code>extradoc</code></strong> :  <code>str</code>, optional, <code>deprecated</code></dt>
- <dd>This string is used as the last part of the docstring returned when a
- subclass has no docstring of its own. Note: <code>extradoc</code> exists for
- backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>seed</code></strong> : <code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
- <dd>This parameter defines the RandomState object to use for drawing
- random variates.
- If None (or np.random), the global np.random state is used.
- If integer, it is used to seed the local RandomState instance.
- Default is None.</dd>
- </dl>
- <h2 id="methods">Methods</h2>
- <p>rvs
- pdf
- logpdf
- cdf
- logcdf
- sf
- logsf
- ppf
- isf
- moment
- stats
- entropy
- expect
- median
- mean
- std
- var
- interval
- <strong>call</strong>
- fit
- fit_loc_scale
- nnlf</p>
- <h2 id="notes">Notes</h2>
- <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
- <code>cdf</code>) check their arguments and pass valid arguments to private,
- computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
- if it is within the support of a distribution, <code>self.a <= x <= self.b</code>.
- Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
- (which defaults to checking that its arguments are strictly positive.)</p>
- <p><strong>Subclassing</strong></p>
- <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
- and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
- to location 0 and scale 1).</p>
- <p>If positive argument checking is not correct for your RV
- then you will also need to re-define the <code>_argcheck</code> method.</p>
- <p>Correct, but potentially slow defaults exist for the remaining
- methods but for speed and/or accuracy you can over-ride::</p>
- <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
- <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
- <p><strong>Methods that can be overwritten by subclasses</strong>
- ::</p>
- <p>_rvs
- _pdf
- _cdf
- _sf
- _ppf
- _isf
- _stats
- _munp
- _entropy
- _argcheck</p>
- <p>There are additional (internal and private) generic methods that can
- be useful for cross-checking and for debugging, but might work in all
- cases when directly called.</p>
- <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
- case, <code>shapes</code> will be automatically deduced from the signatures of the
- overridden methods (<code>pdf</code>, <code>cdf</code> etc).
- If, for some reason, you prefer to avoid relying on introspection, you can
- specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
- <p><strong>Frozen Distributions</strong></p>
- <p>Normally, you must provide shape parameters (and, optionally, location and
- scale parameters to each call of a method of a distribution.</p>
- <p>Alternatively, the object may be called (as a function) to fix the shape,
- location, and scale parameters returning a "frozen" continuous RV object:</p>
- <p>rv = generic(<shape(s)>, loc=0, scale=1)
- frozen RV object with the same methods but holding the given shape,
- location, and scale fixed</p>
- <p><strong>Statistics</strong></p>
- <p>Statistics are computed using numerical integration by default.
- For speed you can redefine this using <code>_stats</code>:</p>
- <ul>
- <li>take shape parameters and return mu, mu2, g1, g2</li>
- <li>If you can't compute one of these, return it as None</li>
- <li>Can also be defined with a keyword argument <code>moments</code>, which is a
- string composed of "m", "v", "s", and/or "k".
- Only the components appearing in string should be computed and
- returned in the order "m", "v", "s", or "k"
- with missing values
- returned as None.</li>
- </ul>
- <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
- parameters and returns the n-th non-central moment of the distribution.</p>
- <h2 id="examples">Examples</h2>
- <p>To create a new Gaussian distribution, we would do the following:</p>
- <pre><code>>>> from scipy.stats import rv_continuous
- >>> class gaussian_gen(rv_continuous):
- ... "Gaussian distribution"
- ... def _pdf(self, x):
- ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
- >>> gaussian = gaussian_gen(name='gaussian')
- </code></pre>
- <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
- <code>rv_continuous</code> and create an instance. With this, we now have
- a fully functional distribution with all relevant methods automagically
- generated by the framework.</p>
- <p>Note that above we defined a standard normal distribution, with zero mean
- and unit variance. Shifting and scaling of the distribution can be done
- by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
- essentially computes <code>y = (x - loc) / scale</code> and
- <code>gaussian._pdf(y) / scale</code>.</p></section>
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">class radialNFW(st.rv_continuous):
- def _pdf(self, x):
- y = 1 / (x * (1 + x)**2) * x**2
- # Normalize pdf in (0, 5) range
- y /= (-5/6 + np.log(6))</code></pre>
- </details>
- </dd>
- <dt id="distributions.radialPlummer"><code class="flex name class">
- <span>class <span class="ident">radialPlummer</span></span>
- <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
- </code></dt>
- <dd>
- <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
- <p><code>rv_continuous</code> is a base class to construct specific distribution classes
- and instances for continuous random variables. It cannot be used
- directly as a distribution.</p>
- <h2 id="parameters">Parameters</h2>
- <dl>
- <dt><strong><code>momtype</code></strong> : <code>int</code>, optional</dt>
- <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
- for ppf.</dd>
- <dt><strong><code>a</code></strong> : <code>float</code>, optional</dt>
- <dd>Lower bound of the support of the distribution, default is minus
- infinity.</dd>
- <dt><strong><code>b</code></strong> : <code>float</code>, optional</dt>
- <dd>Upper bound of the support of the distribution, default is plus
- infinity.</dd>
- <dt><strong><code>xtol</code></strong> : <code>float</code>, optional</dt>
- <dd>The tolerance for fixed point calculation for generic ppf.</dd>
- <dt><strong><code>badvalue</code></strong> : <code>float</code>, optional</dt>
- <dd>The value in a result arrays that indicates a value that for which
- some argument restriction is violated, default is np.nan.</dd>
- <dt><strong><code>name</code></strong> : <code>str</code>, optional</dt>
- <dd>The name of the instance. This string is used to construct the default
- example for distributions.</dd>
- <dt><strong><code>longname</code></strong> : <code>str</code>, optional</dt>
- <dd>This string is used as part of the first line of the docstring returned
- when a subclass has no docstring of its own. Note: <code>longname</code> exists
- for backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>shapes</code></strong> : <code>str</code>, optional</dt>
- <dd>The shape of the distribution. For example <code>"m, n"</code> for a
- distribution that takes two integers as the two shape arguments for all
- its methods. If not provided, shape parameters will be inferred from
- the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
- instance.</dd>
- <dt><strong><code>extradoc</code></strong> :  <code>str</code>, optional, <code>deprecated</code></dt>
- <dd>This string is used as the last part of the docstring returned when a
- subclass has no docstring of its own. Note: <code>extradoc</code> exists for
- backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>seed</code></strong> : <code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
- <dd>This parameter defines the RandomState object to use for drawing
- random variates.
- If None (or np.random), the global np.random state is used.
- If integer, it is used to seed the local RandomState instance.
- Default is None.</dd>
- </dl>
- <h2 id="methods">Methods</h2>
- <p>rvs
- pdf
- logpdf
- cdf
- logcdf
- sf
- logsf
- ppf
- isf
- moment
- stats
- entropy
- expect
- median
- mean
- std
- var
- interval
- <strong>call</strong>
- fit
- fit_loc_scale
- nnlf</p>
- <h2 id="notes">Notes</h2>
- <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
- <code>cdf</code>) check their arguments and pass valid arguments to private,
- computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
- if it is within the support of a distribution, <code>self.a <= x <= self.b</code>.
- Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
- (which defaults to checking that its arguments are strictly positive.)</p>
- <p><strong>Subclassing</strong></p>
- <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
- and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
- to location 0 and scale 1).</p>
- <p>If positive argument checking is not correct for your RV
- then you will also need to re-define the <code>_argcheck</code> method.</p>
- <p>Correct, but potentially slow defaults exist for the remaining
- methods but for speed and/or accuracy you can over-ride::</p>
- <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
- <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
- <p><strong>Methods that can be overwritten by subclasses</strong>
- ::</p>
- <p>_rvs
- _pdf
- _cdf
- _sf
- _ppf
- _isf
- _stats
- _munp
- _entropy
- _argcheck</p>
- <p>There are additional (internal and private) generic methods that can
- be useful for cross-checking and for debugging, but might work in all
- cases when directly called.</p>
- <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
- case, <code>shapes</code> will be automatically deduced from the signatures of the
- overridden methods (<code>pdf</code>, <code>cdf</code> etc).
- If, for some reason, you prefer to avoid relying on introspection, you can
- specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
- <p><strong>Frozen Distributions</strong></p>
- <p>Normally, you must provide shape parameters (and, optionally, location and
- scale parameters to each call of a method of a distribution.</p>
- <p>Alternatively, the object may be called (as a function) to fix the shape,
- location, and scale parameters returning a "frozen" continuous RV object:</p>
- <p>rv = generic(<shape(s)>, loc=0, scale=1)
- frozen RV object with the same methods but holding the given shape,
- location, and scale fixed</p>
- <p><strong>Statistics</strong></p>
- <p>Statistics are computed using numerical integration by default.
- For speed you can redefine this using <code>_stats</code>:</p>
- <ul>
- <li>take shape parameters and return mu, mu2, g1, g2</li>
- <li>If you can't compute one of these, return it as None</li>
- <li>Can also be defined with a keyword argument <code>moments</code>, which is a
- string composed of "m", "v", "s", and/or "k".
- Only the components appearing in string should be computed and
- returned in the order "m", "v", "s", or "k"
- with missing values
- returned as None.</li>
- </ul>
- <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
- parameters and returns the n-th non-central moment of the distribution.</p>
- <h2 id="examples">Examples</h2>
- <p>To create a new Gaussian distribution, we would do the following:</p>
- <pre><code>>>> from scipy.stats import rv_continuous
- >>> class gaussian_gen(rv_continuous):
- ... "Gaussian distribution"
- ... def _pdf(self, x):
- ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
- >>> gaussian = gaussian_gen(name='gaussian')
- </code></pre>
- <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
- <code>rv_continuous</code> and create an instance. With this, we now have
- a fully functional distribution with all relevant methods automagically
- generated by the framework.</p>
- <p>Note that above we defined a standard normal distribution, with zero mean
- and unit variance. Shifting and scaling of the distribution can be done
- by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
- essentially computes <code>y = (x - loc) / scale</code> and
- <code>gaussian._pdf(y) / scale</code>.</p></section>
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">class radialPlummer(st.rv_continuous):
- def _pdf(self, x):#(3M/4πa3)(1+(r/a)2)−5/2
- return 3/(4*np.pi**3) * (1 + x**2)**(-5/2) * 4*np.pi*x**2</code></pre>
- </details>
- </dd>
- <dt id="distributions.radialUniform"><code class="flex name class">
- <span>class <span class="ident">radialUniform</span></span>
- <span>(</span><span><small>ancestors:</small> scipy.stats._distn_infrastructure.rv_continuous, scipy.stats._distn_infrastructure.rv_generic)</span>
- </code></dt>
- <dd>
- <section class="desc"><p>A generic continuous random variable class meant for subclassing.</p>
- <p><code>rv_continuous</code> is a base class to construct specific distribution classes
- and instances for continuous random variables. It cannot be used
- directly as a distribution.</p>
- <h2 id="parameters">Parameters</h2>
- <dl>
- <dt><strong><code>momtype</code></strong> : <code>int</code>, optional</dt>
- <dd>The type of generic moment calculation to use: 0 for pdf, 1 (default)
- for ppf.</dd>
- <dt><strong><code>a</code></strong> : <code>float</code>, optional</dt>
- <dd>Lower bound of the support of the distribution, default is minus
- infinity.</dd>
- <dt><strong><code>b</code></strong> : <code>float</code>, optional</dt>
- <dd>Upper bound of the support of the distribution, default is plus
- infinity.</dd>
- <dt><strong><code>xtol</code></strong> : <code>float</code>, optional</dt>
- <dd>The tolerance for fixed point calculation for generic ppf.</dd>
- <dt><strong><code>badvalue</code></strong> : <code>float</code>, optional</dt>
- <dd>The value in a result arrays that indicates a value that for which
- some argument restriction is violated, default is np.nan.</dd>
- <dt><strong><code>name</code></strong> : <code>str</code>, optional</dt>
- <dd>The name of the instance. This string is used to construct the default
- example for distributions.</dd>
- <dt><strong><code>longname</code></strong> : <code>str</code>, optional</dt>
- <dd>This string is used as part of the first line of the docstring returned
- when a subclass has no docstring of its own. Note: <code>longname</code> exists
- for backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>shapes</code></strong> : <code>str</code>, optional</dt>
- <dd>The shape of the distribution. For example <code>"m, n"</code> for a
- distribution that takes two integers as the two shape arguments for all
- its methods. If not provided, shape parameters will be inferred from
- the signature of the private methods, <code>_pdf</code> and <code>_cdf</code> of the
- instance.</dd>
- <dt><strong><code>extradoc</code></strong> :  <code>str</code>, optional, <code>deprecated</code></dt>
- <dd>This string is used as the last part of the docstring returned when a
- subclass has no docstring of its own. Note: <code>extradoc</code> exists for
- backwards compatibility, do not use for new subclasses.</dd>
- <dt><strong><code>seed</code></strong> : <code>None</code> or <code>int</code> or <code>numpy.random.RandomState</code> <code>instance</code>, optional</dt>
- <dd>This parameter defines the RandomState object to use for drawing
- random variates.
- If None (or np.random), the global np.random state is used.
- If integer, it is used to seed the local RandomState instance.
- Default is None.</dd>
- </dl>
- <h2 id="methods">Methods</h2>
- <p>rvs
- pdf
- logpdf
- cdf
- logcdf
- sf
- logsf
- ppf
- isf
- moment
- stats
- entropy
- expect
- median
- mean
- std
- var
- interval
- <strong>call</strong>
- fit
- fit_loc_scale
- nnlf</p>
- <h2 id="notes">Notes</h2>
- <p>Public methods of an instance of a distribution class (e.g., <code>pdf</code>,
- <code>cdf</code>) check their arguments and pass valid arguments to private,
- computational methods (<code>_pdf</code>, <code>_cdf</code>). For <code>pdf(x)</code>, <code>x</code> is valid
- if it is within the support of a distribution, <code>self.a <= x <= self.b</code>.
- Whether a shape parameter is valid is decided by an <code>_argcheck</code> method
- (which defaults to checking that its arguments are strictly positive.)</p>
- <p><strong>Subclassing</strong></p>
- <p>New random variables can be defined by subclassing the <code>rv_continuous</code> class
- and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
- to location 0 and scale 1).</p>
- <p>If positive argument checking is not correct for your RV
- then you will also need to re-define the <code>_argcheck</code> method.</p>
- <p>Correct, but potentially slow defaults exist for the remaining
- methods but for speed and/or accuracy you can over-ride::</p>
- <p>_logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf</p>
- <p>Rarely would you override <code>_isf</code>, <code>_sf</code> or <code>_logsf</code>, but you could.</p>
- <p><strong>Methods that can be overwritten by subclasses</strong>
- ::</p>
- <p>_rvs
- _pdf
- _cdf
- _sf
- _ppf
- _isf
- _stats
- _munp
- _entropy
- _argcheck</p>
- <p>There are additional (internal and private) generic methods that can
- be useful for cross-checking and for debugging, but might work in all
- cases when directly called.</p>
- <p>A note on <code>shapes</code>: subclasses need not specify them explicitly. In this
- case, <code>shapes</code> will be automatically deduced from the signatures of the
- overridden methods (<code>pdf</code>, <code>cdf</code> etc).
- If, for some reason, you prefer to avoid relying on introspection, you can
- specify <code>shapes</code> explicitly as an argument to the instance constructor.</p>
- <p><strong>Frozen Distributions</strong></p>
- <p>Normally, you must provide shape parameters (and, optionally, location and
- scale parameters to each call of a method of a distribution.</p>
- <p>Alternatively, the object may be called (as a function) to fix the shape,
- location, and scale parameters returning a "frozen" continuous RV object:</p>
- <p>rv = generic(<shape(s)>, loc=0, scale=1)
- frozen RV object with the same methods but holding the given shape,
- location, and scale fixed</p>
- <p><strong>Statistics</strong></p>
- <p>Statistics are computed using numerical integration by default.
- For speed you can redefine this using <code>_stats</code>:</p>
- <ul>
- <li>take shape parameters and return mu, mu2, g1, g2</li>
- <li>If you can't compute one of these, return it as None</li>
- <li>Can also be defined with a keyword argument <code>moments</code>, which is a
- string composed of "m", "v", "s", and/or "k".
- Only the components appearing in string should be computed and
- returned in the order "m", "v", "s", or "k"
- with missing values
- returned as None.</li>
- </ul>
- <p>Alternatively, you can override <code>_munp</code>, which takes <code>n</code> and shape
- parameters and returns the n-th non-central moment of the distribution.</p>
- <h2 id="examples">Examples</h2>
- <p>To create a new Gaussian distribution, we would do the following:</p>
- <pre><code>>>> from scipy.stats import rv_continuous
- >>> class gaussian_gen(rv_continuous):
- ... "Gaussian distribution"
- ... def _pdf(self, x):
- ... return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
- >>> gaussian = gaussian_gen(name='gaussian')
- </code></pre>
- <p><code>scipy.stats</code> distributions are <em>instances</em>, so here we subclass
- <code>rv_continuous</code> and create an instance. With this, we now have
- a fully functional distribution with all relevant methods automagically
- generated by the framework.</p>
- <p>Note that above we defined a standard normal distribution, with zero mean
- and unit variance. Shifting and scaling of the distribution can be done
- by using <code>loc</code> and <code>scale</code> parameters: <code>gaussian.pdf(x, loc, scale)</code>
- essentially computes <code>y = (x - loc) / scale</code> and
- <code>gaussian._pdf(y) / scale</code>.</p></section>
- <details class="source">
- <summary>Source code</summary>
- <pre><code class="python">class radialUniform(st.rv_continuous):
- def _pdf(self, x):
- return 2*x if x<1 else 0</code></pre>
- </details>
- </dd>
- </dl>
- </section>
- </article>
- <nav id="sidebar">
- <h1>Index</h1>
- <div class="toc">
- <ul></ul>
- </div>
- <ul id="index">
- <li><h3><a href="#header-classes">Classes</a></h3>
- <ul>
- <li>
- <h4><code><a title="distributions.radialExp" href="#distributions.radialExp">radialExp</a></code></h4>
- </li>
- <li>
- <h4><code><a title="distributions.radialHernquist" href="#distributions.radialHernquist">radialHernquist</a></code></h4>
- </li>
- <li>
- <h4><code><a title="distributions.radialNFW" href="#distributions.radialNFW">radialNFW</a></code></h4>
- </li>
- <li>
- <h4><code><a title="distributions.radialPlummer" href="#distributions.radialPlummer">radialPlummer</a></code></h4>
- </li>
- <li>
- <h4><code><a title="distributions.radialUniform" href="#distributions.radialUniform">radialUniform</a></code></h4>
- </li>
- </ul>
- </li>
- </ul>
- </nav>
- </main>
- <footer id="footer">
- <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.5.2</a>.</p>
- </footer>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
- <script>hljs.initHighlightingOnLoad()</script>
- </body>
- </html>
|