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

exponential-regression

v1.0.2

Published

Super fast non-iterative exponential regression with constant term (t => a + b * exp(c * t)) with no dependency

Downloads

326

Readme

Exponential regression

This library provides a fast and simple non-iterative way to make exponential regressions.

It also supports a non-zero constant term, that is every function of the form:

t => a + b * exp(c * t)
// (a, b, c) ϵ ℝ³

It accepts various form of input for the points, that is:

  • solve([x0, x1, ..], [y0, y1, ..])
  • sovle([[t0, y0], [t1, y1], ..])
  • solve(origin, period, [y0, y1, ..])

The fastest being the first one.

Small example:

// import
const ExpReg = require('exponential-regression').ExpReg;

// create dataset (5 values)
const a = 1, b = 2, c = -0.5;
const exp = t => a + b * Math.exp(c * t);
const t = [0, 1, 2, 3, 4];
const y = t.map(exp);

// make regression
const solved = ExpReg.solve(t, y);

// output result
console.log(solved);
/*
 * { a: 0.9827848677867319,
 *   b: 2.014213829585767,
 *   c: -0.4898373248074215 }
 */

Install

The easiest way to install this is using npm

npm i --save exponential-regression

How to use

Here are the available methods to get the approximation of (a, b, c):

type RegressionResult {a: number; b: number; c: number;}

RegExp.solve(xk: number[], yk: number[]): RegressionResult
RegExp.solve(xyk: number[][]): RegressionResult
RegExp.solve(origin: number, period: number, yk: number[]): RegressionResult

Test

Automatic tests

Tests are made with mocha. To run them, use

npm run test

Automatic tests ensure the relative error is less than a certain percentage for every test sample. Test samples are in test/samples.ts.

Manual tests

You can store the csv file corresponding to the test samples using

npm run test-manual $STORE_PATH

$STORE_PATH is the path where you would like to store the csv file.

Benchmark

Benchmark between different input forms have been done using these values

const A: number = 0.3;
const B: number = 0.6;
const C: number = - 1.7;
const XMIN: number = 0;
const XMAX: number = 20;
const N: number = 1000000; // number of points
function                                                    ms
solve(xk: number[], yk: number[]) [optimized]               21 ms
solve(o: number, t: number, yk: number[]) [optimized]       55 ms
solve(points: number[][]) [optimized]                       30 ms

To run the benchmark, use

npm run bench

Credits

Credits to Jean Jacquelin for his paper REGRESSION & FULL EQUATIONS