pub struct ContinuousQNetwork<B: Backend> { /* private fields */ }Expand description
Continuous-action Q-critic on Burn: Q(s, a) -> scalar.
Implementations§
Source§impl<B: Backend> ContinuousQNetwork<B>
impl<B: Backend> ContinuousQNetwork<B>
Sourcepub fn new(
obs_dim: usize,
action_dim: usize,
hidden_dim: usize,
device: &B::Device,
) -> Self
pub fn new( obs_dim: usize, action_dim: usize, hidden_dim: usize, device: &B::Device, ) -> Self
Build a fresh critic with the default config (2-layer ReLU, orthogonal init) and the given hidden width.
Sourcepub fn with_config(
obs_dim: usize,
action_dim: usize,
config: ContinuousQNetworkConfig,
device: &B::Device,
) -> Self
pub fn with_config( obs_dim: usize, action_dim: usize, config: ContinuousQNetworkConfig, device: &B::Device, ) -> Self
Build a fresh critic with the given configuration.
The trunk input width is obs_dim + action_dim (the concatenated
(state, action) feature vector). When config.seed is Some,
every layer is drawn from a per-layer-derived StdRng stream so
the construction is bit-exact across runs and machines.
Sourcepub fn forward(&self, obs: Tensor<B, 2>, action: Tensor<B, 2>) -> Tensor<B, 1>
pub fn forward(&self, obs: Tensor<B, 2>, action: Tensor<B, 2>) -> Tensor<B, 1>
Forward pass: compute Q(s, a) for a batch of (state, action)
pairs.
obsshape[batch, obs_dim].actionshape[batch, action_dim].- Returns Q-values of shape
[batch](the trailing singleton head dimension is squeezed).
The observation and action are concatenated along the feature axis
before the trunk, so gradients flow into both inputs — SAC’s actor
loss differentiates Q(s, a) with respect to the action.
Sourcepub fn copy_params_from(
self,
source: &ContinuousQNetwork<B>,
) -> ContinuousQNetwork<B>
pub fn copy_params_from( self, source: &ContinuousQNetwork<B>, ) -> ContinuousQNetwork<B>
Replace this critic’s parameters with a deep copy of source’s
(hard target sync, theta_target <- theta_online).
Returns a new module with the same architecture but source’s
records. Burn’s optimizer ownership model (step consumes the
module by value) means we return Self rather than mutating
&mut self; the trainer holds each target critic as a field and
swaps it through this call when initializing the targets.
Sourcepub fn soft_update_from(&mut self, online: &ContinuousQNetwork<B>, tau: f64)
pub fn soft_update_from(&mut self, online: &ContinuousQNetwork<B>, tau: f64)
Polyak (soft) target update:
theta_target <- tau * theta_online + (1 - tau) * theta_target.
Applied to every parameter tensor (every trunk layer’s weight and
bias, plus the Q-head’s). tau = 1.0 reduces exactly to a hard
copy (copy_params_from); a tau in
(0, 1) nudges the target toward the online network — the
always-soft update SAC performs every gradient step.
Mutates self in place. self (the target) and online must
share the same architecture (depth, widths); the trainer
constructs the targets as clones of the online critics, so this
holds by construction.
Trait Implementations§
Source§impl<B> AutodiffModule<B> for ContinuousQNetwork<B>
impl<B> AutodiffModule<B> for ContinuousQNetwork<B>
Source§type InnerModule = ContinuousQNetwork<<B as AutodiffBackend>::InnerBackend>
type InnerModule = ContinuousQNetwork<<B as AutodiffBackend>::InnerBackend>
Source§fn valid(&self) -> Self::InnerModule
fn valid(&self) -> Self::InnerModule
Source§fn from_inner(module: Self::InnerModule) -> Self
fn from_inner(module: Self::InnerModule) -> Self
Source§impl<B: Backend> Clone for ContinuousQNetwork<B>
impl<B: Backend> Clone for ContinuousQNetwork<B>
Source§impl<B: Backend> Display for ContinuousQNetwork<B>
impl<B: Backend> Display for ContinuousQNetwork<B>
Source§impl<B> HasAutodiffModule<B> for ContinuousQNetwork<B::InnerBackend>
impl<B> HasAutodiffModule<B> for ContinuousQNetwork<B::InnerBackend>
Source§type TrainModule = ContinuousQNetwork<B>
type TrainModule = ContinuousQNetwork<B>
Source§impl<B: Backend> Module<B> for ContinuousQNetwork<B>
impl<B: Backend> Module<B> for ContinuousQNetwork<B>
Source§type Record = ContinuousQNetworkRecord<B>
type Record = ContinuousQNetworkRecord<B>
Source§fn load_record(self, record: Self::Record) -> Self
fn load_record(self, record: Self::Record) -> Self
Source§fn into_record(self) -> Self::Record
fn into_record(self) -> Self::Record
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
Source§fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
Source§fn to_device(self, device: &B::Device) -> Self
fn to_device(self, device: &B::Device) -> Self
Source§fn fork(self, device: &B::Device) -> Self
fn fork(self, device: &B::Device) -> Self
Source§fn devices(&self) -> Vec<<B as BackendTypes>::Device>
fn devices(&self) -> Vec<<B as BackendTypes>::Device>
Source§fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
Source§fn save_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
) -> Result<(), RecorderError>
fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
Source§fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &<B as BackendTypes>::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as BackendTypes>::Device, ) -> Result<Self, RecorderError>
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§impl<B: Backend> ModuleDisplay for ContinuousQNetwork<B>
impl<B: Backend> ModuleDisplay for ContinuousQNetwork<B>
Source§fn format(&self, passed_settings: DisplaySettings) -> String
fn format(&self, passed_settings: DisplaySettings) -> String
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Auto Trait Implementations§
impl<B> !Freeze for ContinuousQNetwork<B>
impl<B> !RefUnwindSafe for ContinuousQNetwork<B>
impl<B> !UnwindSafe for ContinuousQNetwork<B>
impl<B> Send for ContinuousQNetwork<B>
impl<B> Sync for ContinuousQNetwork<B>
impl<B> Unpin for ContinuousQNetwork<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
<B as BackendTypes>::Device: Unpin,
impl<B> UnsafeUnpin for ContinuousQNetwork<B>where
<B as BackendTypes>::Device: UnsafeUnpin,
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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