generate: function (n) {
var U = [], V = [], W, Y, randomVariables = [];
for (var k = 0; k < n / 2; k++ ) {
do {
U = [mctad.getRandomArbitrary(0, 1), mctad.getRandomArbitrary(0, 1)];
V = [2 * U[0] - 1, 2 * U[1] - 1];
W = Math.pow(V[0], 2) + Math.pow(V[1], 2);
} while (W > 1);
Y = Math.sqrt((-2 * Math.log(W) / W));
randomVariables.push(μ + Math.sqrt(σ2) * (V[0] * Y), μ + Math.sqrt(σ2) * (V[1] * Y));
}
if (randomVariables.length === n + 1) { randomVariables.pop(); }
return randomVariables;
},
pdf: function (x) {
return (1 / (Math.sqrt(σ2) * Math.sqrt(2 * mctad.π))) * Math.pow(Math.E, -(Math.pow(x - μ, 2) / (2 * σ2)));
},
cdf: function (x) {
var Z = (x - μ) / Math.sqrt(2 * σ2);
if (Z >= 0) {
return 0.5 * (1.0 + mctad.erf(Z));
} else {
return 0.5 * (1.0 - mctad.erf(-Z));
}
}
};
Normal Distribution
The Normal Distribution or Gaussian Distribution is a family of symmetric, continuous probability distributions.
Assumptions
μ
andσ2
are real numbers, the mean and variance.Use
mctad.normal(μ, σ2)
Inline Comments