pub struct DqnPolicy<E, Enc, Act, B: Backend> { /* private fields */ }Expand description
A DQN agent in inference-only mode.
Holds just the Q-network, encoder, and action mapper – no optimizer,
no replay buffer, no exploration. Requires only B: Backend (not
AutodiffBackend), so it can run on plain NdArray without any
autodiff overhead.
Load from a checkpoint saved by DqnAgent::save:
ⓘ
use burn::backend::NdArray;
let policy = DqnPolicy::<CartPoleEnv, _, _, NdArray>::new(
VecEncoder::new(4),
UsizeActionMapper::new(2),
&config,
device,
)
.load("cartpole_dqn")?;Implementations§
Source§impl<E, Enc, Act, B> DqnPolicy<E, Enc, Act, B>where
E: Environment,
Enc: ObservationEncoder<E::Observation, B>,
Act: DiscreteActionMapper<E::Action>,
B: Backend,
impl<E, Enc, Act, B> DqnPolicy<E, Enc, Act, B>where
E: Environment,
Enc: ObservationEncoder<E::Observation, B>,
Act: DiscreteActionMapper<E::Action>,
B: Backend,
Sourcepub fn new(
encoder: Enc,
action_mapper: Act,
config: &DqnConfig,
device: B::Device,
) -> Self
pub fn new( encoder: Enc, action_mapper: Act, config: &DqnConfig, device: B::Device, ) -> Self
Build an uninitialised policy with the given architecture.
The network weights are random until load is called.
Sourcepub fn from_network(
net: QNetwork<B>,
encoder: Enc,
action_mapper: Act,
device: B::Device,
) -> Self
pub fn from_network( net: QNetwork<B>, encoder: Enc, action_mapper: Act, device: B::Device, ) -> Self
Create a policy directly from a pre-built network.
Used by DqnAgent::into_policy() to convert a trained agent into
an inference-only policy without touching the disk.
Trait Implementations§
Source§impl<E, Enc, Act, B> Policy<<E as Environment>::Observation, <E as Environment>::Action> for DqnPolicy<E, Enc, Act, B>where
E: Environment,
Enc: ObservationEncoder<E::Observation, B>,
Act: DiscreteActionMapper<E::Action>,
B: Backend,
impl<E, Enc, Act, B> Policy<<E as Environment>::Observation, <E as Environment>::Action> for DqnPolicy<E, Enc, Act, B>where
E: Environment,
Enc: ObservationEncoder<E::Observation, B>,
Act: DiscreteActionMapper<E::Action>,
B: Backend,
Source§fn act(&self, obs: &E::Observation) -> E::Action
fn act(&self, obs: &E::Observation) -> E::Action
Select an action given the current observation.
Auto Trait Implementations§
impl<E, Enc, Act, B> Freeze for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> !RefUnwindSafe for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> Send for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> !Sync for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> Unpin for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> UnsafeUnpin for DqnPolicy<E, Enc, Act, B>
impl<E, Enc, Act, B> !UnwindSafe for DqnPolicy<E, Enc, Act, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more