Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

skmeans

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skmeans - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

test/test_rand.js

33

dist/skmeans.js

@@ -133,17 +133,20 @@ "use strict";

var idx = 0;
while (idx < len - 1 && prs[idx++].cs >= rnd) {}
var done = false;
while (!done) {
// this is our new centroid
c = prs[idx - 1].v;
key = multi ? c.join("_") : "" + c;
if (!map[key]) {
map[key] = true;
ks.push(c);
done = true;
} else {
idx++;
}
}
while (idx < len - 1 && prs[idx++].cs < rnd) {}
ks.push(prs[idx - 1].v);
/*
let done = false;
while(!done) {
// this is our new centroid
c = prs[idx-1].v
key = multi? c.join("_") : `${c}`;
if(!map[key]) {
map[key] = true;
ks.push(c);
done = true;
}
else {
idx++;
}
}
*/
}

@@ -150,0 +153,0 @@

@@ -1,3 +0,3 @@

/*! skmeans 2017-07-20 */
/*! skmeans 2017-07-21 */
"use strict";!function r(n,t,o){function a(i,f){if(!t[i]){if(!n[i]){var s="function"==typeof require&&require;if(!f&&s)return s(i,!0);if(e)return e(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var v=t[i]={exports:{}};n[i][0].call(v.exports,function(r){var t=n[i][1][r];return a(t||r)},v,v.exports,r,n,t,o)}return t[i].exports}for(var e="function"==typeof require&&require,i=0;i<o.length;i++)a(o[i]);return a}({1:[function(r,n,t){!function(n){var t=r("./main.js");n.skmeans=t}(window)},{"./main.js":4}],2:[function(r,n,t){n.exports={eudist:function(r,n,t){for(var o=r.length,a=0,e=0;e<o;e++){var i=(r[e]||0)-(n[e]||0);a+=i*i}return t?Math.sqrt(a):a},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"),a=o.eudist,e=o.dist;n.exports={kmrand:function(r,n){for(var t={},o=[],a=n<<2,e=r.length,i=r[0].length>0;o.length<n&&a-- >0;){var f=r[Math.floor(Math.random()*e)],s=i?f.join("_"):""+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?a:e,o=[],i=r.length,f=r[0].length>0,s={},u=r[Math.floor(Math.random()*i)],v=f?u.join("_"):""+u;for(o.push(u),s[v]=!0;o.length<n;){for(var c=[],h=o.length,l=0,d=[],p=0;p<i;p++){for(var g=1/0,m=0;m<h;m++){var k=t(r[p],o[m]);k<=g&&(g=k)}c[p]=g}for(var j=0;j<i;j++)l+=c[j];for(var M=0;M<i;M++)d[M]={i:M,v:r[M],pr:c[M]/l,cs:0};d.sort(function(r,n){return r.pr-n.pr}),d[0].cs=d[0].pr;for(var x=1;x<i;x++)d[x].cs=d[x-1].cs+d[x].pr;for(var w=Math.random(),q=0;q<i-1&&d[q++].cs>=w;);for(var _=!1;!_;)u=d[q-1].v,s[v=f?u.join("_"):""+u]?q++:(s[v]=!0,o.push(u),_=!0)}return o}}},{"./distance.js":2}],4:[function(r,n,t){function o(r,n,t){t=t||[];for(var o=0;o<r;o++)t[o]=n;return t}var a=r("./distance.js"),e=r("./kinit.js"),i=a.eudist,f=(a.dist,e.kmrand),s=e.kmpp,u=1e4;n.exports=function(r,n,t,a){var e=[],v=[],c=[],h=[],l=!1,d=a||u,p=r.length,g=r[0].length,m=g>0;if(t)e="kmrand"==t?f(r,n):"kmpp"==t?s(r,n):t;else for(var k={};e.length<n;){var j=Math.floor(Math.random()*p);k[j]||(k[j]=!0,e.push(r[j]))}do{for(var M=0;M<p;M++){for(var x=1/0,w=0,q=0;q<n;q++)(h=m?i(r[M],e[q]):Math.abs(r[M]-e[q]))<=x&&(x=h,w=q);c[M]=w}for(var _=[],b=[],v=[],E=0;E<n;E++)_[E]=0,b[E]=m?o(g,0,b[E]):0,v[E]=e[E];if(m){for(var O=0;O<n;O++)e[O]=[];for(var y=0;y<p;y++){for(var D=c[y],N=b[D],U=r[y],z=0;z<g;z++)N[z]+=U[z];_[D]++}l=!0;for(var C=0;C<n;C++){for(var F=e[C],L=b[C],T=v[C],A=_[C],B=0;B<g;B++)F[B]=L[B]/A||0;if(l)for(var G=0;G<g;G++)if(T[G]!=F[G]){l=!1;break}}}else{for(var H=0;H<p;H++){var I=c[H];b[I]+=r[H],_[I]++}for(var J=0;J<n;J++)e[J]=b[J]/_[J]||0;l=!0;for(var K=0;K<n;K++)if(v[K]!=e[K]){l=!1;break}}l=l||--d<=0}while(!l);return{it:u-d,k:n,idxs:c,centroids:e}}},{"./distance.js":2,"./kinit.js":3}]},{},[1]);
"use strict";!function r(n,t,o){function a(i,f){if(!t[i]){if(!n[i]){var s="function"==typeof require&&require;if(!f&&s)return s(i,!0);if(e)return e(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var v=t[i]={exports:{}};n[i][0].call(v.exports,function(r){var t=n[i][1][r];return a(t||r)},v,v.exports,r,n,t,o)}return t[i].exports}for(var e="function"==typeof require&&require,i=0;i<o.length;i++)a(o[i]);return a}({1:[function(r,n,t){!function(n){var t=r("./main.js");n.skmeans=t}(window)},{"./main.js":4}],2:[function(r,n,t){n.exports={eudist:function(r,n,t){for(var o=r.length,a=0,e=0;e<o;e++){var i=(r[e]||0)-(n[e]||0);a+=i*i}return t?Math.sqrt(a):a},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"),a=o.eudist,e=o.dist;n.exports={kmrand:function(r,n){for(var t={},o=[],a=n<<2,e=r.length,i=r[0].length>0;o.length<n&&a-- >0;){var f=r[Math.floor(Math.random()*e)],s=i?f.join("_"):""+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?a:e,o=[],i=r.length,f=r[0].length>0,s={},u=r[Math.floor(Math.random()*i)],v=f?u.join("_"):""+u;for(o.push(u),s[v]=!0;o.length<n;){for(var c=[],h=o.length,l=0,d=[],p=0;p<i;p++){for(var g=1/0,m=0;m<h;m++){var k=t(r[p],o[m]);k<=g&&(g=k)}c[p]=g}for(var M=0;M<i;M++)l+=c[M];for(var j=0;j<i;j++)d[j]={i:j,v:r[j],pr:c[j]/l,cs:0};d.sort(function(r,n){return r.pr-n.pr}),d[0].cs=d[0].pr;for(var x=1;x<i;x++)d[x].cs=d[x-1].cs+d[x].pr;for(var w=Math.random(),q=0;q<i-1&&d[q++].cs<w;);o.push(d[q-1].v)}return o}}},{"./distance.js":2}],4:[function(r,n,t){function o(r,n,t){t=t||[];for(var o=0;o<r;o++)t[o]=n;return t}var a=r("./distance.js"),e=r("./kinit.js"),i=a.eudist,f=(a.dist,e.kmrand),s=e.kmpp,u=1e4;n.exports=function(r,n,t,a){var e=[],v=[],c=[],h=[],l=!1,d=a||u,p=r.length,g=r[0].length,m=g>0;if(t)e="kmrand"==t?f(r,n):"kmpp"==t?s(r,n):t;else for(var k={};e.length<n;){var M=Math.floor(Math.random()*p);k[M]||(k[M]=!0,e.push(r[M]))}do{for(var j=0;j<p;j++){for(var x=1/0,w=0,q=0;q<n;q++)(h=m?i(r[j],e[q]):Math.abs(r[j]-e[q]))<=x&&(x=h,w=q);c[j]=w}for(var b=[],E=[],v=[],_=0;_<n;_++)b[_]=0,E[_]=m?o(g,0,E[_]):0,v[_]=e[_];if(m){for(var O=0;O<n;O++)e[O]=[];for(var y=0;y<p;y++){for(var D=c[y],N=E[D],U=r[y],z=0;z<g;z++)N[z]+=U[z];b[D]++}l=!0;for(var C=0;C<n;C++){for(var F=e[C],L=E[C],T=v[C],A=b[C],B=0;B<g;B++)F[B]=L[B]/A||0;if(l)for(var G=0;G<g;G++)if(T[G]!=F[G]){l=!1;break}}}else{for(var H=0;H<p;H++){var I=c[H];E[I]+=r[H],b[I]++}for(var J=0;J<n;J++)e[J]=E[J]/b[J]||0;l=!0;for(var K=0;K<n;K++)if(v[K]!=e[K]){l=!1;break}}l=l||--d<=0}while(!l);return{it:u-d,k:n,idxs:c,centroids:e}}},{"./distance.js":2,"./kinit.js":3}]},{},[1]);

@@ -79,4 +79,5 @@ const

let idx = 0;
while(idx<len-1 && prs[idx++].cs>=rnd);
while(idx<len-1 && prs[idx++].cs<rnd);
ks.push(prs[idx-1].v);
/*
let done = false;

@@ -96,2 +97,3 @@ while(!done) {

}
*/
}

@@ -98,0 +100,0 @@

{
"name": "skmeans",
"version": "0.9.3",
"version": "0.9.4",
"description": "Super fast simple kmeans clustering for unidimiensional and multidimensional data. Works in node and browser",

@@ -5,0 +5,0 @@ "author": "David Gómez Matarrodona <solzimer@gmail.com>",

const skmeans = require("../main.js");
const data = require("./data/well-separated.js");
var res = skmeans(data,3,"kmpp");
var method = process.argv[2] || null;
var res = skmeans(data,3,method);
console.error(res);

@@ -22,2 +23,2 @@ var out = data.map((d,i)=>{

console.log(JSON.stringify(out));
console.log(JSON.stringify(out,null,2));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc