Trait Actor

Source
pub trait Actor<O: ?Sized, A> {
    type EpisodeState;

    // Required methods
    fn initial_state(&self, rng: &mut Prng) -> Self::EpisodeState;
    fn act(
        &self,
        episode_state: &mut Self::EpisodeState,
        observation: &O,
        rng: &mut Prng,
    ) -> A;
}
Expand description

Take actions in an environment.

The actions may depend on the action-observation history within an episode but not across episodes. This is managed with an explicit EpisodeState associated type.

§Design Discussion

§Episode State

If Generic Associated Types were stable, an alternate strategy would be to have a self-contaned EpisodeActor<'a> associated type with an act(&mut self, observation: &O) method. However, this would make it challenging to store both an Actor and its EpisodeActor together (if wanting a single object to act over multiple sequential episodes). As such, the current EpisodeState strategy might still be preferable.

Another strategy (allowed without GAT) is for the Actor to internally manage episode state and provide a reset() method for resetting between episodes. This lacks the benefit of being able to guarantee independence between episodes via the type system.

§Random State

The actor is not responsible for managing its own pseudo-random state. This avoids having to frequently re-initialize the random number generator on each episode and simplifies episode state definitions.

Required Associated Types§

Source

type EpisodeState

Stores state for each episode.

Required Methods§

Source

fn initial_state(&self, rng: &mut Prng) -> Self::EpisodeState

Create the initial actor state for the start of a new episode.

Source

fn act( &self, episode_state: &mut Self::EpisodeState, observation: &O, rng: &mut Prng, ) -> A

Select an action in response to an observation.

May depend on and update the episode state. The observation, the selected action, and any other internal state may be stored into episode_state.

Implementations on Foreign Types§

Source§

impl<T, O, A> Actor<O, A> for &T
where T: Actor<O, A> + ?Sized, O: ?Sized,

Source§

type EpisodeState = <T as Actor<O, A>>::EpisodeState

Source§

fn initial_state(&self, rng: &mut Prng) -> Self::EpisodeState

Source§

fn act( &self, episode_state: &mut Self::EpisodeState, observation: &O, rng: &mut Prng, ) -> A

Source§

impl<T, O, A> Actor<O, A> for Box<T>
where T: Actor<O, A> + ?Sized, O: ?Sized,

Source§

type EpisodeState = <T as Actor<O, A>>::EpisodeState

Source§

fn initial_state(&self, rng: &mut Prng) -> Self::EpisodeState

Source§

fn act( &self, episode_state: &mut Self::EpisodeState, observation: &O, rng: &mut Prng, ) -> A

Source§

impl<T, O, A> Actor<O, A> for Arc<T>
where T: Actor<O, A> + ?Sized, O: ?Sized,

Source§

type EpisodeState = <T as Actor<O, A>>::EpisodeState

Source§

fn initial_state(&self, rng: &mut Prng) -> Self::EpisodeState

Source§

fn act( &self, episode_state: &mut Self::EpisodeState, observation: &O, rng: &mut Prng, ) -> A

Implementors§

Source§

impl<O, AS: SampleSpace + Clone> Actor<O, <AS as Space>::Element> for RandomAgent<AS>

Source§

impl<OS, AS, P> Actor<<OS as Space>::Element, <AS as Space>::Element> for PolicyActor<OS, AS, P>

Source§

impl<OS, AS, V> Actor<<OS as Space>::Element, <AS as Space>::Element> for DqnActor<OS, AS, V>

Source§

impl<T0, T1, O0, O1, A0, A1> Actor<(O0, O1), (A0, A1)> for AgentPair<T0, T1>
where T0: Actor<O0, A0>, T1: Actor<O1, A1>,

Source§

type EpisodeState = (<T0 as Actor<O0, A0>>::EpisodeState, <T1 as Actor<O1, A1>>::EpisodeState)

Source§

impl<T, O, A> Actor<O, A> for SerialActorAgent<T, O, A>
where T: Agent<O, A> + BatchUpdate<O, A>,

Source§

type EpisodeState = <<T as Agent<O, A>>::Actor as Actor<O, A>>::EpisodeState

Source§

impl<T, OS, AS> Actor<<OS as Space>::Element, <AS as Space>::Element> for FiniteSpaceActor<T, OS, AS>
where T: Actor<usize, usize>, OS: FiniteSpace, AS: FiniteSpace,

Source§

impl<TC, OS, AS, FS> Actor<MetaObservation<<OS as Space>::Element, <AS as Space>::Element, <FS as Space>::Element>, <AS as Space>::Element> for ResettingMetaAgent<TC, OS, AS, FS>
where TC: BuildAgent<OS, AS, FS>, TC::Agent: BatchUpdate<OS::Element, AS::Element, Feedback = FS::Element>, OS: Space + Clone, AS: NonEmptySpace + Clone, FS: Space + Clone,

Source§

type EpisodeState = InnerEpisodeState<<TC as BuildAgent<OS, AS, FS>>::Agent, <OS as Space>::Element, <AS as Space>::Element>