bqme package

Submodules

bqme.distributions module

class bqme.distributions.Distribution(parameters_dict: Dict[str, bqme.variables.Variable], name: str)

Bases: object

Base class for all distribution Key and values of parameters_dict needs the same order as the input to the distribution in stan.

cdf(x: List[float]) → numpy.ndarray
code() → Dict[str, str]
domain()
logcdf(x: List[float]) → numpy.ndarray
logpdf(x: List[float]) → numpy.ndarray
pdf(x: List[float]) → numpy.ndarray
ppf(q: List[float]) → numpy.ndarray
class bqme.distributions.Gamma(alpha: float, beta: float, name: str)

Bases: bqme.distributions.Distribution

Container for Gamma Distribution

alphafloat

shape of the Gamma

betafloat

rate of the Gamma

name : str

>>> Gamma(1., 1., name='sigma')
Gamma(alpha=1.0, beta=1.0, name="sigma")
>>> Gamma(1.1, 1.0, name='sigma').code()
{'parameter': 'real<lower=0> sigma;', 'prior': 'sigma ~ gamma(1.1, 1.0);'}
domain() → Tuple[float, float]
class bqme.distributions.Lognormal(mu: float, sigma: float, name: str)

Bases: bqme.distributions.Distribution

Container for Lognormal Distribution

mufloat

log(rv) has loc mu

sigmafloat

log(rv) has scale sigma

name : str

>>> Lognormal(1., 1., name='sigma')
Lognormal(mu=1.0, sigma=1.0, name="sigma")
>>> Lognormal(1.1, 1.0, name='sigma').code()
{'parameter': 'real<lower=0> sigma;', 'prior': 'sigma ~ lognormal(1.1, 1.0);'}
domain() → Tuple[float, float]
class bqme.distributions.Normal(mu: float, sigma: float, name: str)

Bases: bqme.distributions.Distribution

Container for Normal Distribution

mufloat

location of the normal

sigmafloat

standard deviation of the normal

name : str

>>> Normal(0, 1, name='mu')
Normal(mu=0, sigma=1, name="mu")
>>> Normal(0, 1, name='mu').code()
{'parameter': 'real mu;', 'prior': 'mu ~ normal(0, 1);'}
domain() → Tuple[float, float]
class bqme.distributions.Weibull(alpha: float, sigma: float, name: str)

Bases: bqme.distributions.Distribution

Container for Weibull Distribution

alphafloat

shape of the weibull

sigmafloat

scale of the weibull - equivalent to 1/rate

name : str

>>> Weibull(1., 1., name='sigma')
Weibull(alpha=1.0, sigma=1.0, name="sigma")
>>> Weibull(1.1, 1.0, name='sigma').code()
{'parameter': 'real<lower=0> sigma;', 'prior': 'sigma ~ weibull(1.1, 1.0);'}
domain() → Tuple[float, float]

bqme.fit_object module

class bqme.fit_object.FitObject

Bases: object

Base class for the fit object

cdf(x: float, method='mean')

Calculates the cdf of x using posterior samples or MAP estimate

xfloat or List[float]

points where the cdf should be evaluated

method: str, default: ‘mean’

if sampling is used possible values are (‘mean’, ‘median’, ‘full’). Return values is the mean over all samples if ‘mean’ is selected. Otherwise median or the full matrix is returned if optimizing is used return values are the pdf evaluation of the model at x.

ret : ndarray

pdf(x: float, method='mean')

Calculates the pdf of x using posterior samples or MAP estimate

xfloat or List[float]

points where the pdf should be evaluated

method: str, default: ‘mean’

if sampling is used possible values are (‘mean’, ‘median’, ‘full’). Return values is the mean over all samples if ‘mean’ is selected. Otherwise median or the full matrix is returned if optimizing is used return values are the pdf evaluation of the model at x.

ret : ndarray

ppf(q: float, method='full')

Calculates the percent point funtion (ppf) of x using posterior samples or MAP estimate

qfloat or List[float]

points where the ppf should be evaluated. Must be in range (0, 1)

method: str, default: ‘mean’

if sampling is used possible values are (‘mean’, ‘median’, ‘full’). Return values is the mean over all samples if ‘mean’ is selected. Otherwise median or the full matrix is returned if optimizing is used return values are the pdf evaluation of the model at x.

