Detalhes do pacote

ml-ransac

mljs764MIT1.0.0

Fit a model to noisy data by excluding outliers. This is an implementation of the RANSAC algorithm.

readme (leia-me)

ml-ransac

NPM version build status Test coverage npm download

Fit a model to noisy data by excluding outliers. This is an implementation of the RANSAC algorithm..

Installation

$ npm i ml-ransac

Examples

Finding the best linear regression which doesn't take the outliers into account:

import { levenbergMarquardt } from 'ml-levenberg-marquardt'; // library allowing you to find a regression of any type
import { ransac } from 'ml-ransac';

// defining the model function: a line
export type LineFunction = (x: number) => number;

export function line([a, b]: number[]): LineFunction {
  return (x: number) => a * x + b;
}

// defining the fit function: we create a linear regression using levenberg-maquard
export interface LinearRegressionOptions {
  /**
   * Initial parameter values.
   *
   * @default [0,0]
   */
  initialValues?: number[];
}

export function linearRegression(
  source: number[],
  destination: number[],
  options: LinearRegressionOptions = {},
): number[] {
  const { initialValues = [0, 0] } = options;
  const result = levenbergMarquardt({ x: source, y: destination }, line, {
    initialValues,
  });

  return result.parameterValues;
}

// data
const source = [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const destination = [-6, -2, 0, 5, 0, 0, -1, 1, 0, 0, -1, 0, 3];

// finding the best model
const result = ransac(source, destination, {
  distanceFunction,
  fitFunction,
  modelFunction,
  threshold: 1.1,
  sampleSize: 2,
  maxNbIterations: 10,
  seed: 0,
});

// result is :
//   {
//     nbIterations: 10,
//     modelParameters: [0, 0],
//     inliers: [2, 4, 5, 6, 7, 8, 9, 10, 11],
//     error: 1,
//   }

License

MIT

changelog (log de mudanças)

Changelog

1.0.0 (2023-06-08)

Features

  • geometry: implement getIntersectionPoint (47dd14a)
  • geometry: implement getPointLineDistance (3973f9a)
  • geometry: implement getPointLineDistance (9f56d17)
  • implement affineFitFunction (c13ec57)
  • implement applyRigidTransform (76fa878)
  • implement applyRigidTransform (2723906)
  • implement drawResults (0ef1c7f)
  • implement getAffineTransform (347ff38)
  • implement getCentroid (ee40d8b)
  • implement getEuclidianDistance (d9cca23)
  • implement getMatrixFromPoints (9d19b2f)
  • implement getNbIterations (859e5cb)
  • implement getPerpendicularLine (c5a7e3c)
  • implement getPointsFromMatrix (ce47616)
  • implement getRigidTransform (7467bbf)
  • implement getTranslation (18688a6)
  • implement linear regression (e1013ce)
  • implement mad (b3f705b)
  • implement probability option (057a735)
  • implement RansacOptiosn (e96f2ac)
  • implement RansacOutput (b700d50)
  • implement scale (1a45a56)
  • implement translatePoints.ts (5ffd289)
  • refactor getCentroid (39de6ec)

Bug Fixes

  • add error property to RansacOutput (3e6b441)
  • add seed option (8fbdabe)
  • bug with angle in degrees (fb3da82)
  • debugging ransac (23912b3)
  • drawResults works (840d880)
  • enhance ransac options (49c7981)
  • getMatrixFromPoints result had wrong dimension (5e10d9e)
  • getMatrixFromPoints: bug in loop (c29a82e)
  • getRigidTransform: all tests are passing (3cbc088)
  • getRigidTransform: bug with translated vectors (a091277)
  • linearRegression works (9ecb0ac)
  • modify rigidTransform functions to match ransac (ce8a8d5)
  • ransac works with 2D points (471f671)
  • seed issue (8039ab8)
  • working on ransac options (8b2f8ef)

Documentation

  • add linear regression example (209fd66)
  • fix readme links (5804715)
  • transformation between 2D points (e10176c)