GaussianCopula#
- class liesel.distributions.GaussianCopula(*args, **kwargs)[source]#
Bases:
TransformedDistributionThe bivariate Gaussian copula.
- Parameters:
dependence (default:
None) – The correlation parameter.validate_args (default:
False) – Pythonbool, defaultFalse. WhenTrue, distribution parameters are checked for validity despite possibly degrading runtime performance. WhenFalse, invalid inputs may silently render incorrect outputs.allow_nan_stats (default:
True) – Pythonbool, defaultTrue. WhenTrue, statistics (e.g., mean, mode, variance) use the valueNaNto indicate the result is undefined. WhenFalse, an exception is raised if one or more of the statistic’s batch members are undefined.name (default:
'GaussianCopula') – Pythonstr, name prefixed toOpscreated by this class.
See also
liesel.model.PITA Liesel variable for the probability integral transformation.
Examples
This is an example for how to use this class with Liesel.
>>> import jax.numpy as jnp >>> import liesel.model as lsl >>> import tensorflow_probability.substrates.jax.bijectors as tfb >>> import tensorflow_probability.substrates.jax.distributions as tfd >>> from liesel.distributions import GaussianCopula
>>> correlation = lsl.Var.new_param(0.2, bijector=tfb.Tanh(), name="rho") >>> correlation.bijected_var Var(name="h(rho)")
>>> dist1 = lsl.Dist(tfd.Normal, loc=0.0, scale=1.0) >>> x1 = lsl.Var.new_obs(jnp.array([-0.5, -0.1, -0.25]), dist1).update() >>> dist2 = lsl.Dist(tfd.Normal, loc=0.0, scale=1.0) >>> x2 = lsl.Var.new_obs(jnp.array([0.5, 0.1, 0.25]), dist2).update()
>>> x1_pit = lsl.PIT(x1, name="PIT(x1)").update() >>> x2_pit = lsl.PIT(x2, name="PIT(x2)").update() >>> x_dependence = lsl.Var.new_calc( ... lambda *inputs: jnp.stack(inputs, axis=1), ... x1_pit, ... x2_pit, ... dist=lsl.Dist(GaussianCopula, dependence=correlation), ... name="x_dependence", ... ).update()
>>> (x1.log_prob + x2.log_prob + x_dependence.log_prob).sum().round(1) Array(-5.9, dtype=float32)
Comparing to an ordinary multivariate normal:
>>> dist = tfd.MultivariateNormalFullCovariance( ... loc=jnp.zeros(2), covariance_matrix=jnp.array([[1.0, 0.2], [0.2, 1.0]]) ... ) >>> dist.log_prob(jnp.stack((x1.value, x2.value), axis=-1)).sum().round(1) Array(-5.9, dtype=float32)
Methods
cross_entropy(other[, name])Computes the (Shannon) cross entropy.
kl_divergence(other[, name])Computes the Kullback--Leibler divergence.