ret : ndarray

class bqme.fit_object.FitObjectOptimizing(model: QM, opt_parameters: Dict)

Bases: bqme.fit_object.FitObject

Fit object using MAP estimate of the model

class bqme.fit_object.FitObjectSampling(model: QM, stan_fit_object: StanFit4Model)

Bases: bqme.fit_object.FitObject

Fit object using posterior samples of the model. This is an extension of the ‘StanFit4Model’-type by composition.

bqme.models module

class bqme.models.GammaQM(alpha: bqme.distributions.Distribution, beta: bqme.distributions.Distribution)

Bases: bqme.models.QM

Quantile matching using Gamma distribution

alphaDistribution

Also called the shape of the Gamma

betaDistribution

Also called the rate of the Gamma

>>> from bqme.distributions import Gamma
>>> model = GammaQM(Gamma(1., 1. ,'alpha'), Gamma(1., 1., 'beta'))
>>> model
GammaQM(Gamma(alpha=1.0, beta=1.0, name="alpha"), Gamma(alpha=1.0, beta=1.0, name="beta"))
>>> code = model.code
domain() → Tuple[float, float]
class bqme.models.LognormalQM(mu: bqme.distributions.Distribution, sigma: bqme.distributions.Distribution)

Bases: bqme.models.QM

Quantile matching using Lognormal distribution

muDistribution

location of the corresponding Normal distribution

sigmaDistribution

scale of the corresponding Normal distribution

>>> from bqme.distributions import Lognormal, Normal
>>> model = LognormalQM(Normal(1., 1. ,'mu'), Lognormal(1., 1., 'sigma'))
>>> model
LognormalQM(Normal(mu=1.0, sigma=1.0, name="mu"), Lognormal(mu=1.0, sigma=1.0, name="sigma"))
>>> code = model.code
domain() → Tuple[float, float]
class bqme.models.NormalQM(mu: bqme.distributions.Distribution, sigma: bqme.distributions.Distribution)

Bases: bqme.models.QM

Quantile matching using Normal distribution

muDistribution

location of the Normal

sigmaDistribution

scale of the Normal

>>> from bqme.distributions import Normal, Gamma
>>> model = NormalQM(Normal(0., 1., 'mu'), Gamma(1., 1., 'sigma'))
>>> model
NormalQM(Normal(mu=0.0, sigma=1.0, name="mu"), Gamma(alpha=1.0, beta=1.0, name="sigma"))
>>> code = model.code
domain() → Tuple[float, float]
class bqme.models.QM(parameters_dict: Dict[str, bqme.distributions.Distribution])

Bases: object

Base class for quantile matching (QM) models

parameters_dictDict

Keys are internal names for the priors of the model e.g. ‘mu’, ‘sigma’ for a GaussianQM. Values are the user defined Distributions. Note key must not be identical to value.name.

property code

returns the final stan code

compile()
domain()
optimizing(N: int, q: Tuple[float, ], X: Tuple[float, ]) → StanFit4Model
sampling(N: int, q: Tuple[float, ], X: Tuple[float, ]) → StanFit4Model
class bqme.models.WeibullQM(alpha: bqme.distributions.Distribution, sigma: bqme.distributions.Distribution)

Bases: bqme.models.QM

Quantile matching using Weibull distribution

alphaDistribution

Also called the shape of the Weibull

sigmaDistribution

Also called the scale of the Weibull

>>> from bqme.distributions import Weibull
>>> model = WeibullQM(Weibull(1., 1. ,'alpha'), Weibull(1., 1., 'sigma'))
>>> model
WeibullQM(Weibull(alpha=1.0, sigma=1.0, name="alpha"), Weibull(alpha=1.0, sigma=1.0, name="sigma"))
>>> code = model.code
domain() → Tuple[float, float]

bqme.variables module

class bqme.variables.ContinuousVariable(value: float, name: str)

Bases: bqme.variables.Variable

container for continuous variables (-inf, inf)

class bqme.variables.PositiveContinuousVariable(value: float, name: str)

Bases: bqme.variables.Variable

container for positive continous variables (0, inf)

class bqme.variables.Variable(value: float, name: str, lower: float, upper: float)

Bases: object

Base class for different kind of variables

approve(value: float) → float

Module contents