Skip to contents

Samples from a normal distribution with mean \(\mu\) and standard deviation \(\sigma\) using the Box-Muller transform.

Usage

nv_rnorm(shape, initial_state, dtype = "f32", mu = 0, sigma = 1)

Arguments

shape

(integer())
Shape.

initial_state

(arrayish)
RNG state (ui64[2]).

dtype

(character(1) | tengen::DataType)
Data type.

mu

(arrayish)
Mean.

sigma

(arrayish)
Standard deviation. Must be positive, otherwise results are invalid.

Value

(list() of arrayish)
List of two elements: the updated RNG state and the sampled values.

Covariance

To implement a covariance structure use Cholesky decomposition.

Examples

state <- nv_rng_state(42L)
result <- nv_rnorm(c(2, 3), state)
result[[2]]
#> AnvlArray
#>  -0.0675  0.9489  1.9457
#>  -0.5255  1.2002  0.0008
#> [ CPUf32{2,3} ]