pub struct KnnDecoder { /* private fields */ }Expand description
Simple KNN decoder using stored labeled embeddings.
Classifies a query embedding by majority vote among its k nearest
neighbors in Euclidean distance.
Implementations§
Source§impl KnnDecoder
impl KnnDecoder
Sourcepub fn train(&mut self, embeddings: Vec<(NeuralEmbedding, CognitiveState)>)
pub fn train(&mut self, embeddings: Vec<(NeuralEmbedding, CognitiveState)>)
Load labeled training data into the decoder.
Sourcepub fn predict(&self, embedding: &NeuralEmbedding) -> CognitiveState
pub fn predict(&self, embedding: &NeuralEmbedding) -> CognitiveState
Predict the cognitive state for a query embedding using majority vote.
Returns CognitiveState::Unknown if no training data is available.
Sourcepub fn predict_with_confidence(
&self,
embedding: &NeuralEmbedding,
) -> (CognitiveState, f64)
pub fn predict_with_confidence( &self, embedding: &NeuralEmbedding, ) -> (CognitiveState, f64)
Predict the cognitive state with a confidence score in [0, 1].
Confidence is the fraction of the k nearest neighbors that agree
on the winning state.
Sourcepub fn num_samples(&self) -> usize
pub fn num_samples(&self) -> usize
Number of stored labeled embeddings.
Trait Implementations§
Source§impl StateDecoder for KnnDecoder
impl StateDecoder for KnnDecoder
Source§fn decode(&self, embedding: &NeuralEmbedding) -> Result<CognitiveState>
fn decode(&self, embedding: &NeuralEmbedding) -> Result<CognitiveState>
Decode the most likely cognitive state from an embedding.
Source§fn decode_with_confidence(
&self,
embedding: &NeuralEmbedding,
) -> Result<(CognitiveState, f64)>
fn decode_with_confidence( &self, embedding: &NeuralEmbedding, ) -> Result<(CognitiveState, f64)>
Decode with a confidence score in [0, 1].
Auto Trait Implementations§
impl Freeze for KnnDecoder
impl RefUnwindSafe for KnnDecoder
impl Send for KnnDecoder
impl Sync for KnnDecoder
impl Unpin for KnnDecoder
impl UnsafeUnpin for KnnDecoder
impl UnwindSafe for KnnDecoder
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