Skip to main content

normal_

Function normal_ 

Source
pub fn normal_(
    shape: &[usize],
    mean: f32,
    std: f32,
    generator: Option<u64>,
) -> Result<Tensor>
Expand description

Generate tensor with values drawn from normal distribution

§Mathematical Background

The normal (Gaussian) distribution N(μ, σ²) has probability density function:

f(x) = (1/(σ√(2π))) × exp(-½((x-μ)/σ)²)
```text

Properties:
- **Mean**: μ
- **Variance**: σ²
- **Standard deviation**: σ
- **Support**: (-∞, ∞)
- **68-95-99.7 rule**: ~68% within μ±σ, ~95% within μ±2σ, ~99.7% within μ±3σ

## Box-Muller Transformation

Converts uniform random variables to normal:
```text
U₁, U₂ ~ Uniform(0,1)
Z₀ = √(-2 ln U₁) × cos(2π U₂)
Z₁ = √(-2 ln U₁) × sin(2π U₂)
Z₀, Z₁ ~ N(0,1)
X = μ + σZ  ~ N(μ, σ²)
```text

## Parameters
* `shape` - Shape of the tensor
* `mean` - Mean of the normal distribution
* `std` - Standard deviation of the normal distribution
* `generator` - Optional random number generator seed

## Returns
* Tensor filled with normally distributed values N(mean, std²)