dymad.modules.kernel¶
Functions
|
Inverse of softplus, for initialization. |
|
Pairwise distance ||X/scale - Z/scale||^p with broadcasting-friendly scaling. |
Classes
|
Base interface for all kernels (scalar or operator-valued). |
|
Separable operator-valued kernel K(x,z) = sum_i k_i(x,z; ell) * B_i where B_i = L_i L_i^T is PSD and learnable. |
|
Operator-valued kernel for vector fields on a manifold |
|
|
|
Operator-valued kernel induced by scalar kernels Output shape: (..., N, Dy, M, Dy) |
|
Symmetric-normalized diffusion kernel via diffusion maps. |
|
Scalar Exponential: k(x,z) = exp(-||x - z|| / ell) Learnable positive lengthscale. |
|
Scalar RBF: k(x,z) = exp(-0.5 * ||x - z||^2 / ell^2) Learnable positive lengthscale. |
|
- class dymad.modules.kernel.KernelAbstract(in_dim, dtype=None)¶
Bases:
Module,ABCBase interface for all kernels (scalar or operator-valued).
- abstractmethod forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- abstract property is_operator_valued: bool¶
True for operator-valued kernels; False for scalar kernels.
- set_reference_data(Xref)¶
Prepare data-dependent structures from Xref (N,d). Must be differentiable if kernel params are learnable.
By default the kernel is data-independent and does nothing.
- Return type:
None
- class dymad.modules.kernel.KernelOpSeparable(kernels, out_dim, Ls=None, dtype=None)¶
Bases:
KernelOperatorValuedScalarsSeparable operator-valued kernel K(x,z) = sum_i k_i(x,z; ell) * B_i where B_i = L_i L_i^T is PSD and learnable. Output shape: (…, N, Dy, M, Dy)
- forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- class dymad.modules.kernel.KernelOpTangent(kernel, out_dim, dtype=None)¶
Bases:
KernelOperatorValuedOperator-valued kernel for vector fields on a manifold
For manifold of intrinsic dimension d and ambient dimension Dy:
K(x,z) = k(x,z; ell) * T(x’) O(x’,z’) T(z’)^T
where O(x’,z’) = T(x’)^T T(z’) and T, of (Dy,d), are tangent basis vectors at x’ and z’, and the ‘ denotes the state part of the input (the first out_dim dimensions). k is a scalar kernel that includes both states and inputs.
Returns a factored representation of the kernel to stay in intrinsic dimension
k(x,z; ell) O(x,z), T(x), T(z)
of shapes: (…, d, M, d), (…, d, Dy), (M, d, Dy)
- forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- set_manifold(manifold)¶
- Return type:
None
- set_reference_data(Xref)¶
Prepare data-dependent structures from Xref (N,d). Must be differentiable if kernel params are learnable.
By default the kernel is data-independent and does nothing.
- Return type:
None
- class dymad.modules.kernel.KernelOperatorValued(in_dim, out_dim, dtype=None)¶
Bases:
KernelAbstract,ABC- property is_operator_valued: bool¶
True for operator-valued kernels; False for scalar kernels.
- class dymad.modules.kernel.KernelOperatorValuedScalars(kernels, out_dim, dtype=None)¶
Bases:
KernelOperatorValuedOperator-valued kernel induced by scalar kernels Output shape: (…, N, Dy, M, Dy)
- set_reference_data(Xref)¶
Prepare data-dependent structures from Xref (N,d). Must be differentiable if kernel params are learnable.
By default the kernel is data-independent and does nothing.
- Return type:
None
- class dymad.modules.kernel.KernelScDM(in_dim, eps_init=None, t_init=1.0, dtype=None)¶
Bases:
KernelScalarValuedSymmetric-normalized diffusion kernel via diffusion maps.
Everything keeps autograd for eps and t.
- property eps¶
- forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- set_reference_data(Xref)¶
Prepare data-dependent structures from Xref (N,d). Must be differentiable if kernel params are learnable.
By default the kernel is data-independent and does nothing.
- Return type:
None
- property t¶
- class dymad.modules.kernel.KernelScExp(in_dim, lengthscale_init=None, dtype=None)¶
Bases:
KernelScalarValuedScalar Exponential: k(x,z) = exp(-||x - z|| / ell) Learnable positive lengthscale.
- property ell¶
- forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- class dymad.modules.kernel.KernelScRBF(in_dim, lengthscale_init=None, dtype=None)¶
Bases:
KernelScalarValuedScalar RBF: k(x,z) = exp(-0.5 * ||x - z||^2 / ell^2) Learnable positive lengthscale.
- property ell¶
- forward(X, Z=None)¶
Compute kernel between X (N,d) and Z (M,d).
If Z is None, compute K(X,X).
- Returns:
(N, M) - Operator-valued kernels: (N, Dy, M, Dy)
- Return type:
Scalar kernels
- set_reference_data(Xref)¶
Prepare data-dependent structures from Xref (N,d). Must be differentiable if kernel params are learnable.
By default the kernel is data-independent and does nothing.
- Return type:
None
- class dymad.modules.kernel.KernelScalarValued(in_dim, dtype=None)¶
Bases:
KernelAbstract,ABC- property is_operator_valued: bool¶
True for operator-valued kernels; False for scalar kernels.
- dymad.modules.kernel.inv_softplus(y, dtype)¶
Inverse of softplus, for initialization.
- Return type:
Tensor
- dymad.modules.kernel.scaled_cdist(X, Z, scale, p)¶
Pairwise distance ||X/scale - Z/scale||^p with broadcasting-friendly scaling.
- Parameters:
X (torch.Tensor) – (N,d)
Z (torch.Tensor) – (M,d)
scale (float or torch.Tensor) – (d,) or scalar, positive
p (float) – order of the norm
- Return type:
Tensor