/* * Copyright (c), Mohamed Ali Jamaoui, All rights reserved * released under the MIT license */ var dm = {}; dm.dataMiner = function module(){ function exports(){ console.log("starting the dataMiner"); }; /* @param{Array}: the data subset, an array of double * @param{integer}: the number of cluster centroids * @param{integer}: max number of iterations in the algorithm * * Note: iteration is a safety key, that is defined by the user to handle the case when the algorithm doesn't converge * , I don't know if this case will occur but better be sure than sorry, therefore the algorithm will stop when * the max number of iterations is reached (default max 1000) */ exports.kmeans = function(subsets, k, Maxiteration){ if(k > subsets.length) { return false; } Array.prototype.diff = function(a) { return this.filter(function(i) {return !(a.indexOf(i) > -1);}); }; var that = this; //storing the current context, required within callbacks //initializing the cluster centroids var centroids = []; for(var i = 0; i