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

ransac

v0.0.2

Published

Implementation of random sample consensus (RANSAC), which can be used to fit a model for your data

Downloads

3

Readme

RANSAC

Implementation of random sample consensus (RANSAC), which can be used to fit a model for your data

Install

On Node.JS:

$ npm install --save ransac

On the browser:

$ bower install --save ransac

Usage

Create two objects, one for the problem definition and another for options. For instance, take the 2D line fitting problem:

var problem = {
    // Your model, is how you compute your parameters or
    // variable you want to find. Here there are m and b
    model: function(sample) {
        var p1 = sample[0];
        var p2 = sample[1];
        // You should validate p2.x != p1.x
        var m = (p2.y - p1.y) / (p2.x - p1.x);
        var b = p1.y - m * p1.x;
        return {
            m: m,
            b: b
        }
    },
    // Given model values, return a number indicate if you
    // accept the point as inlier
    fit: function(model, point) {
        var y_estimated = model.m * point.x + model.b;
        var error = point.y - y_estimated;
        return Math.abs(error);
    },

    data: data
};

var options = {
    sampleSize: 2,      // We only need 2 points to compute m and b
    threshold: 2.5,     // Used to determine if error is good enough
    maxIterations: 30,  // Number of times RANSAC will try a model
    inliersRatio: 0.7,  // To accept a model, atl least 70% of points must fit
    improveModelWithConcensusSet: false // If model function supports more than sampleSize points, set this true to improve accepted models
};

The format for data is an Array of what you prefer. We will rely on your fit function, which should be able to read such format. So, in the sample, format is:

// THIS IS FOR THE 2D LINE EXAMPLE!!!! The format depends on your problem
var data = [{
    x: 0,
    y: 0.2
}, {
	x: 2,
	y: 1.9
}, {
	x: 2.1,
	y: 1.85
}];

Then, create your object and estime a model:

// This is only required in Node. In Browser we use window.Ransac
var Ransac = require('ransac');

var ransacProblem = new Ransac(problem);
var solution = ransacProblem.estimate(options);

Solution will include the following:

{
    inliers: inliers,
    outliers: outliers,
    model: bestModelFound,
    error: accumulatedError,
    status: 'Success'
};

Inliers and outliers are both arrays, with the elements classified accordingly.

The best model found is also dependent on your format (problem model function). Error, at this moment we use sum of squared differences, for each of your data points, where each data point uses your fit function.

When no model is found, status may contain 'Failed' string.

License

MIT © Manlio Barajas

Travis build status Code Climate Test Coverage Dependency Status devDependency Status