IndependentMarginalsVariable

class pyapprox.variables.IndependentMarginalsVariable(unique_variables, unique_variable_indices=None, variable_labels=None)[source]

Bases: JointVariable

Class representing independent random variables

Examples

>>> from pyapprox.variables.joint import IndependentMarginalsVariable
>>> from scipy.stats import norm, beta
>>> marginals = [norm(0,1),beta(0,1),norm()]
>>> variable = IndependentMarginalsVariable(marginals)
>>> print(variable)
I.I.D. Variable
Number of variables: 3
Unique variables and global id:
    norm(loc=0,scale=1): z0, z2
    beta(a=0,b=1,loc=0,scale=1): z1

Methods Summary

evaluate(function_name, x)

Evaluate a frunction for each univariate random variable.

get_statistics(function_name, *args, **kwargs)

Get a statistic from each univariate random variable.

is_bounded_continuous_variable()

Are all 1D variables are continuous and bounded.

marginals()

Return a list of all the 1D scipy.stats random variables.

num_vars()

Return The number of independent 1D variables

pdf(x[, log])

Evaluate the joint probability distribution function.

rvs(num_samples[, random_states])

Generate samples from a tensor-product probability measure.

Methods Documentation

evaluate(function_name, x)[source]

Evaluate a frunction for each univariate random variable.

Parameters:
function_namestring

The function name of the scipy random variable statistic of interest

xnp.ndarray (nsamples)

The input to the scipy statistic function

Returns:
statnp.ndarray (nsamples, nqoi)

The outputs of the stat function for each variable

get_statistics(function_name, *args, **kwargs)[source]

Get a statistic from each univariate random variable.

Parameters:
function_namestring

The function name of the scipy random variable statistic of interest

kwargskwargs

The arguments to the scipy statistic function

Returns:
statnp.ndarray

The output of the stat function

Examples

>>> import pyapprox as pya
>>> from scipy.stats import uniform
>>> num_vars = 2
>>> variable = pya.IndependentMarginalsVariable([uniform(-2, 3)], [np.arange(num_vars)])
>>> variable.get_statistics("interval", confidence=1)
array([[-2.,  1.],
       [-2.,  1.]])
>>> variable.get_statistics("pdf",x=np.linspace(-2, 1, 3))
array([[0.33333333, 0.33333333, 0.33333333],
       [0.33333333, 0.33333333, 0.33333333]])
is_bounded_continuous_variable()[source]

Are all 1D variables are continuous and bounded.

Returns:
is_boundedboolean

True - all 1D variables are continuous and bounded False - otherwise

marginals()[source]

Return a list of all the 1D scipy.stats random variables.

Returns:
variableslist

List of scipy.stats.dist variables

num_vars()[source]

Return The number of independent 1D variables

Returns:
nvarsinteger

The number of independent 1D variables

pdf(x, log=False)[source]

Evaluate the joint probability distribution function.

Parameters:
xnp.ndarray (nvars, nsamples)

Values in the domain of the random variable X

logboolean

True - return the natural logarithm of the PDF values False - return the PDF values

Returns:
valuesnp.ndarray (nsamples, 1)

The values of the PDF at x

rvs(num_samples, random_states=None)[source]

Generate samples from a tensor-product probability measure.

Parameters:
num_samplesinteger

The number of samples to generate

Returns:
samplesnp.ndarray (num_vars, num_samples)

Independent samples from the target distribution