Git Product home page Git Product logo

norm.js's Introduction

norm.js

Build Status Coverage Status npm version

A small collection of methods for array and object normalization, standardization, and simple statistics.

Usage

$ npm install norm.js

To use norm.js in Node.js, simply require it:

var n = require("norm.js");

A minified, browserified file dist/norm.min.js is included for use in the browser. Including this file attaches a normjs object to window:

<script src="dist/norm.min.js" type="text/javascript"></script>

All of norm.js's methods accept both arrays and objects as inputs. If an object is used, then calculations are done on the object's values. The adjusted (normalized) values remain associated with the same key.

n.norm calculates the norm (length) of the input array/object. It accepts an optional second argument, which specifies the length type. This can take the following values: Euclidean, L1, max, min. If no second argument is supplied, then a simple sum is used.

n.norm([0.1, 3, 1.21, -1, 0.2], "Euclidean"); // 3.393243286297049

n.normalize divides all elements of the input array/object by a constant value (the norm). It accepts an optional second argument, the same as n.norm. If no second argument is supplied, then normalization simply divides by the sum (so that elements of the array/object will sum to 1).

n.normalize({a: 0.1, b: 0.2});
// outputs:
{
    a: 0.3333333333333333,
    b: 0.6666666666666666
}

n.standardize divides all elements of the input array/object by their standard deviation. It accepts an optional second argument, which specifies whether Bessel's correction is used; this should be set to true if the inputs are sample values. (If left blank, elements are assumed to be population values.)

n.standardize({a: 0.1, b: 3, c: 1.21, d: -1, e: 0.2}, true);
// outputs:
{
    a: 0.06648195568920466,
    b: 1.9944586706761396,
    c: 0.8044316638393763,
    d: -0.6648195568920465,
    e: 0.13296391137840932
}

norm.js also includes n.variance, n.std, n.rescale, n.mean, and n.sum methods. Examples (and function signatures, etc.) can be found in test/norm.js.

Tests

Unit tests are included in test/, and can be run using npm:

$ npm test

norm.js's People

Contributors

tinybike avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.