pub struct PrototypicalNetwork<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Prototypical network for task representation
Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> PrototypicalNetwork<T>
impl<T: Float + Debug + Send + Sync + 'static> PrototypicalNetwork<T>
Sourcepub fn new(config: PrototypicalNetworkConfig<T>) -> Result<Self>
pub fn new(config: PrototypicalNetworkConfig<T>) -> Result<Self>
Create a new prototypical network from configuration
Sourcepub fn from_dims(embedding_dim: usize, _num_classes: usize) -> Result<Self>
pub fn from_dims(embedding_dim: usize, _num_classes: usize) -> Result<Self>
Create from embedding dimension and number of classes (convenience)
Sourcepub fn embedding_dim(&self) -> usize
pub fn embedding_dim(&self) -> usize
Get the embedding dimension
Sourcepub fn encoder_layers(&self) -> &[EncoderLayer<T>]
pub fn encoder_layers(&self) -> &[EncoderLayer<T>]
Get encoder layers (for projection)
Sourcepub fn prototypes_mut(&mut self) -> &mut HashMap<String, Prototype<T>>
pub fn prototypes_mut(&mut self) -> &mut HashMap<String, Prototype<T>>
Get mutable access to prototypes
Sourcepub fn prototypes(&self) -> &HashMap<String, Prototype<T>>
pub fn prototypes(&self) -> &HashMap<String, Prototype<T>>
Get read access to prototypes
Sourcepub fn distance_metric(&self) -> &DistanceMetric
pub fn distance_metric(&self) -> &DistanceMetric
Get the distance metric
Sourcepub fn encode_task(&self, task_data: &TaskData<T>) -> Result<Array1<T>>
pub fn encode_task(&self, task_data: &TaskData<T>) -> Result<Array1<T>>
Encode a task into an embedding vector
Sourcepub fn update_prototypes(
&mut self,
task_data: &TaskData<T>,
_result: &AdaptationResult<T>,
) -> Result<()>
pub fn update_prototypes( &mut self, task_data: &TaskData<T>, _result: &AdaptationResult<T>, ) -> Result<()>
Update prototypes with new experience
Source§impl<T: Float + Debug + Send + Sync + 'static> PrototypicalNetwork<T>
impl<T: Float + Debug + Send + Sync + 'static> PrototypicalNetwork<T>
Sourcepub fn encode(&self, features: &Array1<T>) -> Result<Array1<T>>
pub fn encode(&self, features: &Array1<T>) -> Result<Array1<T>>
Encode a single feature vector through the encoder network.
Performs a simple linear projection: out = features * W + b (truncating or zero-padding the input to match the weight matrix dimensions). A ReLU activation is applied element-wise.
Sourcepub fn compute_prototype(&self, examples: &[Array1<T>]) -> Result<Array1<T>>
pub fn compute_prototype(&self, examples: &[Array1<T>]) -> Result<Array1<T>>
Compute a prototype (class centroid) from a set of example embeddings.
The prototype is the element-wise mean of the encoded examples.
Sourcepub fn classify(
&self,
query: &Array1<T>,
prototypes: &[Array1<T>],
) -> Result<usize>
pub fn classify( &self, query: &Array1<T>, prototypes: &[Array1<T>], ) -> Result<usize>
Classify a query by finding the nearest prototype.
Returns the index of the closest prototype according to squared Euclidean distance.
Sourcepub fn find_nearest_prototype(&self, query: &Array1<T>) -> Result<(usize, T)>
pub fn find_nearest_prototype(&self, query: &Array1<T>) -> Result<(usize, T)>
Find the nearest prototype and return its index plus the distance.
Auto Trait Implementations§
impl<T> Freeze for PrototypicalNetwork<T>where
T: Freeze,
impl<T> RefUnwindSafe for PrototypicalNetwork<T>where
T: RefUnwindSafe,
impl<T> Send for PrototypicalNetwork<T>
impl<T> Sync for PrototypicalNetwork<T>
impl<T> Unpin for PrototypicalNetwork<T>where
T: Unpin,
impl<T> UnsafeUnpin for PrototypicalNetwork<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for PrototypicalNetwork<T>where
T: UnwindSafe + RefUnwindSafe,
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> 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.