det_gram
: Gramian determinant#
det_gram
#
- hypercoil.loss.det_gram(X: Tensor, theta: Tensor | None = None, *, op: ~typing.Callable | None = <function corr_kernel>, psi: float | None = 0.0, xi: float | None = 0.0, key: ~jax._src.random.PRNGKey | None = None)[source]#
Gramian determinant score function.
This function computes the determinant of the Gram matrix of the input tensor, defined according to the kernel function
op
. The kernel function should always be a positive semi-definite function, and additional arguments are provided to ensure a non-singular (i.e., strictly positive definite) matrix.- Parameters:
- XTensor
Input tensor.
- thetaTensor, optional (default:
None
) Kernel parameter tensor. If
None
, then the kernel is assumed to be isotropic.- opCallable, optional (default:
corr_kernel()
) Kernel function. By default, the Pearson correlation kernel is used.
- psifloat, optional (default:
0.
) Kernel regularisation parameter. If
psi > 0
, then the kernel matrix is regularised by addingpsi
to the diagonal. This can be used to ensure that the matrix is strictly positive definite.- xifloat, optional (default:
0.
) Kernel regularisation parameter. If
xi > 0
, then the kernel matrix is regularised by stochastically adding samples from a uniform distribution with support \(\psi - \xi, \xi\) to the diagonal. This can be used to ensure that the matrix does not have degenerate eigenvalues. Ifxi > 0
, thenpsi
must also be greater thanxi
and a key must be provided.- key: PRNGKey, optional (default: ``None``)
Random number generator key. This is only required if
xi > 0
.
- Returns:
- Tensor
Gramian determinant score for each set of observations.
GramDeterminantLoss
#
- class hypercoil.loss.GramDeterminantLoss(nu: float = 1.0, name: Optional[str] = None, *, op: Callable = <function corr_kernel>, theta: Optional[Tensor] = None, psi: float = 0.0, xi: float = 0.0, scalarisation: Optional[Callable] = None, key: Optional['jax.random.PRNGKey'] = None)[source]#
Loss based on the determinant of the Gram matrix.
This function computes the determinant of the Gram matrix of the input tensor, defined according to the kernel function
op
. The kernel function should always be a positive semi-definite function, and additional arguments are provided to ensure a non-singular (i.e., strictly positive definite) matrix.- Parameters:
- name: str
Designated name of the loss function. It is not required that this be specified, but it is recommended to ensure that the loss function can be identified in the context of a reporting utilities. If not explicitly specified, the name will be inferred from the class name and the name of the scoring function.
- nu: float
Loss strength multiplier. This is a scalar multiplier that is applied to the loss value before it is returned. This can be used to modulate the relative contributions of different loss functions to the overall loss value. It can also be used to implement a schedule for the loss function, by dynamically adjusting the multiplier over the course of training.
- thetaTensor, optional (default:
None
) Kernel parameter tensor. If
None
, then the kernel is assumed to be isotropic.- opCallable, optional (default:
corr_kernel()
) Kernel function. By default, the Pearson correlation kernel is used.
- psifloat, optional (default:
0.
) Kernel regularisation parameter. If
psi > 0
, then the kernel matrix is regularised by addingpsi
to the diagonal. This can be used to ensure that the matrix is strictly positive definite.- xifloat, optional (default:
0.
) Kernel regularisation parameter. If
xi > 0
, then the kernel matrix is regularised by stochastically adding samples from a uniform distribution with support \(\psi - \xi, \xi\) to the diagonal. This can be used to ensure that the matrix does not have degenerate eigenvalues. Ifxi > 0
, thenpsi
must also be greater thanxi
and a key must be provided.- key: PRNGKey, optional (default: ``None``)
Random number generator key. This is only required if
xi > 0
.- scalarisation: Callable
The scalarisation function to be used to aggregate the values returned by the scoring function. This function should take a single argument, which is a tensor of arbitrary shape, and return a single scalar value. By default, the mean scalarisation is used.