VinecopLike

class VinecopLike(*args, **kwargs)

Contract for a post-fit vine-copula evaluator.

A vine evaluator exposes the joint pdf / cdf, the rosenblatt and inverse_rosenblatt transforms, and a simulate sampler, plus a structure attribute (the RVineStructure it was built on). The optional keyword-only x covariate matrix (row-aligned with u) is the conditional extension — left None for the usual (unconditional) case. Subclass VinecopBase to get every method from a small set of hooks; pyvinecopulib.core.Vinecop and pyvinecopulib.torch.TorchVinecop are the reference implementations.

Methods

cdf(u, *[, x, N, num_threads, seeds])

Joint vine-copula distribution C(u) via Monte-Carlo.

inverse_rosenblatt(u, *[, x, num_threads])

Inverse Rosenblatt transform: independent uniforms to dependent uniforms.

pdf(u, *[, x, num_threads])

Joint vine-copula density c(u_1, ..., u_d) at each observation.

rosenblatt(u, *[, x, num_threads])

Rosenblatt transform: dependent uniforms to independent uniforms.

simulate(n, *[, x, qrng, num_threads, seeds])

Draw n samples from the fitted vine copula.

See also

pyvinecopulib.core.VinecopBase

Canonical partial implementation to subclass.

pyvinecopulib.core.Vinecop

The reference vine.

BicopLike

The pair-copula contract.

Examples

Host copulas in a vine by subclassing VinecopBase; the only required hook is _get_pair_copula. Under the default SimplifiedContext it is a classic (unconditional, simplified) vine, and hosting Bicop pairs reproduces from_structure():

import numpy as np
import pyvinecopulib as pv
from pyvinecopulib.core import VinecopBase

class ListVinecop(VinecopBase[np.ndarray]):
  def __init__(self, pairs, structure):
    self._pairs = pairs
    self._bind_vine(structure)          # SimplifiedContext by default

  def _get_pair_copula(self, tree, edge):
    return self._pairs[tree][edge]

struct = pv.RVineStructure.from_order([1, 2, 3])
g = pv.families.gaussian
pairs = [
  [pv.Bicop(family=g, parameters=np.array([[0.5]])),
   pv.Bicop(family=g, parameters=np.array([[0.4]]))],
  [pv.Bicop(family=g, parameters=np.array([[0.2]]))],
]
vine = ListVinecop(pairs, struct)
ref = pv.Vinecop.from_structure(structure=struct, pair_copulas=pairs)
u = np.random.default_rng(0).uniform(size=(4, 3))
np.allclose(vine.pdf(u), ref.pdf(u))    # -> True

Attributes

structure

Methods

__init__

cdf

Joint vine-copula distribution C(u) via Monte-Carlo.

inverse_rosenblatt

Inverse Rosenblatt transform: independent uniforms to dependent uniforms.

pdf

Joint vine-copula density c(u_1, ..., u_d) at each observation.

rosenblatt

Rosenblatt transform: dependent uniforms to independent uniforms.

simulate

Draw n samples from the fitted vine copula.