lumenize
Version:
Illuminating the forest AND the trees in your data.
61 lines (49 loc) • 1.86 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var multiRegression, predict;
multiRegression = {};
multiRegression.calculateA = function(data) {
/*
@method calculateA
Calculates the coefficient matrix for gaussian elimination solution
*/
var a, i, j, k, l, m, n, numOfVariables, o, ref, ref1, ref2;
numOfVariables = data[0].length;
n = data.length;
a = [];
for (i = l = 0, ref = numOfVariables - 1; 0 <= ref ? l <= ref : l >= ref; i = 0 <= ref ? ++l : --l) {
a.push([]);
for (j = m = 0, ref1 = numOfVariables; 0 <= ref1 ? m <= ref1 : m >= ref1; j = 0 <= ref1 ? ++m : --m) {
a[i].push(0);
for (k = o = 0, ref2 = n - 1; 0 <= ref2 ? o <= ref2 : o >= ref2; k = 0 <= ref2 ? ++o : --o) {
a[i][j] += (i === 0 ? 1 : data[k][i - 1]) * (j === 0 ? 1 : data[k][j - 1]);
}
}
}
return a;
};
multiRegression.swapRows = function(a, firstRowIndex, secondRowIndex) {
var j, l, ref, results, temp;
results = [];
for (j = l = 0, ref = a[0].length - 1; 0 <= ref ? l <= ref : l >= ref; j = 0 <= ref ? ++l : --l) {
temp = a[firstRowIndex][j];
a[firstRowIndex][j] = a[secondRowIndex][j];
results.push(a[secondRowIndex][j] = temp);
}
return results;
};
predict = function(data, inputs) {
/*
@method predict
@param {[][]} data A two-dimensional array
@param
Returns a prediction of the output based upon historical data and input "estimates"
The last column of the Data array is the value we are trying to predict. The other
columns are the inputs. The input array will order-wise coorespond to the first
n-1 columns of the data array.
@return {Object}
returns {A, Beta, variance, prediction}
*/
};
exports.multiRegression = multiRegression;
}).call(this);