Linear Gaussian

A simple data generating process in which the mean and standard deviation of a normal distribution are specified by two parameterized lines.

class cde.density_simulation.LinearGaussian(ndim_x=1, mu=0.0, mu_slope=0.005, std=0.01, std_slope=0.002, random_seed=None)[source]

A simple, Gaussian conditional distribution where

x = U(-1,1) y = N(y | mean = mu_slope*x+mu, scale = std_slope*x+std)

Parameters
  • ndim_x – number of dimensions of x

  • mu – the intercept of the mean line

  • mu_slope – the slope of the mean line

  • std – the intercept of the std dev. line

  • std_slope – the slope of the std. dev. line

  • random_seed – seed for the random_number generator

cdf(X, Y)[source]

Conditional cumulated probability density function P(Y < y | x) of the underlying probability model

Parameters
  • X – x to be conditioned on - numpy array of shape (n_points, ndim_x)

  • Y – y target values for witch the cdf shall be evaluated - numpy array of shape (n_points, ndim_y)

Returns

P(Y < y | x) cumulated density values for the provided X and Y - numpy array of shape (n_points, )

conditional_value_at_risk(x_cond, alpha=0.01, **kwargs)[source]

Computes the Conditional Value-at-Risk (CVaR) / Expected Shortfall of the fitted distribution. Only if ndim_y = 1

Parameters
  • x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

  • alpha – quantile percentage of the distribution

  • n_samples – number of samples for monte carlo model_fitting

Returns

CVaR values for each x to condition on - numpy array of shape (n_values)

covariance(x_cond, n_samples=None)[source]

Covariance of the distribution conditioned on x_cond

Parameters

x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

Returns

Covariances Cov[y|x] corresponding to x_cond - numpy array of shape (n_values, ndim_y, ndim_y)

get_params(deep=True)

Get parameters for this estimator.

Parameters

deep (boolean, optional) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

kurtosis(x_cond, n_samples=1000000)

Kurtosis of the fitted distribution conditioned on x_cond

Parameters

x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

Returns

Kurtosis Kurt[y|x] corresponding to x_cond - numpy array of shape (n_values, ndim_y, ndim_y)

log_pdf(X, Y)

Conditional log-probability log p(y|x). Requires the model to be fitted.

Parameters
  • X – numpy array to be conditioned on - shape: (n_samples, n_dim_x)

  • Y – numpy array of y targets - shape: (n_samples, n_dim_y)

Returns

conditional log-probability log p(y|x) - numpy array of shape (n_query_samples, )

mean_(x_cond, n_samples=None)[source]

Conditional mean of the distribution :param x_cond: different x values to condition on - numpy array of shape (n_values, ndim_x)

Returns

Means E[y|x] corresponding to x_cond - numpy array of shape (n_values, ndim_y)

pdf(X, Y)[source]

Conditional probability density function p(y|x) of the underlying probability model

Parameters
  • X – x to be conditioned on - numpy array of shape (n_points, ndim_x)

  • Y – y target values for witch the pdf shall be evaluated - numpy array of shape (n_points, ndim_y)

Returns

p(X|Y) conditional density values for the provided X and Y - numpy array of shape (n_points, )

plot(xlim=(-5, 5), ylim=(-5, 5), resolution=100, mode='pdf', show=False, numpyfig=False)

Plots the distribution specified in mode if x and y are 1-dimensional each

Parameters
  • xlim – 2-tuple specifying the x axis limits

  • ylim – 2-tuple specifying the y axis limits

  • resolution – integer specifying the resolution of plot

  • mode – spefify which dist to plot [“pdf”, “cdf”, “joint_pdf”]

plot2d(x_cond=[0, 1, 2], ylim=(-8, 8), resolution=100, mode='pdf', show=True, prefix='', numpyfig=False)

Generates a 3d surface plot of the fitted conditional distribution if x and y are 1-dimensional each

Parameters
  • xlim – 2-tuple specifying the x axis limits

  • ylim – 2-tuple specifying the y axis limits

  • resolution – integer specifying the resolution of plot

plot3d(xlim=(-5, 5), ylim=(-8, 8), resolution=100, show=False, numpyfig=False)

Generates a 3d surface plot of the fitted conditional distribution if x and y are 1-dimensional each

Parameters
  • xlim – 2-tuple specifying the x axis limits

  • ylim – 2-tuple specifying the y axis limits

  • resolution – integer specifying the resolution of plot

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns

Return type

self

simulate(n_samples=1000)[source]

Draws random samples from the joint distribution p(x,y) :param n_samples: (int) number of samples to be drawn from the joint distribution

Returns

(X,Y) - random samples drawn from p(x,y) - numpy arrays of shape (n_samples, ndim_x) and (n_samples, ndim_y)

simulate_conditional(X)[source]

Draws random samples from the conditional distribution

Parameters

X – x to be conditioned on when drawing a sample from y ~ p(y|x) - numpy array of shape (n_samples, ndim_x)

Returns

Conditional random samples y drawn from p(y|x) - numpy array of shape (n_samples, ndim_y)

skewness(x_cond, n_samples=1000000)

Skewness of the fitted distribution conditioned on x_cond

Parameters

x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

Returns

Skewness Skew[y|x] corresponding to x_cond - numpy array of shape (n_values, ndim_y, ndim_y)

std_(x_cond, n_samples=1000000)

Standard deviation of the fitted distribution conditioned on x_cond

Parameters

x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

Returns

Standard deviations sqrt(Var[y|x]) corresponding to x_cond - numpy array of shape (n_values, ndim_y)

tail_risk_measures(x_cond, alpha=0.01, n_samples=10000000)[source]

Computes the Value-at-Risk (VaR) and Conditional Value-at-Risk (CVaR)

Parameters
  • x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

  • alpha – quantile percentage of the distribution

  • n_samples – number of samples for monte carlo model_fitting

Returns

  • VaR values for each x to condition on - numpy array of shape (n_values)

  • CVaR values for each x to condition on - numpy array of shape (n_values)

value_at_risk(x_cond, alpha=0.01, **kwargs)[source]

Computes the Value-at-Risk (VaR) of the fitted distribution. Only if ndim_y = 1

Parameters
  • x_cond – different x values to condition on - numpy array of shape (n_values, ndim_x)

  • alpha – quantile percentage of the distribution

Returns

VaR values for each x to condition on - numpy array of shape (n_values)