TorchLean API

NN.Runtime.RL.Algorithms.DQN

DQN Minibatch Helpers #

NN.Runtime.RL.Algorithms.ValueLearning contains the scalar DQN/Double-DQN targets. This module adds the missing batch-facing layer used by replay-buffer training loops:

The functions are intentionally higher-order: TorchLean examples can pass typed-graph/eager model closures without this module knowing anything about parameters, optimizers, or autograd sessions.

References:

def Runtime.RL.DQN.loss {α : Type} [TorchLean.Storage α] [Context α] {obsShape : Spec.Shape} {nActions : ℕ} {Input : Type} (onlineQ targetQ : TorchLean.Tensor α obsShape → TorchLean.Tensor α [nActions]) (gamma : α) (input : Input) (batch double : Bool := false) (error : α → α → α := Core.squaredError) [TorchLean.Internal.BatchInput (Core.Transition α obsShape nActions) (Array (Core.Transition α obsShape nActions)) batch Input] :
α

DQN loss for one transition, or the mean loss of a replay batch (batch := true).

double := true selects actions with the online network and evaluates them with the target network. error defaults to squared error; pass a scalar loss such as Core.huberLoss to change it. Batch reduction uses Tensor.mean, including its empty-batch convention.

Instances For
    def Runtime.RL.DQN.updateTarget {α : Type u_1} [One α] [Add α] [Sub α] [Mul α] (tau online target : α) :
    α

    Weighted target-network update:

    target ← τ * online + (1 - τ) * target.

    Use this elementwise over parameter tensors for DQN/DDPG/TD3/SAC target synchronization. The mixing weight is used as supplied, without validation. The arithmetic order is retained for floating-point callers; algebraically equivalent rearrangements can round differently.

    Instances For