Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gaussianMixture

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gaussianMixture

An implementation of a Gaussian Mixture class in one dimension, that allows to fit models with an Expectation Maximization algorithm.

  • 0.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Gaussian Mixture

Build Status

This module implements a 1D Gaussian Mixture class that allows to fit a distribution of points along a one-dimensional axis.

image

Install

npm install gaussianMixture

Require

var GMM = require('gaussianMixture');

GMM

Instantiate a new GMM.

Parameters

  • nComponents Number number of components in the mixture
  • weights Array array of weights for each component in the mixture, must sum to 1
  • means Array array of means for each component
  • vars Array array of variances of each component
  • options Object an object that can define the variancePrior, separationPrior, variancePriorRelevance and separationPriorRelevance. The priors are taken into account when the GMM is optimized given some data. The relevance parameters should be non-negative numbers, 1 meaning that the prior has equal weight as the result of the optimal GMM in each EM step, 0 meaning no influence, and Infinity means a fixed variance (resp. separation).

Examples

var gmm = new GMM(3, [0.3, 0.2, 0.5], [1, 2, 3], [1, 1, 0.5]);

sample

Randomly sample from the GMM's distribution.

Parameters

  • nSamples Number desired number of samples

Returns Array An array of randomly sampled numbers that follow the GMM's distribution

memberships

Given an array of data, determine their memberships for each component of the GMM.

Parameters

  • data Array array of numbers representing the samples to score under the model

Returns Array (data.length * this.nComponents) matrix with membership weights

membership

Given a datapoint, determine its memberships for each component of the GMM.

Parameters

  • x Number number representing the sample to score under the model

Returns Array an array of length this.nComponents with membership weights, i.e the probabilities that this datapoint was drawn from the each component

updateModel

Perform one expectation-maximization step and update the GMM weights, means and variances in place. Optionally, if options.variancePrior and options.priorRelevance are defined, mix in the prior.

Parameters

  • data Array array of numbers representing the samples to use to update the model

logLikelihood

Compute the log-likelihood for the GMM given an array of data.

Parameters

  • data Array array of numbers representing the samples to use to update the model

Returns Number the log-likelihood

optimize

Compute the optimal GMM components given an array of data.

Parameters

  • data Array array of numbers representing the samples to use to optimize the model
  • maxIterations Number? maximum number of expectation-maximization steps (optional, default 200)
  • logLikelihoodTol Number? tolerance for the log-likelihood to determine if we reached the optimum (optional, default 0.0000001)

Examples

var gmm = new GMM(3, undefined, [1, 5, 10]);
var data = [1.2, 1.3, 7.4, 1.4, 14.3, 15.3, 1.0, 7.2];
gmm.optimize(data); // updates weights, means and variances with the EM algorithm given the data.
console.log(gmm.means); // >> [1.225, 7.3, 14.8]

Returns Number the number of steps to reach the converged solution

model

Return the model for the GMM as a raw JavaScript Object.

Returns Object the model, with keys nComponents, weights, means, vars.

fromModel

Instantiate a GMM from an Object model and options.

Parameters

  • model
  • options

Examples

var gmm = GMM.fromModel({
nComponents: 3,
weights: [0.3, 0.2, 0.5],
means: [1, 2, 3],
vars: [1, 1, 0.5]
});

Returns GMM the GMM corresponding to the given model

Keywords

FAQs

Package last updated on 31 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc