Comparing version 0.11.0 to 0.11.1
@@ -0,0 +0,0 @@ "use strict"; |
@@ -128,4 +128,4 @@ "use strict"; | ||
*/ | ||
kmpp: function kmpp(data, k) { | ||
var distance = data[0].length ? eudist : dist; | ||
kmpp: function kmpp(data, k, fndist) { | ||
var distance = fndist || (data[0].length ? eudist : dist); | ||
var ks = [], | ||
@@ -296,3 +296,3 @@ len = data.length; | ||
} else if (initial == "kmpp") { | ||
ks = kmpp(data, k); | ||
ks = kmpp(data, k, fndist); | ||
} else { | ||
@@ -299,0 +299,0 @@ ks = initial; |
@@ -1,3 +0,3 @@ | ||
/*! skmeans 2019-08-27 */ | ||
/*! skmeans 2019-09-13 */ | ||
"use strict";!function e(i,f,s){function u(n,r){if(!f[n]){if(!i[n]){var t="function"==typeof require&&require;if(!r&&t)return t(n,!0);if(v)return v(n,!0);var o=new Error("Cannot find module '"+n+"'");throw o.code="MODULE_NOT_FOUND",o}var a=f[n]={exports:{}};i[n][0].call(a.exports,function(r){return u(i[n][1][r]||r)},a,a.exports,e,i,f,s)}return f[n].exports}for(var v="function"==typeof require&&require,r=0;r<s.length;r++)u(s[r]);return u}({1:[function(n,t,o){(function(){this.skmeans;var r=n("./main.js");void 0!==o&&(void 0!==t&&t.exports&&(o=t.exports=r),o.skmeans=r),"undefined"!=typeof window&&(window.skmeans=r)}).call(this)},{"./main.js":4}],2:[function(r,n,t){n.exports={eudist:function(r,n){for(var t=r.length,o=0,a=0;a<t;a++){var e=(r[a]||0)-(n[a]||0);o+=e*e}return o},mandist:function(r,n){for(var t=r.length,o=0,a=0,e=0;e<t;e++)o+=0<=(a=(r[e]||0)-(n[e]||0))?a:-a;return o},dist:function(r,n,t){var o=Math.abs(r-n);return t?o:o*o}}},{}],3:[function(r,n,t){var o=r("./distance.js"),M=o.eudist,j=o.dist;n.exports={kmrand:function(r,n){for(var t={},o=[],a=n<<2,e=r.length,i=0<r[0].length;o.length<n&&0<a--;){var f=r[Math.floor(Math.random()*e)],s=i?f.join("_"):"".concat(f);t[s]||(t[s]=!0,o.push(f))}if(o.length<n)throw new Error("Error initializating clusters");return o},kmpp:function(r,n){var t=r[0].length?M:j,o=[],a=r.length,e=0<r[0].length,i=r[Math.floor(Math.random()*a)];e?i.join("_"):"".concat(i);for(o.push(i);o.length<n;){for(var f=[],s=o.length,u=0,v=[],c=0;c<a;c++){for(var h=1/0,d=0;d<s;d++){var l=t(r[c],o[d]);l<=h&&(h=l)}f[c]=h}for(var p=0;p<a;p++)u+=f[p];for(var m=0;m<a;m++)v[m]={i:m,v:r[m],pr:f[m]/u,cs:0};v.sort(function(r,n){return r.pr-n.pr}),v[0].cs=v[0].pr;for(var g=1;g<a;g++)v[g].cs=v[g-1].cs+v[g].pr;for(var k=Math.random(),x=0;x<a-1&&v[x++].cs<k;);o.push(v[x-1].v)}return o}}},{"./distance.js":2}],4:[function(r,n,t){var o=r("./distance.js"),a=r("./kinit.js"),H=o.eudist,I=(o.mandist,o.dist,a.kmrand),J=a.kmpp;function K(r,n,t){t=t||[];for(var o=0;o<r;o++)t[o]=n;return t}function P(r,n){for(var t=Array.isArray(r),o=this.centroids,a=o.length,e=1/0,i=0,f=0;f<a;f++){var s=n?n(r,o[f]):t?H(r,o[f]):Math.abs(r-o[f]);s<=e&&(e=s,i=f)}return{idx:i,centroid:o[i]}}n.exports=function(r,n,t,o,a){var e=[],i=[],f=[],s=[],u=!1,v=o||1e4,c=r.length,h=r[0].length,d=0<h,l=[];if(t)e="kmrand"==t?I(r,n):"kmpp"==t?J(r,n):t;else for(var p={},m=0;e.length<n;){var g=Math.floor(Math.random()*c);p[g]||(p[g]=!0,e[m++]=r[g])}do{K(n,0,l);for(var k=0;k<c;k++){for(var x=1/0,M=0,j=0;j<n;j++)(s=a?a(r[k],e[j]):d?H(r[k],e[j]):Math.abs(r[k]-e[j]))<=x&&(x=s,M=j);l[f[k]=M]++}var w=[];if(i=[],d)for(var b=0;b<n;b++)w[b]=K(h,0,w[b]),i[b]=e[b];else for(var y=0;y<n;y++)w[y]=0,i[y]=e[y];if(d){for(var q=0;q<n;q++)e[q]=[];for(var E=0;E<c;E++)for(var _=w[f[E]],O=r[E],A=0;A<h;A++)_[A]+=O[A];u=!0;for(var D=0;D<n;D++){for(var N=e[D],U=w[D],z=i[D],C=l[D],F=0;F<h;F++)N[F]=U[F]/C||0;if(u)for(var L=0;L<h;L++)if(z[L]!=N[L]){u=!1;break}}}else{for(var T=0;T<c;T++)w[f[T]]+=r[T];for(var B=0;B<n;B++)e[B]=w[B]/l[B]||0;u=!0;for(var G=0;G<n;G++)if(i[G]!=e[G]){u=!1;break}}u=u||--v<=0}while(!u);return{it:1e4-v,k:n,idxs:f,centroids:e,test:P}}},{"./distance.js":2,"./kinit.js":3}]},{},[1]); | ||
"use strict";!function e(i,f,s){function u(n,r){if(!f[n]){if(!i[n]){var t="function"==typeof require&&require;if(!r&&t)return t(n,!0);if(v)return v(n,!0);var o=new Error("Cannot find module '"+n+"'");throw o.code="MODULE_NOT_FOUND",o}var a=f[n]={exports:{}};i[n][0].call(a.exports,function(r){return u(i[n][1][r]||r)},a,a.exports,e,i,f,s)}return f[n].exports}for(var v="function"==typeof require&&require,r=0;r<s.length;r++)u(s[r]);return u}({1:[function(n,t,o){(function(){this.skmeans;var r=n("./main.js");void 0!==o&&(void 0!==t&&t.exports&&(o=t.exports=r),o.skmeans=r),"undefined"!=typeof window&&(window.skmeans=r)}).call(this)},{"./main.js":4}],2:[function(r,n,t){n.exports={eudist:function(r,n){for(var t=r.length,o=0,a=0;a<t;a++){var e=(r[a]||0)-(n[a]||0);o+=e*e}return o},mandist:function(r,n){for(var t=r.length,o=0,a=0,e=0;e<t;e++)o+=0<=(a=(r[e]||0)-(n[e]||0))?a:-a;return o},dist:function(r,n,t){var o=Math.abs(r-n);return t?o:o*o}}},{}],3:[function(r,n,t){var o=r("./distance.js"),j=o.eudist,w=o.dist;n.exports={kmrand:function(r,n){for(var t={},o=[],a=n<<2,e=r.length,i=0<r[0].length;o.length<n&&0<a--;){var f=r[Math.floor(Math.random()*e)],s=i?f.join("_"):"".concat(f);t[s]||(t[s]=!0,o.push(f))}if(o.length<n)throw new Error("Error initializating clusters");return o},kmpp:function(r,n,t){var o=t||(r[0].length?j:w),a=[],e=r.length,i=0<r[0].length,f=r[Math.floor(Math.random()*e)];i?f.join("_"):"".concat(f);for(a.push(f);a.length<n;){for(var s=[],u=a.length,v=0,c=[],h=0;h<e;h++){for(var d=1/0,l=0;l<u;l++){var p=o(r[h],a[l]);p<=d&&(d=p)}s[h]=d}for(var m=0;m<e;m++)v+=s[m];for(var g=0;g<e;g++)c[g]={i:g,v:r[g],pr:s[g]/v,cs:0};c.sort(function(r,n){return r.pr-n.pr}),c[0].cs=c[0].pr;for(var k=1;k<e;k++)c[k].cs=c[k-1].cs+c[k].pr;for(var x=Math.random(),M=0;M<e-1&&c[M++].cs<x;);a.push(c[M-1].v)}return a}}},{"./distance.js":2}],4:[function(r,n,t){var o=r("./distance.js"),a=r("./kinit.js"),H=o.eudist,I=(o.mandist,o.dist,a.kmrand),J=a.kmpp;function K(r,n,t){t=t||[];for(var o=0;o<r;o++)t[o]=n;return t}function P(r,n){for(var t=Array.isArray(r),o=this.centroids,a=o.length,e=1/0,i=0,f=0;f<a;f++){var s=n?n(r,o[f]):t?H(r,o[f]):Math.abs(r-o[f]);s<=e&&(e=s,i=f)}return{idx:i,centroid:o[i]}}n.exports=function(r,n,t,o,a){var e=[],i=[],f=[],s=[],u=!1,v=o||1e4,c=r.length,h=r[0].length,d=0<h,l=[];if(t)e="kmrand"==t?I(r,n):"kmpp"==t?J(r,n,a):t;else for(var p={},m=0;e.length<n;){var g=Math.floor(Math.random()*c);p[g]||(p[g]=!0,e[m++]=r[g])}do{K(n,0,l);for(var k=0;k<c;k++){for(var x=1/0,M=0,j=0;j<n;j++)(s=a?a(r[k],e[j]):d?H(r[k],e[j]):Math.abs(r[k]-e[j]))<=x&&(x=s,M=j);l[f[k]=M]++}var w=[];if(i=[],d)for(var b=0;b<n;b++)w[b]=K(h,0,w[b]),i[b]=e[b];else for(var y=0;y<n;y++)w[y]=0,i[y]=e[y];if(d){for(var q=0;q<n;q++)e[q]=[];for(var E=0;E<c;E++)for(var _=w[f[E]],O=r[E],A=0;A<h;A++)_[A]+=O[A];u=!0;for(var D=0;D<n;D++){for(var N=e[D],U=w[D],z=i[D],C=l[D],F=0;F<h;F++)N[F]=U[F]/C||0;if(u)for(var L=0;L<h;L++)if(z[L]!=N[L]){u=!1;break}}}else{for(var T=0;T<c;T++)w[f[T]]+=r[T];for(var B=0;B<n;B++)e[B]=w[B]/l[B]||0;u=!0;for(var G=0;G<n;G++)if(i[G]!=e[G]){u=!1;break}}u=u||--v<=0}while(!u);return{it:1e4-v,k:n,idxs:f,centroids:e,test:P}}},{"./distance.js":2,"./kinit.js":3}]},{},[1]); |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -31,4 +31,4 @@ "use strict"; | ||
*/ | ||
kmpp: function kmpp(data, k) { | ||
var distance = data[0].length ? eudist : dist; | ||
kmpp: function kmpp(data, k, fndist) { | ||
var distance = fndist || (data[0].length ? eudist : dist); | ||
var ks = [], | ||
@@ -35,0 +35,0 @@ len = data.length; |
@@ -78,3 +78,3 @@ "use strict"; | ||
} else if (initial == "kmpp") { | ||
ks = kmpp(data, k); | ||
ks = kmpp(data, k, fndist); | ||
} else { | ||
@@ -81,0 +81,0 @@ ks = initial; |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = function(grunt) { |
@@ -28,4 +28,4 @@ const | ||
*/ | ||
kmpp(data,k) { | ||
var distance = data[0].length? eudist : dist; | ||
kmpp(data,k,fndist) { | ||
var distance = fndist || (data[0].length? eudist : dist); | ||
var ks = [], len = data.length; | ||
@@ -32,0 +32,0 @@ var multi = data[0].length>0; |
@@ -68,3 +68,3 @@ /*jshint esversion: 6 */ | ||
else if(initial=="kmpp") { | ||
ks = kmpp(data,k); | ||
ks = kmpp(data,k,fndist); | ||
} | ||
@@ -71,0 +71,0 @@ else { |
{ | ||
"name": "skmeans", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "Super fast simple k-means and k-means++ clustering for unidimiensional and multidimensional data. Works in node and browser", | ||
@@ -5,0 +5,0 @@ "author": "David Gómez Matarrodona <solzimer@gmail.com>", |
@@ -0,0 +0,0 @@ # skmeans |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
@@ -0,0 +0,0 @@ const skmeans = require("../main.js"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
106027