mode — SciPy v1.15.3 Manual (original) (raw)
scipy.stats.Uniform.
Uniform.mode(*, method=None)[source]#
Mode (most likely value)
Informally, the mode is a value that a random variable has the highest probability (density) of assuming. That is, the mode is the element of the support \(\chi\) that maximizes the probability density function \(f(x)\):
\[\text{mode} = \arg\max_{x \in \chi} f(x)\]
Parameters:
method{None, ‘formula’, ‘optimization’}
The strategy used to evaluate the mode. By default (None
), the infrastructure chooses between the following options, listed in order of precedence.
'formula'
: use a formula for the median'optimization'
: numerically maximize the PDF
Not all method options are available for all distributions. If the selected method is not available, a NotImplementedError
will be raised.
Returns:
outarray
The mode
Notes
For some distributions
- the mode is not unique (e.g. the uniform distribution);
- the PDF has one or more singularities, and it is debateable whether a singularity is considered to be in the domain and called the mode (e.g. the gamma distribution with shape parameter less than 1); and/or
- the probability density function may have one or more local maxima that are not a global maximum (e.g. mixture distributions).
In such cases, mode will
- return a single value,
- consider the mode to occur at a singularity, and/or
- return a local maximum which may or may not be a global maximum.
If a formula for the mode is not specifically implemented for the chosen distribution, SciPy will attempt to compute the mode numerically, which may not meet the user’s preferred definition of a mode. In such cases, the user is encouraged to subclass the distribution and override mode
.
References
Examples
Instantiate a distribution with the desired parameters:
from scipy import stats X = stats.Normal(mu=1., sigma=2.)
Evaluate the mode:
If the mode is not uniquely defined, mode
nonetheless returns a single value.
X = stats.Uniform(a=0., b=1.) X.mode() 0.5
If this choice does not satisfy your requirements, subclass the distribution and override mode
:
class BetterUniform(stats.Uniform): ... def mode(self): ... return self.b X = BetterUniform(a=0., b=1.) X.mode() 1.0