Kernel, MLP & Gaussian Process
SVR
Epsilon-Support Vector Regression using 2N LIBSVM-style dual SMO and hardware-accelerated kernel Gram matrices.
Overview
SVR implements epsilon-insensitive Support Vector Regression using a 2N LIBSVM-style dual Sequential Minimal Optimization (SMO) solver in Rust. Predictions within an epsilon-tube around the target incur no loss, while points outside the tube become support vectors weighted by C. (^▽^)
Backend Support
- Primitives:
N3(pairwise L2 distance for RBF kernels),E1(dense matrix multiplication for linear, polynomial, and sigmoid Gram matrices) - Devices:
cpu(Rayon parallelf64),cuda/cuda:0(dynamic cuBLAS),wgpu(Vulkan/Metal/DX12),tpu(OpenXLA PJRT), andauto - Persistence:
.ditbinary format viasave()/load()(andochreml.save()/ochreml.load()), plus Pythonpicklesupport
Import & Signature
from ochreml.svm import SVR
# Also available from top-level: from ochreml import SVR
SVR(
kernel: str = "rbf",
degree: int = 3,
gamma: str | float = "scale",
coef0: float = 0.0,
tol: float = 1e-3,
C: float = 1.0,
epsilon: float = 0.1,
max_iter: int = -1,
device: str | None = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
kernel | {"linear", "poly", "rbf", "sigmoid", "precomputed"} | "rbf" | Kernel function used to compute the Gram matrix. |
degree | int | 3 | Degree of the polynomial kernel (kernel="poly"). Ignored by other kernels. |
gamma | {"scale", "auto"} or float | "scale" | Kernel coefficient for "rbf", "poly", and "sigmoid". "scale" uses 1 / (n_features * X.var()); "auto" uses 1 / n_features. |
coef0 | float | 0.0 | Independent term in "poly" and "sigmoid" kernel functions. |
tol | float | 1e-3 | Tolerance for the SMO stopping criterion. |
C | float | 1.0 | Regularization parameter. Must be strictly positive (C > 0). |
epsilon | float | 0.1 | Width of the epsilon-tube within which no penalty is associated in the training loss function. |
max_iter | int | -1 | Hard limit on solver iterations, or -1 for no limit. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
support_ | ndarray of shape (n_SV,) | Indices of support vectors in the training set. |
support_vectors_ | ndarray of shape (n_SV, n_features) | Support vectors extracted during fitting. |
dual_coef_ | ndarray of shape (1, n_SV) | Dual coefficients of the support vectors in the regression function. |
intercept_ | ndarray of shape (1,) | Constant intercept term in the decision function. |
n_features_in_ | int | Number of features seen during fit(). |
device_ | str | None | Resolved execution device string. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y) -> SVR | Fit the SVR model on feature matrix X and continuous target vector y. |
predict | predict(X) -> ndarray | Predict continuous target values for samples in X. |
score | score(X, y) -> float | Return the coefficient of determination (R^2) on (X, y). |
to | to(device) -> SVR | Move the estimator's compute target to another device. |
save | save(path) -> None | Save the fitted model to a .dit binary file. |
load | SVR.load(path, device=None) -> SVR | Class method to load a fitted model from a .dit file. |
Example
import numpy as np
from ochreml.svm import SVR
rng = np.random.default_rng(42)
X = np.linspace(-3.0, 3.0, 60).reshape(-1, 1)
y = np.sin(X[:, 0]) + 0.05 * rng.normal(size=60)
reg = SVR(kernel="rbf", C=10.0, epsilon=0.05, gamma="scale")
reg.fit(X, y)
X_query = np.array([[-1.5], [0.0], [1.5]])
print("Predictions:", reg.predict(X_query))
print("R^2 score:", reg.score(X, y))
print("Number of support vectors:", len(reg.support_))