UNPKG

siafun

Version:
22 lines (21 loc) 920 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); const util_1 = require("./util"); function getConnectednessRatings(siatecResult) { const numPoints = siatecResult.points.length; const connections = _.times(numPoints, () => _.times(numPoints, _.constant(0))); const occurrences = siatecResult.patterns.map(p => p.occurrences); const indexOccs = util_1.pointsToIndices(occurrences, siatecResult.points); indexOccs.forEach(o => //increase the connection matrix values for all pairs of associated points _.zip(...o).forEach(t => allPairs(t).forEach(p => { connections[p[0]][p[1]]++; connections[p[1]][p[0]]++; }))); return connections; } exports.getConnectednessRatings = getConnectednessRatings; function allPairs(nums) { return _.flatten(nums.map((n, i) => nums.filter((_, j) => j > i).map(m => [n, m]))); }