VinecopBase

class VinecopBase(*args, **kwargs)

Canonical array-agnostic vine cascades (numpy / torch).

Concrete subclasses implement _get_pair_copula (and optionally override _prep / _simulate_uniform / the batched-path hooks) and call _bind_vine once; they then inherit the whole evaluator surface — pdf / cdf / rosenblatt / inverse_rosenblatt / simulate, loglik / plot / __repr__, the dim / trunc_lvl / order accessors, and the fit() / select() engines. Not an nn.Module, so it composes with any pair-copula implementation (including non-torch ones).

Attributes:
dim

Number of variables in the vine.

matrix

R-vine structure matrix (from structure).

Methods

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

Evaluate the joint CDF at each query row via quasi-Monte-Carlo.

fit(structure, u, fit_edge, *[, context, x])

Fit pair copulas tree-by-tree along a fixed structure (returns them).

get_pair_copula(tree, edge)

Return the pair copula at (tree, edge).

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

Inverse Rosenblatt transform: independent uniforms to dependent uniforms.

loglik(u, *[, x])

Total log-likelihood sum(log c(u)) of the vine at u.

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

Evaluate the vine-copula density c(u_1, ..., u_d).

plot([tree, add_edge_labels, layout, vars_names])

Plot the vine tree structure with networkx.

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

Rosenblatt transform: dependent uniforms to independent uniforms.

select(u, fit_edge, *[, trunc_lvl, ...])

Select an R-vine structure from data (array-agnostic Dissmann).

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

Simulate n samples from the fitted copula.

See also

pyvinecopulib.core.VinecopLike

The contract this implements.

pyvinecopulib.core.Vinecop

The reference vine.

pyvinecopulib.core.ConditioningContext

Per-edge conditioning policy.

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

dim

Number of variables in the vine.

matrix

R-vine structure matrix (from structure).

structure

d

trunc_lvl

order

inverse_order

Methods

__init__

cdf

Evaluate the joint CDF at each query row via quasi-Monte-Carlo.

fit

Fit pair copulas tree-by-tree along a fixed structure (returns them).

get_pair_copula

Return the pair copula at (tree, edge).

inverse_rosenblatt

Inverse Rosenblatt transform: independent uniforms to dependent uniforms.

loglik

Total log-likelihood sum(log c(u)) of the vine at u.

pdf

Evaluate the vine-copula density c(u_1, ..., u_d).

plot

Plot the vine tree structure with networkx.

rosenblatt

Rosenblatt transform: dependent uniforms to independent uniforms.

select

Select an R-vine structure from data (array-agnostic Dissmann).

simulate

Simulate n samples from the fitted copula.