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§
Sourcefn evaluate<R>(
&mut self,
agent: &mut Box<dyn Agent<E, R>>,
) -> Result<(f32, Record)>where
R: ReplayBufferBase,
fn evaluate<R>(
&mut self,
agent: &mut Box<dyn Agent<E, R>>,
) -> Result<(f32, Record)>where
R: ReplayBufferBase,
Evaluates an agent’s performance in the environment.
This method should:
- Set the agent to evaluation mode
- Run the agent in the environment for the specified number of episodes
- Collect and aggregate performance metrics
- 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.