viewof mu = Inputs.range([-1, 1], {
step: 0.1,
value: 0,
label: tex`\mu`,
width: 200
})
viewof sigma = Inputs.range([0.1, 2], {
step: 0.1,
value: 1,
label: tex`\sigma`,
width: 200
})
// Generate points for the normal distribution curve
pointsGaussian = {
const x = d3.range(-5, 5, 0.1);
return x.map(x => ({
x,
y: (1 / (sigma * Math.sqrt(2 * Math.PI))) *
Math.exp(-0.5 * Math.pow((x - mu) / sigma, 2))
}));
}
Plot.plot({
style: "overflow: visible; display: block; margin: 0 auto;",
width: 600,
height: 400,
y: {
grid: true,
label: "Density"
},
x: {
label: "x",
domain: [-5, 5]
},
marks: [
Plot.line(pointsGaussian, {x: "x", y: "y", stroke: "steelblue"}),
Plot.ruleY([0])
]
})Gaussian Distribution
f_{X}(x)=\frac{1}{\sqrt{2\pi\sigma^{2} }}e^{-\frac{(x-\mu)^{2}}{2\sigma^{2}}}
- Used frequently to represent real-valued random variables whose distributions are not known.
- Its importance is derived from the central limit theorem that states, under some conditions, the average of many samples of a random variable is itself a random variable that converges to a Gaussian distribution as it increases.
- E[X] = \mu
- Var[X] = \sigma^{2}
Python Code: Gaussian Distribution
To create Gaussian distributed data using numpy:
import numpy as np
mu = 0
sigma = 1
size = (1000,1)
data = np.random.normal(mu, sigma, size)