Skip to main content

DQNConfig

Struct DQNConfig 

Source
pub struct DQNConfig {
Show 17 fields pub learning_rate: f64, pub batch_size: usize, pub buffer_capacity: usize, pub min_buffer_size: usize, pub target_update_interval: usize, pub gamma: f64, pub epsilon_start: f64, pub epsilon_end: f64, pub epsilon_decay_steps: usize, pub max_grad_norm: f64, pub soft_update_tau: Option<f64>, pub prioritized_replay: bool, pub per_alpha: f64, pub per_beta_start: f64, pub per_beta_end: f64, pub per_beta_steps: usize, pub per_epsilon: f64,
}
Expand description

DQN configuration parameters.

Default values target classic CartPole-style discrete control: 50k-capacity replay, 64-sample batches, hard target sync every 500 env steps, linear ε-decay over 10k env steps. These are the same defaults the Stable-Baselines3 DQN baseline uses on CartPole.

Fields§

§learning_rate: f64

Adam learning rate for the online Q-network.

§batch_size: usize

Number of transitions sampled per gradient update.

§buffer_capacity: usize

Maximum number of transitions stored in the replay buffer. Older transitions are evicted FIFO once capacity is reached.

§min_buffer_size: usize

Minimum number of transitions required before training starts. Until the buffer holds this many transitions the trainer only collects experience (via random or ε-greedy actions) and skips gradient updates.

§target_update_interval: usize

Number of environment steps between hard target-net syncs (target ← online).

§gamma: f64

Discount factor used in the TD target. With Double-DQN (used unconditionally by crate::train::dqn::DQNTrainerBurn): y = r + γ · (1 - done) · Q_target(s', argmax_a' Q_online(s', a')).

§epsilon_start: f64

Initial value of the ε-greedy exploration parameter.

§epsilon_end: f64

Final value of ε after the linear decay completes.

§epsilon_decay_steps: usize

Number of environment steps over which ε linearly anneals from epsilon_start to epsilon_end. After this many steps ε stays at epsilon_end.

§max_grad_norm: f64

Maximum gradient norm for clipping the Q-network update.

§soft_update_tau: Option<f64>

Polyak (soft) target update coefficient τ ∈ (0, 1].

When Some(τ), every call to crate::train::dqn::DQNTrainerBurn::maybe_sync_target performs the blend

θ_target ← τ · θ_online + (1 − τ) · θ_target

across every parameter of the target network. This replaces the hard copy that fires every target_update_interval env steps; in soft-update mode target_update_interval is ignored.

When None (default), the trainer falls back to the original hard copy on the interval, preserving byte-for-byte backward compatibility with vanilla DQN.

A typical value is 0.005 (the SB3/Spinning Up default).

§prioritized_replay: bool

Use Prioritized Experience Replay (Schaul et al., 2015) in place of the uniform crate::buffer::replay::ReplayBuffer.

When true, the trainer holds a crate::buffer::replay::PrioritizedReplayBuffer and samples transitions proportionally to (|TD error| + ε)^α. Per-sample importance-sampling weights are applied to the Smooth-L1 loss (so high-priority transitions get correspondingly down-weighted updates), and the buffer’s priorities are refreshed after each gradient step with the new TD-error magnitudes.

Defaults to false to preserve the vanilla uniform behavior.

§per_alpha: f64

PER priority exponent α ∈ [0, 1]. 0 recovers uniform sampling (purely as a degenerate case — flip Self::prioritized_replay off for the same effect without the sum-tree overhead). 1 is fully proportional to priority. Typical value 0.6 (Schaul §3.2).

§per_beta_start: f64

PER importance-sampling exponent at the start of training. Typical value 0.4 (Schaul §3.4).

§per_beta_end: f64

PER importance-sampling exponent at the end of the annealing schedule. Always 1.0 in the original paper — full bias correction by the end of training.

§per_beta_steps: usize

Number of environment steps over which β linearly anneals from per_beta_start to per_beta_end. After this many steps β stays at per_beta_end. Defaults to epsilon_decay_steps if set to 0 (sentinel “follow the ε schedule”).

§per_epsilon: f64

Tiny constant added to |TD error| before raising to α, so transitions with vanishing TD error still have a small chance of being resampled. Typical value 1e-6.

Implementations§

Source§

impl DQNConfig

Source

pub fn new() -> Self

Create a new default configuration.

Source

pub fn validate(&self) -> Result<()>

Validate configuration parameters.

Returns an Err describing the first invalid field encountered.

Source

pub fn beta_at(&self, env_steps: usize) -> f64

Compute β at a given env-step count under the linear schedule:

β(t) = β_start + (β_end − β_start) · min(t / β_steps, 1)

If per_beta_steps == 0 the trainer falls back to epsilon_decay_steps so callers can leave the field at its default and have β anneal over the same window as ε.

Source

pub fn epsilon_at(&self, env_steps: usize) -> f64

Compute the ε used at a given env-step count under the linear schedule:

ε(t) = max(ε_end, ε_start - (ε_start - ε_end) · t / decay_steps)
Source

pub fn learning_rate(self, lr: f64) -> Self

Set learning rate.

Source

pub fn batch_size(self, size: usize) -> Self

Set minibatch size.

Source

pub fn buffer_capacity(self, capacity: usize) -> Self

Set replay buffer capacity.

Source

pub fn min_buffer_size(self, size: usize) -> Self

Set minimum buffer size before training starts.

Source

pub fn target_update_interval(self, steps: usize) -> Self

Set target update interval (env steps between hard target syncs).

Source

pub fn gamma(self, gamma: f64) -> Self

Set discount factor γ.

Source

pub fn epsilon_start(self, eps: f64) -> Self

Set initial ε for ε-greedy exploration.

Source

pub fn epsilon_end(self, eps: f64) -> Self

Set final ε for ε-greedy exploration.

Source

pub fn epsilon_decay_steps(self, steps: usize) -> Self

Set number of env steps over which ε anneals.

Source

pub fn max_grad_norm(self, norm: f64) -> Self

Set maximum gradient norm.

Source

pub fn soft_update_tau(self, tau: f64) -> Self

Enable Polyak (soft) target updates with coefficient τ.

When set, crate::train::dqn::DQNTrainerBurn::maybe_sync_target performs θ_target ← τ · θ_online + (1 − τ) · θ_target on every call (i.e. every env step in the standard rollout loop) instead of the hard copy gated by target_update_interval.

A typical value is 0.005.

Source

pub fn prioritized_replay(self, enabled: bool) -> Self

Enable or disable Prioritized Experience Replay.

Source

pub fn per_alpha(self, alpha: f64) -> Self

Set the PER priority exponent α.

Source

pub fn per_beta_start(self, beta: f64) -> Self

Set the PER importance-sampling exponent at the start of training.

Source

pub fn per_beta_end(self, beta: f64) -> Self

Set the PER importance-sampling exponent at the end of training.

Source

pub fn per_beta_steps(self, steps: usize) -> Self

Set the number of env steps over which β linearly anneals. Pass 0 to follow Self::epsilon_decay_steps.

Source

pub fn per_epsilon(self, eps: f64) -> Self

Set the PER priority floor ε.

Trait Implementations§

Source§

impl Clone for DQNConfig

Source§

fn clone(&self) -> DQNConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DQNConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DQNConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more