79207062

Date: 2024-11-20 11:50:29
Score: 1
Natty:
Report link

Given $u \sim U[0,1]$, (u is a uniform random variable in [0,1]), then for any distribution $\mathbb{P}$ with cumulative distribution function (CDF) $F$, holds $F^{-1}(u) \sim \mathbb{P}$.

I.E., in general you can obtain samples from any distribution, just as the image of a uniform random variable through the inverse CDF of the desired distribution.

In this case, to sample from a normal distribution, your $F^{-1}$ is the inverse normal cdf of a normal, which is not implemented in native js nor in the Math package, but you can find efficients numerical approximations such as Peter J. Acklam's method which are easy to implement in js.

Of course if you need your variable to have a mean $\mu$ and standard deviation $\sigma$, you can always consider $x = \sigma invNormalCDF(u) + \mu \sim \mathcal{N}(\mu, \sigma^2)$.

This is a very powerful trick to generate samples for a distribution, even if you don't know the distribution of data, you can estimate the CDF from a sample.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: user123n't