Kernel Linear#
linear
#
| CLASS | DESCRIPTION |
|---|---|
LinearKernel |
Linear kernel for computing Gram matrices from feature matrices. |
| FUNCTION | DESCRIPTION |
|---|---|
linear_kernel |
Compute linear kernel matrix from feature matrix (functional interface). |
Classes#
LinearKernel(dtype: torch.dtype = torch.float32)
#
Bases: Kernel
Linear kernel for computing Gram matrices from feature matrices.
Computes the linear kernel (dot product kernel) as \(K = X X^\top\). Unlike distance-based kernels, this operates directly on feature matrices.
| PARAMETER | DESCRIPTION |
|---|---|
dtype
|
Data type for internal tensor computations.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get_kernel_params |
Return current kernel parameters. |
forward_step |
Compute linear kernel matrix (Gram matrix). |
Source code in spectre/kernel/linear.py
Functions#
get_kernel_params() -> dict[str, torch.Tensor]
#
Return current kernel parameters.
The linear kernel has no parameters.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
Empty dictionary (no parameters). |
forward_step(X: torch.Tensor, weights: torch.Tensor | None = None, **kwargs) -> torch.Tensor
#
Compute linear kernel matrix (Gram matrix).
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Feature matrix, shape (n_samples, n_features).
TYPE:
|
weights
|
Sample weights (not used in this implementation).
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the kernel.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Linear kernel matrix, shape (n_samples, n_samples). |
Source code in spectre/kernel/linear.py
Functions#
linear_kernel(X: torch.Tensor) -> torch.Tensor
#
Compute linear kernel matrix from feature matrix (functional interface).
The linear kernel is simply the Gram matrix.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Feature matrix, shape (n_samples, n_features).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Linear kernel matrix, shape (n_samples, n_samples). |