-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb178ef
commit fb0c7f9
Showing
9 changed files
with
160 additions
and
6,219 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,53 @@ | ||
import { distance as distances } from './distance'; | ||
|
||
export function mult_dist() { | ||
let distance = distances.euclidean; | ||
|
||
function mult_dist(matrices) { | ||
const n = matrices.length; | ||
|
||
const res = []; | ||
for (let i = 0; i < matrices[0].length; i++) { | ||
const newrow = []; | ||
for (let j = 0; j < matrices[0][0].length; j++) { | ||
newrow.push(0); | ||
} | ||
res.push(newrow); | ||
} | ||
for (let k = 0; k < n; k++){ | ||
let distMatrix = []; | ||
const vector = matrices[k]; | ||
const n1 = vector.length; | ||
for (let i = 0; i < n1; i++) { | ||
const d = []; | ||
distMatrix[i] = d; | ||
for (let j = 0; j < n1; j++) { | ||
if (j < i) { | ||
d[j] = (distMatrix[j][i]); | ||
} else if (i === j) { | ||
d[j] = 0; | ||
} else { | ||
d[j] = distance(vector[i], vector[j]); | ||
} | ||
} | ||
} | ||
for (let i = 0; i < distMatrix.length; i++) { | ||
for (let j = 0; j <distMatrix[0].length; j++) { | ||
res[i][j] += distMatrix[i][j]; | ||
} | ||
|
||
} | ||
} | ||
return res; | ||
} | ||
|
||
mult_dist.distance = function (x) { | ||
if (!arguments.length) { | ||
return distance; | ||
} | ||
distance = x; | ||
return mult_dist; | ||
}; | ||
|
||
return mult_dist; | ||
} |
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,18 @@ | ||
// Computes the union of a list of matrices | ||
export function union(matrices) { | ||
let pile = []; | ||
for(let i = 0 ; i< matrices[0].length; i++){ | ||
if(!pile[i]){ | ||
pile.push([]); | ||
} | ||
for(let j = 0 ; j<matrices[0][0].length ; j++){ | ||
if(!pile[i].length < matrices[0][0].length){ | ||
pile[i].push(0); | ||
} | ||
for(let k = 0; k<matrices.length; k++){ | ||
pile[i][j] = pile[i][j] + matrices[k][i][j]; | ||
} | ||
} | ||
} | ||
return pile; | ||
} |
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,30 @@ | ||
const reorder = require('../dist/reorder.cjs'); | ||
|
||
const vows = require('vows'); | ||
const assert = require('assert'); | ||
|
||
const suite = vows.describe('reorder.morans_i'); | ||
|
||
suite.addBatch({ | ||
morans_i: { | ||
simple() { | ||
const mat1 = [ | ||
[1,1,1,1], | ||
[1,1,1,1], | ||
[1,1,1,1], | ||
[1,1,1,1] | ||
]; | ||
const mat2 = [ | ||
[1,0,1,0], | ||
[0,1,0,1], | ||
[1,0,1,0], | ||
[0,1,0,1] | ||
]; | ||
|
||
assert.equal(reorder.morans_i(mat1), 1); | ||
assert.equal(reorder.morans_i(mat2), -1); | ||
}, | ||
}, | ||
}); | ||
|
||
suite.export(module); |