Skip to main content

Metric

Trait Metric 

pub trait Metric:
    Send
    + Sync
    + Clone {
    type Input;

    // Required methods
    fn name(&self) -> Arc<String> ⓘ;
    fn update(
        &mut self,
        item: &Self::Input,
        metadata: &MetricMetadata,
    ) -> Result<SerializedEntry, TensorReadError>;
    fn compute(&mut self) -> Result<SerializedEntry, TensorReadError>;
    fn clear(&mut self);

    // Provided methods
    fn description(&self) -> Option<String> { ... }
    fn attributes(&self) -> MetricAttributes { ... }
}
Expand description

Metric trait.

§Notes

Implementations should define their own input type only used by the metric. This is important since some conflict may happen when the model output is adapted for each metric’s input type.

Required Associated Types§

type Input

The input type of the metric.

Required Methods§

fn name(&self) -> Arc<String> ⓘ

The parameterized name of the metric.

This should be unique, so avoid using short generic names, prefer using the long name.

For a metric that can exist at different parameters (e.g., top-k accuracy for different values of k), the name should be unique for each instance.

fn update( &mut self, item: &Self::Input, metadata: &MetricMetadata, ) -> Result<SerializedEntry, TensorReadError>

Update the metric state and returns the current metric entry.

§Errors

Returns a TensorReadError when a tensor read fails. In that case, the metric state could hold part or none of this update.

fn compute(&mut self) -> Result<SerializedEntry, TensorReadError>

Compute the final metric value.

§Errors

Returns a TensorReadError when a tensor read fails.

fn clear(&mut self)

Clear the metric state.

Provided Methods§

fn description(&self) -> Option<String>

A short description of the metric.

fn attributes(&self) -> MetricAttributes

Attributes of the metric.

By default, metrics have no attributes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§