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

@chaos-labs/multivariate-normal

v0.1.4

Published

Port of NumPy's random.multivariate_normal to Node.JS

Downloads

9

Readme

multivariate-normal-js

TypeScript definitions on DefinitelyTyped

A pure-javascript port of NumPy's random.multivariate_normal, for Node.js and the browser.

Check out the live demo!

From the NumPy docs:

Draw random samples from a multivariate normal distribution.

The multivariate normal, multinormal or Gaussian distribution is a generalization of the one-dimensional normal distribution to higher dimensions. Such a distribution is specified by its mean and covariance matrix. These parameters are analogous to the mean (average or "center") and variance (standard deviation, or "width," squared) of the one-dimensional normal distribution.

See the NumPy documentation additional notes, examples, and references.

Example

To start, just npm install multivariate-normal. You can also get one of the pre-built files from the dist folder.

Then you can do:

    const MultivariateNormal = require("multivariate-normal");
    // or without ES6 import: var MultivariateNormal = require("multivariate-normal").default;
    // or without a CommonJS runtime: <script src="path/to/multivariate-normal.min.js"></script>, and then use the global window.MultivariateNormal.default

    // means of our three dimensions
    var meanVector = [1, 2, 3];

    // covariance between dimensions. This examples makes the first and third
    // dimensions highly correlated, and the second dimension independent.
    var covarianceMatrix = [
        [ 1.0, 0.0, 0.9 ],
        [ 0.0, 1.0, 0.0 ],
        [ 0.9, 0.0, 1.0 ],
    ];

    var distribution = MultivariateNormal(meanVector, covarianceMatrix);
    distribution.sample(); // => [1.2, 1.8, 3.3]

    var newDistribution = distribution.setMean([3, 2, 1]);
    newDistribution.sample(); // => [2.8, 2.1, 0.7]

    // distributions are immutable
    distribution.getMean(); // => [1, 2, 3];
    newDistribution.getMean(); // => [3, 2, 1];

Typescript

Install @types/multivariate-normal for the Typescript definitions to go along with this package.

API

MultivariateNormal(mean, covarianceMatrix) -> Distribution

Arguments:

  • mean 1-D Array, of length N: Mean of the N-dimensional distribution.
  • cov 2-D Array, of shape (N, N): Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.

Returns:

  • A Distribution object with methods described below. Distributions are immutable -- the set methods return new distributions.
distribution.sample() -> Array

Draw a random sample from the distribution.

Returns:

  • 1-D Array, of length N: The random sample from the distribution.
distribution.getMean(newMean) -> Array

Returns the mean of this distribution. The array will be frozen.

Returns:

  • 1-D Array, of length N: Mean of the distribution.
distribution.setMean(newMean) -> Distribution

Returns a new Distribution with the same covariance matrix as the current distribution, but a new mean.

Arguments:

  • newMean 1-D Array, of length N: Mean of the new distribution.

Returns:

  • A new Distribution object.
distribution.getCov(newMean) -> Array

Returns the covariance of this distribution. The array will be frozen.

Returns:

  • 2-D Array, of shape (N, N): Covariance matrix of the distribution.
distribution.setCov(newMean) -> Distribution

Returns a new Distribution with the same mean as the current distribution, but a new covariance matrix.

Arguments:

  • newMean 2-D Array, of shape (N, N): Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.

Returns:

  • A new Distribution object.

Get Involved

If you've found a bug or have a feature request, file an issue on Github.

To get started developing:

  1. Clone this repo.
  2. npm install

Then, you can run the tests with npm test, or run the example app with npm start and then navigating to http://localhost:8080.

Contributing

How to submit changes:

  1. Fork this repository.
  2. Make your changes, including adding or changing appropriate tests.
  3. Verify unit tests and linting passes with npm test
  4. Play around with the example app. Make sure the correlations look correct.
  5. Email us as [email protected] to sign a CLA.
  6. Submit a pull request.

Coding Conventions

License

multivariate-normal-js is licensed under the Apache Public License.

Who's Behind It

Multivariate Normal is maintained by Tulip. We're an MIT startup located in Boston, helping enterprises manage, understand, and improve their manufacturing operations. We bring our customers modern web-native user experiences to the challenging world of manufacturing, currently dominated by ancient enterprise IT technology. We work on Meteor web apps, embedded software, computer vision, and anything else we can use to introduce digital transformation to the world of manufacturing. If these sound like interesting problems to you, we should talk.