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

gencov

v0.0.1

Published

generate random covariance matrices, and MVN samples using them.

Downloads

12

Readme

gencov

Build Status NPM version NPM download

Generate random covariance matrices, and draw MVN samples using them.

Covariance matrix:

The genS and genArray functions produce random covariance matrices (as ndarray or javascript array) with a specified variance structure. The eigenvalues (principal component variances) V for the covariance matrix may be specified, or may be randomly generated from within a specified range. A random orthogonal matrix Q is generated and its columns used as eigenvectors. The covariance matrix is then generated as S = Q V Q~

Sampling:

Given a covariance ndarray S, you can generate samples from the associated multivariate normal distribution using the mvnrnd function (which creates a function that draws samples from N(mean, S))

Samples x ~ N(0, S) are drawn by first drawing z ~ N(0, I) then transforming x = L z, where S = L L~.

Example usage:

var gencov = require('gencov');

// generate a 3-d correlation matrix with variances between 1 and 10,
// and return it as an ndarray:

var S = gencov.genS(3);

// generate a 5-d correlation matrix with principal components,
// return as a regular array

var S = gencov.genArray([3, 2, 1, 0.5, 0.1]);

// draw 10 3d samples from a N([a,b,c], S) distribution with random S,
// return as an array of 3-vectors.

var X = Array.apply(null, 10).map(mvnrnd([a,b,c], genS(3)))

dependencies

ndarray: https://www.npmjs.com/package/ndarray ndarray-blas-level1: https://www.npmjs.com/package/ndarray-blas-level1 ndarray-blas-level2: https://www.npmjs.com/package/ndarray-blas-level2 ndarray-blas-dger: https://www.npmjs.com/package/ndarray-blas-dger ndarray-unpack: https://www.npmjs.com/package/ndarray-unpack ndarray-gram-schmidt-qr: https://www.npmjs.com/package/ndarray-gram-schmidt-qr ndarray-cholesky-factorization: https://www.npmjs.com/package/ndarray-cholesky-factorization