pub struct QuantumNearestNeighbor { /* private fields */ }Expand description
Quantum-Enhanced Nearest Neighbor Search
This structure implements a quantum-inspired nearest neighbor search algorithm that uses quantum state representations and amplitude amplification to enhance search performance. The algorithm can operate in pure quantum mode or fall back to classical computation for compatibility.
§Features
- Quantum state encoding of reference points
- Amplitude amplification using Grover-like algorithms
- Quantum fidelity-based distance computation
- Classical fallback for robustness
§Example
use scirs2_core::ndarray::Array2;
use scirs2_spatial::quantum_inspired::algorithms::QuantumNearestNeighbor;
let points = Array2::from_shape_vec((3, 2), vec![0.0, 0.0, 1.0, 1.0, 2.0, 2.0]).unwrap();
let mut searcher = QuantumNearestNeighbor::new(&points.view())
.unwrap()
.with_quantum_encoding(true)
.with_amplitude_amplification(true);
let query = scirs2_core::ndarray::arr1(&[0.5, 0.5]);
let (indices, distances) = searcher.query_quantum(&query.view(), 2).unwrap();Implementations§
Source§impl QuantumNearestNeighbor
impl QuantumNearestNeighbor
Sourcepub fn new(points: &ArrayView2<'_, f64>) -> SpatialResult<Self>
pub fn new(points: &ArrayView2<'_, f64>) -> SpatialResult<Self>
Sourcepub fn with_quantum_encoding(self, enabled: bool) -> Self
pub fn with_quantum_encoding(self, enabled: bool) -> Self
Enable quantum encoding of reference points
When enabled, reference points are encoded as quantum states which can provide enhanced search performance through quantum parallelism.
§Arguments
enabled- Whether to enable quantum encoding
Sourcepub fn with_amplitude_amplification(self, enabled: bool) -> Self
pub fn with_amplitude_amplification(self, enabled: bool) -> Self
Enable amplitude amplification (Grover-like algorithm)
Amplitude amplification can enhance search performance by amplifying the probability amplitudes of good solutions.
§Arguments
enabled- Whether to enable amplitude amplification
Sourcepub fn with_grover_iterations(self, iterations: usize) -> Self
pub fn with_grover_iterations(self, iterations: usize) -> Self
Configure Grover iterations
Sets the number of Grover iterations used in amplitude amplification. More iterations can improve search quality but increase computation time.
§Arguments
iterations- Number of Grover iterations (typically 3-5 for best results)
Sourcepub fn query_quantum(
&self,
query_point: &ArrayView1<'_, f64>,
k: usize,
) -> SpatialResult<(Vec<usize>, Vec<f64>)>
pub fn query_quantum( &self, query_point: &ArrayView1<'_, f64>, k: usize, ) -> SpatialResult<(Vec<usize>, Vec<f64>)>
Perform quantum-enhanced nearest neighbor search
Finds the k nearest neighbors to a query point using quantum-enhanced distance computation when quantum encoding is enabled, otherwise falls back to classical Euclidean distance.
§Arguments
query_point- Point to search for neighborsk- Number of nearest neighbors to find
§Returns
Tuple of (indices, distances) for the k nearest neighbors
Sourcepub fn classical_points(&self) -> &Array2<f64>
pub fn classical_points(&self) -> &Array2<f64>
Get reference to classical points
Sourcepub fn is_quantum_enabled(&self) -> bool
pub fn is_quantum_enabled(&self) -> bool
Check if quantum encoding is enabled
Sourcepub fn is_amplification_enabled(&self) -> bool
pub fn is_amplification_enabled(&self) -> bool
Check if amplitude amplification is enabled
Trait Implementations§
Source§impl Clone for QuantumNearestNeighbor
impl Clone for QuantumNearestNeighbor
Source§fn clone(&self) -> QuantumNearestNeighbor
fn clone(&self) -> QuantumNearestNeighbor
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 QuantumNearestNeighbor
impl RefUnwindSafe for QuantumNearestNeighbor
impl Send for QuantumNearestNeighbor
impl Sync for QuantumNearestNeighbor
impl Unpin for QuantumNearestNeighbor
impl UnwindSafe for QuantumNearestNeighbor
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.