API documentation

Module mixedvine

This module implements a copula vine model with mixed marginals.

Classes

MixedVine

Copula vine model with mixed marginals.

class mixedvines.mixedvine.MixedVine(dim)

Represents a copula vine model with mixed marginals.

Parameters:
dimint

The number of marginals of the vine model. Must be greater than 1.

Raises:
ValueError

If the number of marginals dim is not greater than 1.

Attributes:
root_VineLayer

The root layer of the vine tree.

Methods

entropy([alpha, sem_tol, mc_size, random_state])

Estimates the entropy of the mixed vine.

fit(samples, is_continuous[, trunc_level, ...])

Fits the mixed vine to the given samples.

is_continuous()

Determines which marginals are continuous.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

rvs([size, random_state])

Generates random variates from the mixed vine.

set_copula(layer_index, copula_index, copula)

Sets a pair-copula.

set_marginal(marginal_index, rv_mixed)

Sets a marginal distribution.

entropy(alpha=0.05, sem_tol=0.001, mc_size=1000, random_state=None)

Estimates the entropy of the mixed vine.

Parameters:
alphafloat, optional

Significance level of the entropy estimate. (Default: 0.05)

sem_tolfloat, optional

Maximum standard error as a stopping criterion. (Default: 1e-3)

mc_sizeint, optional

Number of samples that are drawn in each iteration of the Monte Carlo estimation. (Default: 1000)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is genered and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
entfloat

Estimate of the mixed vine entropy in bits.

semfloat

Standard error of the mixed vine entropy estimate in bits.

static fit(samples, is_continuous, trunc_level=None, do_refine=False, keep_order=False)

Fits the mixed vine to the given samples.

Parameters:
samplesarray_like

n-by-d matrix of samples where n is the number of samples and d is the number of marginals.

is_continuousarray_like

List of boolean values of length d, where d is the number of marginals and element i is True if marginal i is continuous.

trunc_levelint, optional

Layer level to truncate the vine at. Copulas in layers beyond are just independence copulas. If the level is None, then the vine is not truncated. (Default: None)

do_refineboolean, optional

If True, then all pair-copula parameters are optimized jointly at the end. (Default: False)

keep_orderboolean, optional

If False, then a heuristic is used to select the vine structure. (Default: False)

Returns:
vineMixedVine

The mixed vine with parameters fitted to samples.

is_continuous()

Determines which marginals are continuous.

Returns:
array_like

List of boolean values of length d, where d is the number of marginals and element i is True if marginal i is continuous.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-d matrix of samples where n is the number of samples and d is the number of marginals.

Returns:
ndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-d matrix of samples where n is the number of samples and d is the number of marginals.

Returns:
ndarray

Probability density function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the mixed vine.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
array_like

n-by-d matrix of samples where n is the number of samples and d is the number of marginals.

set_copula(layer_index, copula_index, copula)

Sets a pair-copula.

Sets a particular pair-copula in the mixed vine tree for manual construction of a mixed vine model.

Parameters:
layer_indexint

The index of the vine layer.

copula_indexint

The index of the copula in its layer.

copulaCopula

The copula to be inserted.

Raises:
IndexError

If the argument layer_index is out of range.

set_marginal(marginal_index, rv_mixed)

Sets a marginal distribution.

Sets a particular marginal distribution in the mixed vine tree for manual construction of a mixed vine model.

Parameters:
marginal_indexint

The index of the marginal in the marginal layer.

rv_mixedscipy.stats.distributions.rv_frozen

The marginal distribution to be inserted.

Module marginal

This module implements univariate marginal distributions.

Classes

Marginal

Discrete or continuous marginal distribution.

class mixedvines.marginal.Marginal(rv_mixed)

Represents a continuous or discrete marginal distribution.

Parameters:
rv_mixedscipy.stats.distributions.rv_frozen

The distribution object, either of a continuous or of a discrete univariate distribution.

Attributes:
rv_mixedscipy.stats.distributions.rv_frozen

The distribution object.

is_continuousboolean

