ag_sample_normal: Sample from a diagonal Gaussian

View source: R/ag_select.R

ag_sample_normalR Documentation

Sample from a diagonal Gaussian

Description

mu + exp(log_std) * eps with eps ~ N(0, 1) from stats::rnorm (so set.seed reproduces it). Differentiable in mu and log_std – the reparameterisation used by SAC; for PPO collection the result is just the action.

Usage

ag_sample_normal(mu, log_std)

Arguments

mu

ag_tensor or numeric matrix, [n, batch].

log_std

ag_tensor or numeric matrix, [n, batch] or [n, 1].

Details

log_std is either the shape of mu (state-dependent) or one column [n, 1] broadcast over the batch (state-independent). On the GPU mu and log_std stay on the device; only eps is uploaded.

Value

ag_tensor [n, batch].

Examples

set.seed(1)
a <- ag_sample_normal(matrix(0, 2, 3), matrix(log(0.5), 2, 1))

ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.