amisc.rv
Provides small classes for random variables.
Includes:
BaseRV
: Abstract wrapper class of a random variableUniformRV
: a uniformly-distributed random variableNormalRV
: a normally-distributed random variableScalarRV
: a stand-in class for a variable with no uncertainty or pdfLogUniformRV
: base 10 log-uniformLogNormalRV
: base 10 log-normal
BaseRV(id='', *, tex='', description='Random variable', units='-', param_type='calibration', nominal=1, domain=(0, 1))
Bases: ABC
Small wrapper class similar to scipy.stats
random variables (RVs).
ATTRIBUTE | DESCRIPTION |
---|---|
id |
an identifier for the variable
TYPE:
|
bds |
the explicit domain bounds of the variable (limits of where you expect to use it)
TYPE:
|
nominal |
a typical value for this variable (within
TYPE:
|
tex |
latex format for the random variable, i.e. r"\(x_i\)"
TYPE:
|
description |
a lengthier description of the variable
TYPE:
|
units |
assumed units for the variable (if applicable)
TYPE:
|
param_type |
an additional descriptor for how this rv is used, e.g. calibration, operating, design, etc.
TYPE:
|
Child classes must implement sample
and pdf
methods.
Source code in src/amisc/rv.py
bounds()
pdf(x)
abstractmethod
Compute the PDF of the RV at the given x
locations.
PARAMETER | DESCRIPTION |
---|---|
x |
locations to compute the PDF at
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
the PDF evaluations at |
sample(shape, nominal=None)
abstractmethod
Draw samples from the PDF.
PARAMETER | DESCRIPTION |
---|---|
shape |
the shape of the returned samples
TYPE:
|
nominal |
a nominal value to use if applicable (i.e. a center for relative Uniform or Normal)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
samples from the PDF of this random variable |
Source code in src/amisc/rv.py
sample_domain(shape)
Return an array of the given shape
for random samples over the domain of this RV.
PARAMETER | DESCRIPTION |
---|---|
shape |
the shape of samples to return
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
random samples over the domain of the random variable |
Source code in src/amisc/rv.py
to_tex(units=False, symbol=True)
Return a raw string that is well-formatted for plotting (with tex).
PARAMETER | DESCRIPTION |
---|---|
units |
whether to include the units in the string
DEFAULT:
|
symbol |
just latex symbol if true, otherwise the full description
DEFAULT:
|
Source code in src/amisc/rv.py
LogNormalRV(mu, std, id='', **kwargs)
Bases: BaseRV
A base 10 log-normal distributed random variable.
ATTRIBUTE | DESCRIPTION |
---|---|
mu |
the center of the log-normal distribution
TYPE:
|
std |
the standard deviation of the log-normal distribution
TYPE:
|
Construct the RV with the mean and std of the underlying distribution, i.e. \(\log_{10}(x) \sim N(\mu, \sigma)\).
PARAMETER | DESCRIPTION |
---|---|
mu |
the center of the log-normal distribution
TYPE:
|
std |
the standard deviation of the log-normal distribution
TYPE:
|
Source code in src/amisc/rv.py
recenter(mu, std=None)
Move the center of the distribution to mu
with standard deviation std
(optional)
PARAMETER | DESCRIPTION |
---|---|
mu |
the new center of the distribution
TYPE:
|
std |
(optional) new standard deviation
TYPE:
|
Source code in src/amisc/rv.py
LogUniformRV(log10_a, log10_b, id='', **kwargs)
Bases: BaseRV
A base 10 log-uniform distributed random variable, only supports absolute bounds.
Construct the log-uniform random variable.
PARAMETER | DESCRIPTION |
---|---|
log10_a |
the lower bound in log10 space
TYPE:
|
log10_b |
the upper bound in log10 space
TYPE:
|
Source code in src/amisc/rv.py
NormalRV(mu, std, id='', **kwargs)
Bases: BaseRV
A normally-distributed random variable.
ATTRIBUTE | DESCRIPTION |
---|---|
mu |
float, the mean of the normal distribution
TYPE:
|
std |
float, the standard deviation of the normal distribution
TYPE:
|
Source code in src/amisc/rv.py
recenter(mu, std=None)
Move the center of the distribution to mu
with standard deviation std
(optional)
PARAMETER | DESCRIPTION |
---|---|
mu |
the new center of the distribution
TYPE:
|
std |
(optional) new standard deviation
TYPE:
|
Source code in src/amisc/rv.py
ScalarRV(id='', *, tex='', description='Random variable', units='-', param_type='calibration', nominal=1, domain=(0, 1))
Bases: BaseRV
A stand-in variable with no uncertainty/pdf, just scalars.
Child classes must implement sample
and pdf
methods.
Source code in src/amisc/rv.py
UniformRV(arg1, arg2, id='', **kwargs)
Bases: BaseRV
A uniformly-distributed random variable.
Can be uniformly distributed in one of three ways: between global bounds, relative within a percent, or relative within a set absolute tolerance.
ATTRIBUTE | DESCRIPTION |
---|---|
type |
specifies the type of uniform distribution, either 'bds', 'pct', or 'tol' as described above
TYPE:
|
value |
the absolute tolerance or percent uncertainty if type is 'tol' or 'pct'
TYPE:
|
Construct a uniformly-distributed random variable.
PARAMETER | DESCRIPTION |
---|---|
arg1 |
lower bound if specifying U(lb, ub), otherwise a tol or pct if specifying U(+/- tol/pct)
TYPE:
|
arg2 |
upper bound if specifying U(lb, ub), otherwise a str of either 'tol' or 'pct'
TYPE:
|
Source code in src/amisc/rv.py
get_uniform_bounds(nominal=None)
Return the correct set of bounds based on type of uniform distribution.
PARAMETER | DESCRIPTION |
---|---|
nominal |
the center value for relative uniform distributions
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[float, float]
|
the uniform bounds |
Source code in src/amisc/rv.py
pdf(x, nominal=None)
Compute the pdf for a uniform distribution.
PARAMETER | DESCRIPTION |
---|---|
x |
locations to compute the pdf at
TYPE:
|
nominal |
center location for relative uniform rvs
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
the evaluated PDF at |