True if the distribution is continuous.

Methods

cdf(samples)

Calculates the cumulative distribution function.

fit(samples, is_continuous)

Fits a distribution to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppf(samples)

Calculates the inverse of the cumulative distribution function.

rvs([size, random_state])

Generates random variates from the distribution.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

Array of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

static fit(samples, is_continuous)

Fits a distribution to the given samples.

Parameters:
samplesarray_like

Array of samples.

is_continuousboolean

If True then a continuous distribution is fitted. Otherwise, a discrete distribution is fitted.

Returns:
best_marginalMarginal

The distribution fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

Array of samples.

Returns:
ndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

Array of samples.

Returns:
ndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

Array of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppf(samples)

Calculates the inverse of the cumulative distribution function.

Parameters:
samplesarray_like

Array of samples.

Returns:
ndarray

Inverse of the cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the distribution.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
array_like

Array of samples.

Module copula

This module implements bivariate copula distributions.

Classes

Copula

Abstract class representing a copula.

IndependenceCopula

Independence copula.

GaussianCopula

Copula from the Gaussian family.

ClaytonCopula

Copula from the Clayton family.

FrankCopula

Copula from the Frank family.

class mixedvines.copula.ClaytonCopula(theta=None, rotation=None)

Bases: Copula

This class represents a copula from the Clayton family.

Methods

ccdf(samples[, axis])

Calculates the conditional cumulative distribution function.

cdf(samples)

Calculates the cumulative distribution function.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

fit(samples)

Fits the parameters of the copula to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppcf(samples[, axis])

Calculates the inverse of the conditional CDF.

rvs([size, random_state])

Generates random variates from the copula.

theta_bounds()

Bounds for theta parameters.

ccdf(samples, axis=1)

Calculates the conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Conditional cumulative distribution function evaluated at samples.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

classmethod fit(samples)

Fits the parameters of the copula to the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
copulaCopula

The copula fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppcf(samples, axis=1)

Calculates the inverse of the conditional CDF.

Calculates the inverse of the copula conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Inverse of the conditional cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the copula.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

static theta_bounds()

Bounds for theta parameters.

Returns:
array_like

List of 2-tuples where the first tuple element represents the lower bound and the second element represents the upper bound.

class mixedvines.copula.Copula(theta=None, rotation=None)

Bases: ABC

This abstract class represents a copula.

Parameters:
thetaarray_like or float, optional

Parameter or parameter array of the copula. The number of elements depends on the copula family. (Default: None)

rotationstring, optional

Clockwise rotation of the copula. Can be one of the elements of Copula.rotation_options or None. (Default: None)

Attributes:
thetaarray_like or float

Parameter or parameter array of the copula.

rotationstring

Clockwise rotation of the copula.

Methods

ccdf(samples[, axis])

Calculates the conditional cumulative distribution function.

cdf(samples)

Calculates the cumulative distribution function.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

fit(samples)

Fits the parameters of the copula to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppcf(samples[, axis])

Calculates the inverse of the conditional CDF.

rvs([size, random_state])

Generates random variates from the copula.

theta_bounds()

Bounds for theta parameters.

ccdf(samples, axis=1)

Calculates the conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Conditional cumulative distribution function evaluated at samples.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

classmethod fit(samples)

Fits the parameters of the copula to the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
copulaCopula

The copula fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppcf(samples, axis=1)

Calculates the inverse of the conditional CDF.

Calculates the inverse of the copula conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Inverse of the conditional cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the copula.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

abstract static theta_bounds()

Bounds for theta parameters.

Returns:
array_like

List of 2-tuples where the first tuple element represents the lower bound and the second element represents the upper bound.

class mixedvines.copula.FrankCopula(theta=None, rotation=None)

Bases: Copula

This class represents a copula from the Frank family.

Methods

ccdf(samples[, axis])

Calculates the conditional cumulative distribution function.

cdf(samples)

Calculates the cumulative distribution function.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

fit(samples)

Fits the parameters of the copula to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppcf(samples[, axis])

