pysiglib.sig_kernel_gram_backprop#
Added in version v0.2.1.
- sig_kernel_gram_backprop(derivs, path1, path2, dyadic_order, time_aug=False, lead_lag=False, end_time=1.0, left_deriv=True, right_deriv=False, k_grid=None, n_jobs=1, max_batch=-1)[source]#
This function is required to backpropagate through
pysiglib.sig_kernel_gram. Given the derivatives of a scalar function \(F\) with respect to a gram matrix of signature kernels, \(\partial F / G\), returns the derivatives of \(F\) with respect to one or both of the underlying paths, \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\) and \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\).- Parameters:
derivs (numpy.ndarray | torch.tensor) – Derivatives with respect to a gram matrix of signature kernels, \(\partial F / G\).
path1 (numpy.ndarray | torch.tensor) – The first underlying path or batch of paths, given as a numpy.ndarray or torch.tensor. For a single path, this must be of shape
(length_1, dimension). For a batch of paths, this must be of shape(batch_size_1, length_1, dimension).path2 (numpy.ndarray | torch.tensor) – The second underlying path or batch of paths, given as a numpy.ndarray or torch.tensor. For a single path, this must be of shape
(length_2, dimension). For a batch of paths, this must be of shape(batch_size_2, length_2, dimension).dyadic_order (int | tuple) – The dyadic order(s) used to compute the signature kernels.
time_aug (bool) – If
True, assumes the paths were time augmented.lead_lag (bool) – If
True, assumes the lead-lag transform was applied.end_time (float) – End time for time-augmentation, \(t_L\).
left_deriv (bool) – If
True, returns \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\). At least one ofleft_derivandright_derivmust beTrue. If both areTrue, returns both derivatives as a tuple.right_deriv (bool) – If
True, returns \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\). At least one ofleft_derivandright_derivmust beTrue. If both areTrue, returns both derivatives as a tuple.k_grid (numpy.ndarray | torch.tensor) – Signature kernel PDE grid. If
None, the grid will be recomputed.n_jobs (int) – (Only applicable to CPU computation) Number of threads to run in parallel. If n_jobs = 1, the computation is run serially. If set to -1, all available threads are used. For n_jobs below -1, (max_threads + 1 + n_jobs) threads are used. For example if n_jobs = -2, all threads but one are used.
max_batch (int) – Maximum batch size to run in parallel. If the computation is failing due to insufficient memory, this parameter should be decreased. If set to -1, the entire batch is computed in parallel.
- Returns:
Tuple of derivatives of \(F\) with respect to one or both of the underlying paths. If
left_derivisTrue, the first element of this tuple is \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\), otherwise it isNone. Similarly forright_derivand \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\).- Return type:
numpy.ndarray | torch.tensor | Tuple[numpy.ndarray | numpy.ndarray] | Tuple[torch.tensor | torch.tensor]
Note
Ideally, any array passed to
pysiglib.sig_kernel_backpropshould be both contiguous and own its data. If this is not the case,pysiglib.sig_kernel_backpropwill internally create a contiguous copy, which may be inefficient.Note
When called via
pysiglib.torch_api, the default behaviour is to passk_grid = Noneand reconstruct the PDE grids. This is done to avoid memory allocation issues for large batch sizes.