This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function kMeans(c){ | |
| var center, i, j, new_clusters = [], new_error = centroids.map(function(){return 0;}), | |
| x, y, clu, dp, closest, closest_distance, distance, same; | |
| centroids = []; | |
| //Determine the center point of each cluster | |
| for(i = 0; i < c.length; i++){ | |
| clu = c[i]; | |
| x = 0; | |
| y = 0; | |
| for(j = 0; j < clu.length; j++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function knn(s){ | |
| //Normalize sample | |
| var s0 = (s[0] - min_X) / (max_X - min_X); | |
| var s1 = (s[1] - min_X) / (max_X - min_X); | |
| //Find nearest neighbors | |
| var c1 = false; | |
| var c2 = false; | |
| var distance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var linreg = (function(numbers){ | |
| var xsum = 0, ysum = 0, xysum = 0, x2sum = 0, m, b; | |
| for(var i = 0; i < numbers.length; i++){ | |
| xsum += i; | |
| ysum += numbers[i]; | |
| xysum += i * numbers[i]; | |
| x2sum += Math.pow(i, 2); | |
| } | |
| m = (numbers.length * xysum - xsum * ysum) / (numbers.length * x2sum - Math.pow(xsum, 2)); | |
| b = (ysum - m * xsum) / numbers.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cest, pest = 0, mea, kg, eest = 1, emea = 1; | |
| function kalman(m){ | |
| mea = m; | |
| kg = eest / (eest + emea); | |
| cest = pest + kg * (mea - pest); | |
| pest = cest; | |
| eest = (emea * eest) / (emea + eest); | |
| return cest; | |
| } |
NewerOlder