From 3d24dcedf85a52128c4bca0179bcb6d2d2c65b33 Mon Sep 17 00:00:00 2001 From: jgould Date: Fri, 29 Jul 2016 12:24:45 -0400 Subject: [PATCH] added value to count --- src/matrix/vector_util.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/matrix/vector_util.js b/src/matrix/vector_util.js index 9344f8c..89842c9 100644 --- a/src/matrix/vector_util.js +++ b/src/matrix/vector_util.js @@ -39,6 +39,26 @@ morpheus.VectorUtil.createValueToCountMap = function (vector) { } return map; }; + +morpheus.VectorUtil.createValuesToCountMap = function (vectors) { + var map = new morpheus.Map(); + var nvectors = vectors.length; + if (vectors[0] == null) { + throw 'no vectors found'; + } + for (var i = 0, nitems = vectors[0].size(); i < nitems; i++) { + var array = []; + for (var j = 0; j < nvectors; j++) { + var vector = vectors[j]; + var val = vector.getValue(i); + array.push(val); + } + var key = new morpheus.Identifier(array); + var count = map.get(key) || 0; + map.set(key, count + 1); + } + return map; +}; morpheus.VectorUtil.maybeConvertToStringArray = function (vector, delim) { var newValues = []; var regex = new RegExp(delim); @@ -153,7 +173,7 @@ morpheus.VectorUtil.getValues = function (vector, excludeNull) { } set.add(val); - + } var array = set.values(); array.sort(morpheus.SortKey.ASCENDING_COMPARATOR); -- GitLab