Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function weightFunc (d, dmax, degree) {
export function normalize (referenceArr) {
const cutoff = Math.ceil(0.1 * referenceArr.length)
const trimmed_arr = sort(referenceArr).slice(cutoff, referenceArr.length - cutoff)
const sd = math.std(trimmed_arr)
const sd = trimmed_arr.length > 3 ? math.std(trimmed_arr) : 1
return function (outputArr) {
return outputArr.map(val => val / sd)
}
Expand Down
10 changes: 10 additions & 0 deletions test/helpers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,20 @@ describe('function normalize', function () {
expect: [44.499, 3.266, 2.858, 2.449, 2.041, 1.633, 1.225, 0.816, 0.408, -40.825]
}

const caseTwo = {
test: [109, 8, 7],
expect: [109, 8, 7]
}

it('should return array divided by 10% trimmed sample deviation', function () {
const normalizedArr = normalize(caseOne.test)(caseOne.test)
expect(math.round(normalizedArr, 3)).to.eql(caseOne.expect)
})

it('should return same array if sample count is too small (lt 4)', function () {
const normalizedArr = normalize(caseTwo.test)(caseTwo.test)
expect(normalizedArr).to.eql(caseTwo.expect)
})
})

describe('function euclideanDist', function () {
Expand Down