From 14cfbee310c60acd51158f64c5470eca77561388 Mon Sep 17 00:00:00 2001 From: deqingli Date: Thu, 29 Mar 2018 16:07:43 +0800 Subject: [PATCH] release version 1.1.1 --- dist/ecStat.js | 101 +++++++++++++++++++++++++++++++-------------- dist/ecStat.min.js | 2 +- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/dist/ecStat.js b/dist/ecStat.js index 6788d42..d8fc3c8 100644 --- a/dist/ecStat.js +++ b/dist/ecStat.js @@ -73,7 +73,8 @@ return /******/ (function(modules) { // webpackBootstrap var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { - var dataPreprocess = __webpack_require__(2); + var dataProcess = __webpack_require__(2); + var dataPreprocess = dataProcess.dataPreprocess; var array = __webpack_require__(3); var arraySize = array.size; var sumOfColumn = array.sumOfColumn; @@ -164,12 +165,14 @@ return /******/ (function(modules) { // webpackBootstrap /** * The combine of hierarchical clustering and k-means. * @param {Array} data two-dimension array. - * @param {[type]} k the number of clusters in a dataset + * @param {[type]} k the number of clusters in a dataset. It has to be greater than 1. * @param {boolean} stepByStep * @return {} */ function hierarchicalKMeans(data, k, stepByStep) { - + if (k < 2 ) { + return; + } var dataSet = dataPreprocess(data); var size = arraySize(dataSet); var clusterAssment = zeros(size[0], 2); @@ -397,7 +400,22 @@ return /******/ (function(modules) { // webpackBootstrap return predata; } - return dataPreprocess; + /** + * @param {string|number} val + * @return {number} + */ + function getPrecision(val) { + var str = val.toString(); + // scientific notation is not considered + var dotIndex = str.indexOf('.'); + return dotIndex < 0 ? 0 : str.length - 1 - dotIndex; + } + + return { + dataPreprocess: dataPreprocess, + getPrecision: getPrecision + }; + }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); /***/ }), @@ -569,7 +587,7 @@ return /******/ (function(modules) { // webpackBootstrap */ function isNumber(value) { - value = (value === null ? NaN : +value); + value = value === null ? NaN : +value; return typeof value === 'number' && !isNaN(value); } @@ -595,7 +613,8 @@ return /******/ (function(modules) { // webpackBootstrap var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { - var dataPreprocess = __webpack_require__(2); + var dataProcess = __webpack_require__(2); + var dataPreprocess = dataProcess.dataPreprocess; var regreMethods = { @@ -908,8 +927,8 @@ return /******/ (function(modules) { // webpackBootstrap statistics.mean = __webpack_require__(10); statistics.median = __webpack_require__(12); statistics.min = __webpack_require__(14); - statistics.max = __webpack_require__(13); - statistics.max = __webpack_require__(9); + statistics.quantile = __webpack_require__(13); + statistics.sampleVariance = __webpack_require__(9); statistics.sum = __webpack_require__(11); return statistics; @@ -1000,7 +1019,7 @@ return /******/ (function(modules) { // webpackBootstrap sum += temple * temple; } } - return sum / data.length - 1; + return sum / (data.length - 1); } } @@ -1008,6 +1027,7 @@ return /******/ (function(modules) { // webpackBootstrap }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { @@ -1172,7 +1192,9 @@ return /******/ (function(modules) { // webpackBootstrap var min = __webpack_require__(14); var quantile = __webpack_require__(13); var deviation = __webpack_require__(8); - var dataPreprocess = __webpack_require__(2); + var dataProcess = __webpack_require__(2); + var dataPreprocess = dataProcess.dataPreprocess; + var getPrecision = dataProcess.getPrecision; var array = __webpack_require__(3); var ascending = array.ascending; var map = array.map; @@ -1189,25 +1211,26 @@ return /******/ (function(modules) { // webpackBootstrap function computeBins(data, threshold) { if (threshold == null) { - threshold = thresholdMethod.squareRoot; - } else { - threshold = thresholdMethod[threshold]; - } var values = dataPreprocess(data); var maxValue = max(values); var minValue = min(values); - var binsNumber = threshold(values, minValue, maxValue); - var step = tickStep(minValue, maxValue, binsNumber); - + var precision = -Math.floor(Math.log(Math.abs(maxValue - minValue) / binsNumber) / Math.LN10); + // return the xAxis coordinate for each bins, except the end point of the value - var rangeArray = range(Math.ceil(minValue / step) * step, Math.floor(maxValue / step) * step, step); + var rangeArray = range( + // use function toFixed() to avoid data like '0.700000001' + +((Math.ceil(minValue / step) * step).toFixed(precision)), + +((Math.floor(maxValue / step) * step).toFixed(precision)), + step, + precision + ); var len = rangeArray.length; @@ -1216,7 +1239,7 @@ return /******/ (function(modules) { // webpackBootstrap for (var i = 0; i <= len; i++) { bins[i] = {}; bins[i].sample = []; - bins[i].x0 = i > 0 // 不要数组直接挂属性,改成Object + bins[i].x0 = i > 0 ? rangeArray[i - 1] : (rangeArray[i] - minValue) === step ? minValue @@ -1235,16 +1258,21 @@ return /******/ (function(modules) { // webpackBootstrap } var data = map(bins, function (bin) { - return [(bin.x0 + bin.x1) / 2, bin.sample.length]; + // use function toFixed() to avoid data like '6.5666638489' + return [+((bin.x0 + bin.x1) / 2).toFixed(precision), bin.sample.length]; + }); + + var customData = map(bins, function (bin) { + return [bin.x0, bin.x1, bin.sample.length]; }); return { bins: bins, - data: data + data: data, + customData: customData }; } - /** * Four kinds of threshold methods used to * compute how much bins the histogram should be divided @@ -1291,34 +1319,42 @@ return /******/ (function(modules) { // webpackBootstrap var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { + var dataProcess = __webpack_require__(2); + var getPrecision = dataProcess.getPrecision; + /** - * Computing range array + * Computing range array. + * Adding param precision to fix range value, avoiding range[i] = 0.7000000001. * @param {number} start - * @param {number} stop + * @param {number} end * @param {number} step + * @param {number} precision * @return {Array.} */ - return function (start, stop, step) { + return function (start, end, step, precision) { var len = arguments.length; if (len < 2) { - stop = start; + end = start; start = 0; step = 1; } else if (len < 3) { step = 1; } - else { + else if (len < 4) { step = +step; + precision = getPrecision(step); + } + else { + precision = +precision; } - var n = Math.ceil((stop - start) / step); + var n = Math.ceil(((end - start) / step).toFixed(precision)); var range = new Array(n + 1); - for (var i = 0; i < n + 1; i++) { - range[i] = start + i * step; + range[i] = +(start + i * step).toFixed(precision); } return range; }; @@ -1341,7 +1377,8 @@ return /******/ (function(modules) { // webpackBootstrap return function (start, stop, count) { var step0 = Math.abs(stop - start) / count; - var step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)); + var precision = Math.floor(Math.log(step0) / Math.LN10); + var step1 = Math.pow(10, precision); var error = step0 / step1; if (error >= Math.sqrt(50)) { @@ -1353,7 +1390,7 @@ return /******/ (function(modules) { // webpackBootstrap else if(error >= Math.sqrt(2)) { step1 *= 2; } - return stop >= start ? step1 : -step1; + return +((stop >= start ? step1 : -step1).toFixed(-precision)); }; diff --git a/dist/ecStat.min.js b/dist/ecStat.min.js index 83f218d..6aa4af5 100644 --- a/dist/ecStat.min.js +++ b/dist/ecStat.min.js @@ -1 +1 @@ -!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.ecStat=n():r.ecStat=n()}(this,function(){return function(r){function n(e){if(t[e])return t[e].exports;var o=t[e]={exports:{},id:e,loaded:!1};return r[e].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=r,n.c=t,n.p="",n(0)}([function(r,n,t){var e;e=function(r){return{clustering:t(11),regression:t(13),statistics:t(14),histogram:t(12)}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){return r=null===r?NaN:+r,"number"==typeof r&&!isNaN(r)}function t(r){return isFinite(r)&&r===Math.round(r)}return{isNumber:n,isInteger:t}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return function(r,n){var t=r.length;if(!t)return 0;if(n<=0||t<2)return r[0];if(n>=1)return r[t-1];var e=(t-1)*n,o=Math.floor(e),a=r[o],u=r[o+1];return a+(u-a)*(e-o)}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){for(var n=[];t(r);)n.push(r.length),r=r[0];return n}function t(r){return"[object Array]"===l.call(r)}function e(r,n){for(var t=[],e=0;en?1:r0)e=o;else{if(!(a<0))return o+1;t=o+1}}return t}function f(r,n,t){if(r&&n){if(r.map&&r.map===h)return r.map(n,t);for(var e=[],o=0,a=r.length;on&&(n=r[t]);return n}var e=t(1),o=e.isNumber;return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){var n=r.length;return n?e(r)/r.length:0}var e=t(10);return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){for(var n=1/0,t=0;t=2){for(var t,e=a(r),u=0,i=0;ie&&(e=r[f][i]);o=e-t;for(var f=0;f0?g[x-1]:g[x]-u===l?u:g[x]-l,M[x].x1=x50?50:n},scott:function(r,n,t){return Math.ceil((t-n)/(3.5*u(r)*Math.pow(r.length,-1/3)))},freedmanDiaconis:function(r,n,t){return r.sort(l),Math.ceil((t-n)/(2*(a(r,.75)-a(r,.25))*Math.pow(r.length,-1/3)))},sturges:function(r){return Math.ceil(Math.log(r.length)/Math.LN2)+1}};return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r,n){for(var t=0;tMath.abs(r[t][e])&&(e=o);for(var a=t;a=t;f--)r[f][i]-=r[f][t]/r[t][t]*r[t][i]}for(var l=new Array(n),s=r.length-1,o=r.length-2;o>=0;o--){for(var u=0,t=o+1;t=0;f--)x+=f>1?Math.round(g[f]*Math.pow(10,f+1))/Math.pow(10,f+1)+"x^"+f+" + ":1===f?Math.round(100*g[f])/100+"x + ":Math.round(100*g[f])/100;return{points:d,parameter:g,expression:x}}},a=function(r,n,t){return o[r](n,t)};return a}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){var n={};return n.max=t(6),n.deviation=t(5),n.mean=t(7),n.median=t(15),n.min=t(8),n.max=t(2),n.max=t(9),n.sum=t(10),n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){return e(r,.5)}var e=t(2);return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return function(r,n,t){var e=arguments.length;e<2?(n=r,r=0,t=1):t=e<3?1:+t;for(var o=Math.ceil((n-r)/t),a=new Array(o+1),u=0;u=Math.sqrt(50)?o*=10:a>=Math.sqrt(10)?o*=5:a>=Math.sqrt(2)&&(o*=2),n>=r?o:-o}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))}])}); \ No newline at end of file +!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ecStat=t():r.ecStat=t()}(this,function(){return function(r){function t(e){if(n[e])return n[e].exports;var o=n[e]={exports:{},id:e,loaded:!1};return r[e].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=r,t.c=n,t.p="",t(0)}([function(r,t,n){var e;e=function(r){return{clustering:n(11),regression:n(13),statistics:n(14),histogram:n(12)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){return r=null===r?NaN:+r,"number"==typeof r&&!isNaN(r)}function n(r){return isFinite(r)&&r===Math.round(r)}return{isNumber:t,isInteger:n}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){if(!a(r))throw new Error("Invalid data type, you should input an array");var t=[],n=u(r);if(1===n.length)for(var e=0;e=1)return r[n-1];var e=(n-1)*t,o=Math.floor(e),a=r[o],u=r[o+1];return a+(u-a)*(e-o)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){for(var t=[];n(r);)t.push(r.length),r=r[0];return t}function n(r){return"[object Array]"===l.call(r)}function e(r,t){for(var n=[],e=0;et?1:r0)e=o;else{if(!(a<0))return o+1;n=o+1}}return n}function f(r,t,n){if(r&&t){if(r.map&&r.map===c)return r.map(t,n);for(var e=[],o=0,a=r.length;ot&&(t=r[n]);return t}var e=n(1),o=e.isNumber;return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){var t=r.length;return t?e(r)/r.length:0}var e=n(10);return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){for(var t=1/0,n=0;n=2){for(var n,e=a(r),u=0,i=0;ie&&(e=r[f][i]);o=e-n;for(var f=0;f0?d[m-1]:d[m]-u===l?u:d[m]-l,x[m].x1=m50?50:t},scott:function(r,t,n){return Math.ceil((n-t)/(3.5*u(r)*Math.pow(r.length,-1/3)))},freedmanDiaconis:function(r,t,n){return r.sort(s),Math.ceil((n-t)/(2*(a(r,.75)-a(r,.25))*Math.pow(r.length,-1/3)))},sturges:function(r){return Math.ceil(Math.log(r.length)/Math.LN2)+1}};return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r,t){for(var n=0;nMath.abs(r[n][e])&&(e=o);for(var a=n;a=n;f--)r[f][i]-=r[f][n]/r[n][n]*r[n][i]}for(var l=new Array(t),s=r.length-1,o=r.length-2;o>=0;o--){for(var u=0,n=o+1;n=0;f--)x+=f>1?Math.round(g[f]*Math.pow(10,f+1))/Math.pow(10,f+1)+"x^"+f+" + ":1===f?Math.round(100*g[f])/100+"x + ":Math.round(100*g[f])/100;return{points:d,parameter:g,expression:x}}},u=function(r,t,n){return a[r](t,n)};return u}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){var t={};return t.max=n(6),t.deviation=n(5),t.mean=n(7),t.median=n(15),t.min=n(8),t.quantile=n(3),t.sampleVariance=n(9),t.sum=n(10),t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){return e(r,.5)}var e=n(3);return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){var t=n(2),e=t.getPrecision;return function(r,t,n,o){var a=arguments.length;a<2?(t=r,r=0,n=1):a<3?n=1:a<4?(n=+n,o=e(n)):o=+o;for(var u=Math.ceil(((t-r)/n).toFixed(o)),i=new Array(u+1),f=0;f=Math.sqrt(50)?a*=10:u>=Math.sqrt(10)?a*=5:u>=Math.sqrt(2)&&(a*=2),+(t>=r?a:-a).toFixed(-o)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))}])}); \ No newline at end of file