pub struct QuantumClassifier { /* private fields */ }Expand description
Quantum-Classical Hybrid Classifier
A high-level classifier that wraps QuantumSVMModel with optional
per-feature standardisation preprocessing. The preprocessing computes
z-score normalisation (zero mean, unit variance) from training data and
applies it consistently at test time.
§Example
use scirs2_core::ndarray::{Array1, Array2};
use scirs2_spatial::quantum_inspired::algorithms::quantum_machine_learning::QuantumClassifier;
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 clf = QuantumClassifier::new(4, 1.0, true);
clf.fit(&x, &y)?;
let x_test = Array2::from_shape_vec((1, 2), vec![0.5, 0.5])?;
let preds = clf.predict(&x_test)?;
assert_eq!(preds.len(), 1);Implementations§
Source§impl QuantumClassifier
impl QuantumClassifier
Sourcepub fn new(n_qubits: usize, regularization: f64, standardise: bool) -> Self
pub fn new(n_qubits: usize, regularization: f64, standardise: bool) -> Self
Construct a new QuantumClassifier.
§Arguments
n_qubits- Passed through toQuantumSVMModel.regularization- SVM regularisation constant C.standardise- Iftrue, z-score normalise features before fitting.
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 classifier.
If standardise was set to true, this computes feature statistics
from x and stores them for consistent use at predict time.
§Errors
Propagates errors from QuantumSVMModel::fit.
Sourcepub fn predict(&self, x: &Array2<f64>) -> SpatialResult<Array1<f64>>
pub fn predict(&self, x: &Array2<f64>) -> SpatialResult<Array1<f64>>
Predict labels for new samples.
Applies the same normalisation (if any) that was used during training.
§Errors
Propagates errors from QuantumSVMModel::predict.
Sourcepub fn num_support_vectors(&self) -> usize
pub fn num_support_vectors(&self) -> usize
Return the number of support vectors in the underlying SVM.
Trait Implementations§
Source§impl Clone for QuantumClassifier
impl Clone for QuantumClassifier
Source§fn clone(&self) -> QuantumClassifier
fn clone(&self) -> QuantumClassifier
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumClassifier
impl RefUnwindSafe for QuantumClassifier
impl Send for QuantumClassifier
impl Sync for QuantumClassifier
impl Unpin for QuantumClassifier
impl UnsafeUnpin for QuantumClassifier
impl UnwindSafe for QuantumClassifier
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.