* Calculate the standard deviation of a vector. * * @param {Array} vector The vector represented as an Array of Numbers. * * @returns {number} The standard deviation.
(vector)
| 102 | * @returns {number} The standard deviation. |
| 103 | */ |
| 104 | function stddev(vector) { |
| 105 | let squareSum = 0; |
| 106 | const vectorMean = mean(vector); |
| 107 | for (const x of vector) { |
| 108 | squareSum += (x - vectorMean) * (x - vectorMean); |
| 109 | } |
| 110 | return Math.sqrt(squareSum / (vector.length - 1)); |
| 111 | }; |
| 112 | |
| 113 | /** |
| 114 | * Normalize a vector by its mean and standard deviation. |
no test coverage detected