bayesian-changepoint
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Bayesian Online ChangePoint JS Detection

Edit BayesianChangePointJS

Pure JavaScript/TypeScript implementation of Bayesian Online Changepoint detection which runs for Browsers & NodeJS.

Example

import assert from "assert";
import BayesianChangePoint, { BreakPoint } from "bayesian-changepoint";
 
const breakpointVerifier = (
  nextBreakPoint<number>,
  prevBreakPoint<number>
)boolean => {
  if (Math.abs(next.data - prev.data) >= 5) {
    return true;
  }
 
  return false;
};
 
const values = (breakPoints: BreakPoint<number>[]): number[] => {
  return breakPoints.map(breakPoint => breakPoint.data);
};
 
const indicies = (breakPoints: BreakPoint<number>[]): number[] => {
  return breakPoints.map(breakPoint => breakPoint.index);
};
 
const detection = new BayesianChangePoint<number>({
  breakpointVerifier 
});
 
detection.exec([10, 10, 10, 10, 5000, 5000, 5000, 5000, 30, 30, 30, 30, 30]);
 
assert.deepEqual(values(detection.breakPoints()), [5000, 30]);
assert.deepEqual(indicies(detection.breakPoints()), [4, 8]);

Installation

npm install
npm test

Credits

Based off of Bayesian Online Changepoint

Package Sidebar

Install

npm i bayesian-changepoint

Weekly Downloads

677

Version

1.0.1

License

MIT

Unpacked Size

12.2 kB

Total Files

8

Last publish

Collaborators

  • mathew-kurian