If you have a fitted model from pyvinecopulib (pvc), you can transfer its structure (the vine matrix) to a torchvinecopulib (tvc) model. This is useful for leveraging GPU acceleration or integrating with PyTorch.
Workflow:
- Convert data to pseudo-observations using
pvc.to_pseudo_obs(). - Fit a
pvc.Vinecop using pvc.Vinecop.from_data(). - Extract the
matrix from the pvc.Vinecop object. - Initialize a
tvc.VineCop and pass the matrix to the .fit() method.
import pyvinecopulib as pvc
import torchvinecopulib as tvc
# 1. Fit PVC model
controls = pvc.FitControlsVinecop(family_set=[pvc.BicopFamily.tll])
vine_pvc = pvc.Vinecop.from_data(u_cls, controls=controls)
# 2. Extract matrix and convert to torch format
# Subtract 1 because PVC uses 1-based indexing for the matrix
tvc_mat = torch.tensor(
np.array(vine_pvc.matrix, dtype=np.int32),
dtype=torch.int32,
device=DEVICE
).rot90(k=3) - 1
# 3. Fit TVC model using the PVC structure
vine_tvc = tvc.VineCop(
num_dim=u_cls.shape[1],
is_cop_scale=True,
num_step_grid=30,
).to(DEVICE)
vine_tvc.fit(
obs=u_cls_tensor,
matrix=tvc_mat,
is_dissmann=False,
mtd_kde="tll",
)