Skip to main content

Policy

Trait Policy 

pub trait Policy: Clone {
    type Observation;
    type ActionDistribution;
    type Action;
    type ActionContext;
    type PolicyState: PolicyState;

    // Required methods
    fn forward(&mut self, obs: Self::Observation) -> Self::ActionDistribution;
    fn action(
        &mut self,
        obs: Self::Observation,
        deterministic: bool,
    ) -> (Self::Action, Vec<Self::ActionContext>);
    fn update(&mut self, update: Self::PolicyState);
    fn state(&self) -> Self::PolicyState;
    fn to_device(self, device: &Device) -> Self;
    fn load_record(
        self,
        record: <Self::PolicyState as PolicyState>::Record,
    ) -> Self;
}
Expand description

Trait for a RL policy.

Required Associated Types§

type Observation

The observation given as input to the policy.

type ActionDistribution

The action distribution parameters defining how the action will be sampled.

type Action

The action.

type ActionContext

Additional context on the policy’s decision.

type PolicyState: PolicyState

The current parameterization of the policy.

Required Methods§

fn forward(&mut self, obs: Self::Observation) -> Self::ActionDistribution

Produces the action distribution from a batch of observations.

fn action( &mut self, obs: Self::Observation, deterministic: bool, ) -> (Self::Action, Vec<Self::ActionContext>)

Gives the action from a batch of observations.

fn update(&mut self, update: Self::PolicyState)

Update the policy’s parameters.

fn state(&self) -> Self::PolicyState

Returns the current parameterization.

fn to_device(self, device: &Device) -> Self

Loads the policy on the given device.

fn load_record(self, record: <Self::PolicyState as PolicyState>::Record) -> Self

Loads the policy parameters from a record.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§