Calculates the inverse of the conditional CDF.

rvs([size, random_state])

Generates random variates from the copula.

theta_bounds()

Bounds for theta parameters.

ccdf(samples, axis=1)

Calculates the conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Conditional cumulative distribution function evaluated at samples.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

classmethod fit(samples)

Fits the parameters of the copula to the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
copulaCopula

The copula fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppcf(samples, axis=1)

Calculates the inverse of the conditional CDF.

Calculates the inverse of the copula conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Inverse of the conditional cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the copula.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

static theta_bounds()

Bounds for theta parameters.

Returns:
array_like

List of 2-tuples where the first tuple element represents the lower bound and the second element represents the upper bound.

class mixedvines.copula.GaussianCopula(theta=None, rotation=None)

Bases: Copula

This class represents a copula from the Gaussian family.

Methods

ccdf(samples[, axis])

Calculates the conditional cumulative distribution function.

cdf(samples)

Calculates the cumulative distribution function.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

fit(samples)

Fits the parameters of the copula to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppcf(samples[, axis])

Calculates the inverse of the conditional CDF.

rvs([size, random_state])

Generates random variates from the copula.

theta_bounds()

Bounds for theta parameters.

ccdf(samples, axis=1)

Calculates the conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Conditional cumulative distribution function evaluated at samples.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

classmethod fit(samples)

Fits the parameters of the copula to the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
copulaCopula

The copula fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppcf(samples, axis=1)

Calculates the inverse of the conditional CDF.

Calculates the inverse of the copula conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Inverse of the conditional cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the copula.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

static theta_bounds()

Bounds for theta parameters.

Returns:
array_like

List of 2-tuples where the first tuple element represents the lower bound and the second element represents the upper bound.

class mixedvines.copula.IndependenceCopula(theta=None, rotation=None)

Bases: Copula

This class represents the independence copula.

Methods

ccdf(samples[, axis])

Calculates the conditional cumulative distribution function.

cdf(samples)

Calculates the cumulative distribution function.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

fit(samples)

Fits the parameters of the copula to the given samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

logpdf(samples)

Calculates the log of the probability density function.

pdf(samples)

Calculates the probability density function.

ppcf(samples[, axis])

Calculates the inverse of the conditional CDF.

rvs([size, random_state])

Generates random variates from the copula.

theta_bounds()

Bounds for theta parameters.

ccdf(samples, axis=1)

Calculates the conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Conditional cumulative distribution function evaluated at samples.

cdf(samples)

Calculates the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Cumulative distribution function evaluated at samples.

estimate_theta(samples)

Estimates the theta parameters from the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

classmethod fit(samples)

Fits the parameters of the copula to the given samples.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
copulaCopula

The copula fitted to samples.

logcdf(samples)

Calculates the log of the cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the cumulative distribution function evaluated at samples.

logpdf(samples)

Calculates the log of the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
valsndarray

Log of the probability density function evaluated at samples.

pdf(samples)

Calculates the probability density function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

Returns:
ndarray

Probability density function evaluated at samples.

ppcf(samples, axis=1)

Calculates the inverse of the conditional CDF.

Calculates the inverse of the copula conditional cumulative distribution function.

Parameters:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

axisint, optional

The axis to condition the cumulative distribution function on. (Default: 1)

Returns:
ndarray

Inverse of the conditional cumulative distribution function evaluated at samples.

rvs(size=1, random_state=None)

Generates random variates from the copula.

Parameters:
sizeint, optional

The number of samples to generate. (Default: 1)

random_state{None, int, numpy.random.Generator,

numpy.random.RandomState}, optional

The random state to use for random variate generation. None corresponds to the RandomState singleton. For an int, a new RandomState is generated and seeded. For a RandomState or Generator, the object is used. (Default: None)

Returns:
samplesarray_like

n-by-2 matrix of samples where n is the number of samples.

static theta_bounds()

Bounds for theta parameters.

Returns:
array_like

List of 2-tuples where the first tuple element represents the lower bound and the second element represents the upper bound.