-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Node.js 4 and 6 are no longer supported.
- Loading branch information
Showing
15 changed files
with
93 additions
and
1,287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["@babel/plugin-transform-modules-commonjs"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
extends: 'eslint-config-cheminfo' | ||
extends: cheminfo | ||
parserOptions: | ||
sourceType: module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ logs | |
*.log | ||
npm-debug.log* | ||
coverage | ||
distance-matrix.js | ||
distance-matrix.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- node | ||
- lts/boron # v6 | ||
- lts/argon # v4 | ||
script: "npm run test-travis " | ||
after_script: "bash <(curl -s https://codecov.io/bash)" | ||
- 8 | ||
- 10 | ||
- 12 | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
file: 'distance-matrix.js', | ||
format: 'cjs', | ||
}, | ||
external: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__tests__ | ||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import distanceMatrix from '..'; | ||
|
||
describe('distance-matrix test', () => { | ||
it('identity distance (0 if the same, 1 if not', () => { | ||
// [1, 0, 1, 1] | ||
// => | ||
// [0, 1, 0, 0] | ||
// [1, 0, 1, 1] | ||
// [0, 1, 0, 0] | ||
// [0, 1, 0, 0] | ||
const result = distanceMatrix([1, 0, 1, 1], (a, b) => Number(a !== b)); | ||
expect(result).toStrictEqual([ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 1], | ||
[0, 1, 0, 0], | ||
[0, 1, 0, 0], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
'use strict'; | ||
|
||
|
||
/** | ||
* Computes a distance/similarity matrix given an array of data and a distance/similarity function. | ||
* @param {Array} data An array of data | ||
* @param {function} distanceFn A function that accepts two arguments and computes a distance/similarity between them | ||
* @return {Array<Array>} The distance/similarity matrix. The matrix is square and has a size equal to the length of | ||
* the data array | ||
*/ | ||
function distanceMatrix(data, distanceFn) { | ||
const length = data.length; | ||
let result = Array.from({length}).map(() => Array.from({length})); | ||
|
||
// Compute upper distance matrix | ||
for (let i = 0; i < length; i++) { | ||
for (let j = 0; j <= i; j++) { | ||
result[i][j] = distanceFn(data[i], data[j]); | ||
} | ||
} | ||
export default function distanceMatrix(data, distanceFn) { | ||
const result = getMatrix(data.length); | ||
|
||
// Copy to lower distance matrix | ||
for (let i = 0; i < length; i++) { | ||
for (let j = i + 1; j < length; j++) { | ||
result[i][j] = result[j][i]; | ||
} | ||
// Compute upper distance matrix | ||
for (let i = 0; i < data.length; i++) { | ||
for (let j = 0; j <= i; j++) { | ||
result[i][j] = distanceFn(data[i], data[j]); | ||
result[j][i] = result[i][j]; | ||
} | ||
} | ||
|
||
return result; | ||
return result; | ||
} | ||
|
||
module.exports = distanceMatrix; | ||
function getMatrix(size) { | ||
const matrix = []; | ||
for (let i = 0; i < size; i++) { | ||
const row = []; | ||
matrix.push(row); | ||
for (let j = 0; j < size; j++) { | ||
row.push(0); | ||
} | ||
} | ||
return matrix; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.