@nexys/math-ts
Version:
[](https://www.npmjs.com/package/@nexys/math-ts) [](https://travis-ci.com/github/Nexysweb/math-ts) [ • 1.05 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const M = __importStar(require("../matrix"));
class Linear {
constructor(x, y) {
if (Array.isArray(y[0])) {
this.x = x;
this.y = y;
}
else {
this.x = x;
this.y = M.transpose([y]);
}
const xt = M.transpose(this.x);
this.g = M.multiplication(xt, this.x);
this.z = M.inverse(this.g);
const preb = M.multiplication(xt, this.y);
this.a = M.multiplication(this.z, preb);
}
estimateY(x = this.x) {
return M.multiplication(x, this.a);
}
}
exports.default = Linear;
exports.regression = (x, py) => {
const L = new Linear(x, py);
return L.a;
};