UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

36 lines (35 loc) 1.05 kB
"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; };