pub struct QuantumSVMModel { /* private fields */ }Expand description
Quantum-Enhanced Support Vector Machine
Implements a kernel SVM where the kernel is computed via a quantum-inspired
random Fourier feature map (Rahimi-Recht approximation of the RBF kernel).
The feature map φ(x) = √(2/D) · [cos(ω₁ᵀx + b₁), …, cos(ω_Dᵀx + b_D)]ᵀ
approximates exp(-‖x - z‖² / (2σ²)) for random ωᵢ ~ N(0, I/σ²) and
bᵢ ~ Uniform[0, 2π].
§Training Algorithm
Binary classification is performed via a coordinate-descent dual SVM solver (simplified SMO) on the quantum kernel matrix, respecting the box constraint 0 ≤ αᵢ ≤ C for all support vectors.
§Example
use scirs2_core::ndarray::{Array1, Array2};
use scirs2_spatial::quantum_inspired::algorithms::quantum_machine_learning::QuantumSVMModel;
// Two-class separable dataset (4 points, 2 features)
let x = Array2::from_shape_vec((4, 2), vec![
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
5.0, 5.0,
])?;
let y = Array1::from_vec(vec![1.0, 1.0, 1.0, -1.0]);
let mut model = QuantumSVMModel::new(4, 1.0);
model.fit(&x, &y)?;
let x_test = Array2::from_shape_vec((1, 2), vec![0.5, 0.5])?;
let preds = model.predict(&x_test)?;
assert_eq!(preds.len(), 1);Implementations§
Source§impl QuantumSVMModel
impl QuantumSVMModel
Sourcepub fn n_qubits(&self) -> usize
pub fn n_qubits(&self) -> usize
Return the number of qubits controlling the feature map dimension.
Sourcepub fn regularization(&self) -> f64
pub fn regularization(&self) -> f64
Return the regularisation parameter C.
Sourcepub fn num_support_vectors(&self) -> usize
pub fn num_support_vectors(&self) -> usize
Return the number of support vectors (0 before training).
Sourcepub fn fit(&mut self, x: &Array2<f64>, y: &Array1<f64>) -> SpatialResult<()>
pub fn fit(&mut self, x: &Array2<f64>, y: &Array1<f64>) -> SpatialResult<()>
Train the model on labelled data.
§Arguments
x- Training features matrix of shape(n_samples, n_features).y- Binary labels{+1, -1}of shape(n_samples,).
§Errors
Returns SpatialError::InvalidInput for empty inputs, shape mismatch,
invalid label values, or non-positive regularization.
Trait Implementations§
Source§impl Clone for QuantumSVMModel
impl Clone for QuantumSVMModel
Source§fn clone(&self) -> QuantumSVMModel
fn clone(&self) -> QuantumSVMModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumSVMModel
impl RefUnwindSafe for QuantumSVMModel
impl Send for QuantumSVMModel
impl Sync for QuantumSVMModel
impl Unpin for QuantumSVMModel
impl UnsafeUnpin for QuantumSVMModel
impl UnwindSafe for QuantumSVMModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.