I'm tring to understand the below logic.
function bumps(m) {
var values = [], i, j, w, x, y, z;
for (var i = 0; i < m; ++i) {
values[i] = 0.1 + 0.1 * Math.random();
}
for (var j = 0; j < 5; j++) {
x = 1 / (0.1 + Math.random());
y = 2 * Math.random() - 0.5;
z = 10 / (0.1 + Math.random());
for (var i = 0; i < m; i++) {
w = (i / m - y) * z;
values[i] += x * Math.exp(-w * w);
}
}
for (var i = 0; i < m; i++) {
values[i] = Math.max(0, values[i]);
}
return values;
}
The above code is snippet from http://bl.ocks.org/mbostock/3943967 and the above function is used to display the random series stack on the y axis in the graph displayed url. I'm trying to understand what they are trying to do in the below
x = 1 / (0.1 + Math.random());
y = 2 * Math.random() - 0.5;
z = 10 / (0.1 + Math.random());
How to interpret or understand mathematically / logically the above operations in bumps method ? Please help me in understanding the same.
As the given reference indicates:
This is generating $m=4$ histogram series with five gaussian lobes each: $$ v_j=\sum_{i=1}^{m} z_j \exp^{-\left(\frac{iz_j}{m-y_j}\right)^2} $$
This function do not have any special significance. This is not a distribution, because this do not integrate 1. It is just a pictorical sample for displaying purposes.
They could truly be interpreted as histogram data, if truncated to the nearest integer, or as is, considering an histogram built in discrete ranges from a continuous variable.
The values of $x,y,z$ neither do possess a special significance; they are only random numbers generated from the
Math.random()function, which outputs a uniform random number in the $[0,1]$ range, and operated in order to give different values, in the $[0.909,10]$, $[-0.5,1.5]$ and $[90.90,100]$ ranges, respectively.As pictorical relevance, they are related to the height, spread, and center of each lobe.
Please note the similarities with the gaussian distribution, which do integrate 1 as per any proper probability density function: $$ v=\frac{1}{\sqrt{2\pi}\sigma}\exp^{-(\frac{x-\mu}{2\sigma})^2} $$