npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gordan

v0.1.7

Published

Gauss-Jordan + Regression JS library

Downloads

6

Readme

gordan.png

Gauss-Jordan + Regression JavaScript library

License Version

Installation

npm i gordan --save

Usage

import Gordan from 'gordan'; // for ES6
const Gordan = require('gordan');  // for Node

Main API

  • matrix: the augmented matrix, a bidimensional array

  • Returns: the identity matrix with the solution coefficients

  • Returns: a list of points for the regression rect
  • Returns: a list of points for the regression curve (from cuadratic equation)
  • Returns: a list of points for an Nth grade equation (ax^N + bx^(N - 1) + cx^(N - 2) + ...)

  • points: for all cases, a list of x, y points. The following formats are supported:

[
  [1, 2],
  [2, 2],
  [3, 3]
]
[
  { "x": 1, "y": 2 },
  { "x": 2, "y": 2 },
  { "x": 3, "y": 3 }
]

Secondary API

  • row1: first row to add, a number array

  • row2: second row to add, a number array

  • invert1: boolean, if present, values in row1 are multiplied by -1

  • invert2: boolean, if present, values in row2 are multiplied by -1

  • Returns: the addition of the 2 rows (number[])

  • row: the row to multiply, a number array

  • value: each number in row is multiplied by this number

  • Returns: a new row with the multipled values (number[])

  • row: the row to divide, a number array

  • value: each number in row is divided by this number

  • Returns: a new row with the divided values (number[])

  • matrix: the augmented matrix, a bidimensional array

  • Returns: the last column of the resulting identity matrix (number[])

  • points: an array of [x, y] or {x, y} points

  • Returns: an array of points with {x, y} format

  • points: an array of [x, y] or {x, y} points

  • degreeOfEquation: a number greater than zero

  • Returns: the regression augmented matrix

  • points: an array of [x, y] or {x, y} points

  • axis: a string 'x' or 'y'

  • Returns: 'x'/'y' limits on the plane for the given points

Gauss-Jordan example

let gaussJordanMatrix = [
  [ 1, -2,  2, -3,   15 ],
  [ 3,  4, -1,  1,   -6 ],
  [ 2, -3,  2, -1,   17 ],
  [ 1,  1, -3, -2,   -7 ]
];

let solvedMatrix = Gordan.solveByGaussJordan(gaussJordanMatrix);

Results in:

1, 	0, 	0, 	0, 	2

0, 	1, 	0, 	0, 	-2

0, 	0, 	1, 	0, 	3

0, 	0, 	0, 	1, 	-1

Regression example

let points = [
  [1, 2],
  [1.5, 4],
  [2, 2.4],
  [3, 5],
  [4, 3],
  [5.5, 9.3],
  [5, 6],
  [6, 10],
  [6.5, 8.5],
  [6.5, 13],
  [7, 12.5]
];

let rect = Gordan.getLinearRegressionRect(points);
let curve = Gordan.getQuadraticRegressionCurve(points);
let gradeSixCurve = Gordan.getRegressionPath(points, 6);

Results in:

chart.png

Here's the Chart.js code needed for that:

let chart = new Chart(document.getElementById('chart'), {
  type: 'scatter',
  data: {
    datasets: [{
      label: 'The points',
      data: Gordan.normalizePoints(points),
      backgroundColor: '#f40'
    }, {
      label: 'Linear regression rect',
      data: rect,
      backgroundColor: '#fcc'
    }, {
      label: 'Quadratic regression curve',
      data: curve,
      backgroundColor: '#cfc'
    }, {
      label: 'Grade 6 regression curve',
      data: gradeSixCurve,
      backgroundColor: '#ccf'
    }]
  },
  options: {
    responsive: true
  }
});