Comparing version 1.1.2 to 1.2.0
@@ -0,0 +0,0 @@ Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. |
@@ -0,1 +1,11 @@ | ||
<a name="1.2.0"></a> | ||
# [1.2.0](https://github.com/mljs/hclust/compare/v1.1.2...v1.2.0) (2016-09-05) | ||
### Features | ||
* **cluster:** use a heap to group clusters ([8c70c9e](https://github.com/mljs/hclust/commit/8c70c9e)) | ||
<a name="1.1.2"></a> | ||
@@ -2,0 +12,0 @@ ## [1.1.2](https://github.com/mljs/hclust/compare/v1.1.1...v1.1.2) (2016-09-01) |
{ | ||
"name": "ml-hclust", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Hierarchical clustering algorithms in Javascript", | ||
@@ -39,4 +39,5 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"heap": "^0.2.6", | ||
"ml-distance-euclidean": "^1.0.0" | ||
} | ||
} |
@@ -8,2 +8,3 @@ 'use strict'; | ||
/** | ||
* @private | ||
* @param cluster1 | ||
@@ -25,2 +26,3 @@ * @param cluster2 | ||
/** | ||
* @private | ||
* @param cluster1 | ||
@@ -42,2 +44,3 @@ * @param cluster2 | ||
/** | ||
* @private | ||
* @param cluster1 | ||
@@ -57,2 +60,3 @@ * @param cluster2 | ||
/** | ||
* @private | ||
* @param cluster1 | ||
@@ -74,2 +78,3 @@ * @param cluster2 | ||
/** | ||
* @private | ||
* @param cluster1 | ||
@@ -76,0 +81,0 @@ * @param cluster2 |
'use strict'; | ||
const Heap = require('heap'); | ||
function Cluster () { | ||
@@ -38,31 +40,22 @@ this.children = []; | ||
Cluster.prototype.group = function (minGroups) { | ||
if (minGroups < 1) throw new RangeError('Number of groups too small'); | ||
if (!Number.isInteger(minGroups) || minGroups < 1) throw new RangeError('Number of groups must be a positive integer'); | ||
const heap = new Heap(function (a, b) { | ||
return b.distance - a.distance; | ||
}); | ||
heap.push(this); | ||
while (heap.size() < minGroups) { | ||
var first = heap.pop(); | ||
if (first.children.length === 0) { | ||
break; | ||
} | ||
first.children.forEach(child => heap.push(child)); | ||
} | ||
var root = new Cluster(); | ||
root.children = this.children; | ||
root.children = heap.toArray(); | ||
root.distance = this.distance; | ||
root.index = this.index; | ||
if (minGroups === 1) | ||
return root; | ||
var list = [root]; | ||
var aux; | ||
var listLeafs = []; | ||
while ((list.length + listLeafs.length) < minGroups && list.length !== 0) { | ||
aux = list.shift(); | ||
if (aux.children) | ||
list = list.concat(aux.children); | ||
else | ||
listLeafs.push(aux); | ||
} | ||
if (list.length === 0) throw new RangeError('Number of groups too big'); | ||
list = list.concat(listLeafs); | ||
for (var i = 0; i < list.length; i++) | ||
if (list[i].distance === aux.distance) { | ||
list.concat(list[i].children.slice(1)); | ||
list[i] = list[i].children[0]; | ||
} | ||
for (var j = 0; j < list.length; j++) | ||
if (list[j].distance !== 0) { | ||
var obj = list[j]; | ||
obj.children = obj.index; | ||
} | ||
return root; | ||
@@ -69,0 +62,0 @@ }; |
@@ -10,3 +10,3 @@ 'use strict'; | ||
this.distance = 0; | ||
this.children = undefined; | ||
this.children = []; | ||
} | ||
@@ -13,0 +13,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
/** | ||
* @private | ||
* @param {Array <Array <number>>} cluster1 | ||
@@ -25,2 +26,3 @@ * @param {Array <Array <number>>} cluster2 | ||
/** | ||
* @private | ||
* @param {Array <Array <number>>} cluster1 | ||
@@ -42,2 +44,3 @@ * @param {Array <Array <number>>} cluster2 | ||
/** | ||
* @private | ||
* @param {Array <Array <number>>} cluster1 | ||
@@ -57,2 +60,3 @@ * @param {Array <Array <number>>} cluster2 | ||
/** | ||
* @private | ||
* @param {Array <Array <number>>} cluster1 | ||
@@ -84,2 +88,3 @@ * @param {Array <Array <number>>} cluster2 | ||
/** | ||
* @private | ||
* @param {Array <Array <number>>} cluster1 | ||
@@ -111,2 +116,3 @@ * @param {Array <Array <number>>} cluster2 | ||
/** | ||
* @private | ||
* Returns the most distant point and his distance | ||
@@ -156,2 +162,3 @@ * @param {Array <Array <number>>} splitting - Clusters to split | ||
/** | ||
* @private | ||
* Intra-cluster distance | ||
@@ -158,0 +165,0 @@ * @param {Array} index |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1587876
2
1560
+ Addedheap@^0.2.6
+ Addedheap@0.2.7(transitive)