ml-array-variance
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -15,21 +15,18 @@ 'use strict'; | ||
*/ | ||
var index = function (values, options = {}) { | ||
const { | ||
unbiased = true, | ||
mean = arrayMean(values) | ||
} = options; | ||
var sqrError = 0; | ||
function variance(values, options = {}) { | ||
const { unbiased = true, mean = arrayMean(values) } = options; | ||
var sqrError = 0; | ||
for (var i = 0; i < values.length; i++) { | ||
var x = values[i] - mean; | ||
sqrError += x * x; | ||
} | ||
for (var i = 0; i < values.length; i++) { | ||
var x = values[i] - mean; | ||
sqrError += x * x; | ||
} | ||
if (unbiased) { | ||
return sqrError / (values.length - 1); | ||
} else { | ||
return sqrError / values.length; | ||
} | ||
}; | ||
if (unbiased) { | ||
return sqrError / (values.length - 1); | ||
} else { | ||
return sqrError / values.length; | ||
} | ||
} | ||
module.exports = index; | ||
module.exports = variance; |
{ | ||
"name": "ml-array-variance", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Get the variance in an array", | ||
@@ -23,4 +23,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"ml-array-mean": "^1.0.1" | ||
"ml-array-mean": "^1.0.2" | ||
} | ||
} |
@@ -5,6 +5,6 @@ import variance from '..'; | ||
test('variance', () => { | ||
var v = variance(data); | ||
expect(v).toBeCloseTo(18.667, 3); | ||
expect(variance(data, {unbiased: true})).toBe(v); | ||
expect(variance(data, {unbiased: false})).toBe(14); | ||
var v = variance(data); | ||
expect(v).toBeCloseTo(18.667, 3); | ||
expect(variance(data, { unbiased: true })).toBe(v); | ||
expect(variance(data, { unbiased: false })).toBe(14); | ||
}); |
@@ -11,19 +11,16 @@ import arrayMean from 'ml-array-mean'; | ||
*/ | ||
export default function (values, options = {}) { | ||
const { | ||
unbiased = true, | ||
mean = arrayMean(values) | ||
} = options; | ||
var sqrError = 0; | ||
export default function variance(values, options = {}) { | ||
const { unbiased = true, mean = arrayMean(values) } = options; | ||
var sqrError = 0; | ||
for (var i = 0; i < values.length; i++) { | ||
var x = values[i] - mean; | ||
sqrError += x * x; | ||
} | ||
for (var i = 0; i < values.length; i++) { | ||
var x = values[i] - mean; | ||
sqrError += x * x; | ||
} | ||
if (unbiased) { | ||
return sqrError / (values.length - 1); | ||
} else { | ||
return sqrError / values.length; | ||
} | ||
if (unbiased) { | ||
return sqrError / (values.length - 1); | ||
} else { | ||
return sqrError / values.length; | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4459
7
55
1
Updatedml-array-mean@^1.0.2