Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
GaussianCopula Class Referencefinal

Gaussian copula based on a correlation matrix. More...

#include <GaussianCopula.h>

Inheritance diagram for GaussianCopula:
Collaboration diagram for GaussianCopula:

Public Member Functions

 GaussianCopula (unsigned int seed, RealMatrix R)
 Constructs a Gaussian copula from a correlation matrix.
 
std::vector< Vectorsample_u (std::size_t n) override
 Draws multiple samples from the copula.
 
Vector sample_u () override
 Draws a single sample from the copula.
 
double log_density (Vector u) override
 Evaluates the log-density of the copula at a point in the unit cube.
 
RealMatrix dlog_density (std::vector< double > u) override
 Computes the gradient of the Gaussian copula log-density.
 
RealMatrix ddlog_density (std::vector< double > u) override
 Computes the Hessian of the Gaussian copula log-density.
 
LogDensityDiff log_c_dc_ddc (std::vector< double > u) override
 Computes the log-density and its first and second derivatives.
 
- Public Member Functions inherited from GenericCopula
 GenericCopula (unsigned int seed=std::random_device{}())
 Constructs the copula base with a seeded random engine.
 
- Public Member Functions inherited from ICopula
virtual ~ICopula ()=default
 Virtual destructor.
 

Additional Inherited Members

- Protected Attributes inherited from GenericCopula
const gsl_rng_type * rng_tp {gsl_rng_mt19937}
 
gsl_rng_sptr eng_ {nullptr, &gsl_rng_free}
 GSL RNG type used by the copula.
 

Detailed Description

Gaussian copula based on a correlation matrix.

Internally, the copula stores:

  • a correlation matrix R,
  • its inverse,
  • its Cholesky factor,
  • and its log-determinant.

Sampling:

  • draw a standard Gaussian vector,
  • correlate it with the Cholesky factor,
  • map each component through the Gaussian CDF.

Density evaluation:

  • transform uniforms back to Gaussian latent variables,
  • evaluate the standard Gaussian copula log-density.
Note
The input matrix is regularized through nearest_psd before use.

Definition at line 63 of file GaussianCopula.h.

Constructor & Destructor Documentation

◆ GaussianCopula()

GaussianCopula::GaussianCopula ( unsigned int  seed,
RealMatrix  R 
)
explicit

Constructs a Gaussian copula from a correlation matrix.

The matrix is projected to a nearest positive semidefinite correlation matrix before decomposition.

Parameters
seedSeed for the RNG.
RCorrelation matrix.

Definition at line 3 of file GaussianCopula.cpp.

Member Function Documentation

◆ ddlog_density()

RealMatrix GaussianCopula::ddlog_density ( std::vector< double >  u)
overridevirtual

Computes the Hessian of the Gaussian copula log-density.

Parameters
uUniform vector in $(0,1)^d$.
Returns
Matrix containing second derivatives with respect to u.

Implements ICopula.

Definition at line 66 of file GaussianCopula.cpp.

◆ dlog_density()

RealMatrix GaussianCopula::dlog_density ( std::vector< double >  u)
overridevirtual

Computes the gradient of the Gaussian copula log-density.

Parameters
uUniform vector in $(0,1)^d$.
Returns
Column matrix containing $\nabla_u \log c(u)$.

Implements ICopula.

Definition at line 49 of file GaussianCopula.cpp.

◆ log_c_dc_ddc()

LogDensityDiff GaussianCopula::log_c_dc_ddc ( std::vector< double >  u)
overridevirtual

Computes the log-density and its first and second derivatives.

This combined evaluation is intended to avoid repeated transformations of the same uniform vector when curvature information is required.

Parameters
uUniform vector in $(0,1)^d$.
Returns
Aggregated log-density, gradient and Hessian information.

Implements ICopula.

Definition at line 89 of file GaussianCopula.cpp.

◆ log_density()

double GaussianCopula::log_density ( Vector  u)
overridevirtual

Evaluates the log-density of the copula at a point in the unit cube.

Parameters
uPoint in $[0,1]^d$.
Returns
$\log c(u)$, where $c$ is the copula density.

This evaluates the Gaussian copula density:

\[
  \log c(u)
  = -\frac12 \log\det(R)
    - \frac12 z^\top (R^{-1} - I) z
\]

where $z_i = \Phi^{-1}(u_i)$.

Implements ICopula.

Definition at line 37 of file GaussianCopula.cpp.

◆ sample_u() [1/2]

std::vector< double > GaussianCopula::sample_u ( )
overridevirtual

Draws a single sample from the copula.

Returns
One dependent uniform sample in $[0,1]^d$.

Implements ICopula.

Definition at line 20 of file GaussianCopula.cpp.

◆ sample_u() [2/2]

std::vector< std::vector< double > > GaussianCopula::sample_u ( std::size_t  n)
overridevirtual

Draws multiple samples from the copula.

Each sample is a vector of uniform variates on $[0,1]$ whose dependence is governed by the copula.

Parameters
nNumber of samples to generate.
Returns
A vector of samples, each of dimension equal to the copula dimension.

Implements ICopula.

Definition at line 10 of file GaussianCopula.cpp.


The documentation for this class was generated from the following files: