Trait Evaluator

Source
pub trait Evaluator<E: Env> {
    // Required method
    fn evaluate<R>(
        &mut self,
        agent: &mut Box<dyn Agent<E, R>>,
    ) -> Result<(f32, Record)>
       where R: ReplayBufferBase;
}
Expand description

Interface for evaluating reinforcement learning agents.

This trait defines the standard interface for evaluating agents in different environments. Implementations of this trait should:

  • Run the agent in the environment for a specified number of episodes
  • Collect performance metrics (e.g., average return, success rate)
  • Return the results in a standardized format

§Type Parameters

  • E - The environment type that the agent operates in

§Examples

struct CustomEvaluator<E: Env> {
    env: E,
    n_episodes: usize,
}

impl<E: Env> Evaluator<E> for CustomEvaluator<E> {
    fn evaluate<R>(&mut self, agent: &mut Box<dyn Agent<E, R>>) -> Result<Record>
    where
        R: ReplayBufferBase,
    {
        // Custom evaluation logic
        // ...
    }
}

Required Methods§

Source

fn evaluate<R>( &mut self, agent: &mut Box<dyn Agent<E, R>>, ) -> Result<(f32, Record)>

Evaluates an agent’s performance in the environment.

This method should:

  1. Set the agent to evaluation mode
  2. Run the agent in the environment for the specified number of episodes
  3. Collect and aggregate performance metrics
  4. Return the results in a Record
§Arguments
  • agent - The agent to evaluate
§Returns

A tuple of (performance metric, Record containing the evaluation results)

In Trainer, the performance metric is used to choose the best model.

§Errors

Returns an error if:

  • The environment fails to reset or step
  • The agent fails to produce actions
  • The evaluation process encounters an unexpected error
§Note

The caller is responsible for managing the agent’s internal state, such as switching between training and evaluation modes. This allows for flexible evaluation strategies that may require different agent configurations.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§