Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
gaussianMixture
Advanced tools
An implementation of a Gaussian Mixture class in one dimension, that allows to fit models with an Expectation Maximization algorithm.
This module implements a 1D Gaussian Mixture class that allows to fit a distribution of points along a one-dimensional axis.
npm install gaussianMixture
var GMM = require('gaussianMixture');
Instantiate a new GMM.
Parameters
nComponents
Number number of components in the mixtureweights
Array array of weights for each component in the mixture, must sum to 1means
Array array of means for each componentvars
Array array of variances of each componentoptions
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]);
Randomly sample from the GMM's distribution.
Parameters
nSamples
Number desired number of samplesReturns Array An array of randomly sampled numbers that follow the GMM's distribution
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 modelReturns Array (data.length * this.nComponents) matrix with membership weights
Given a datapoint, determine its memberships for each component of the GMM.
Parameters
x
Number number representing the sample to score under the modelReturns Array an array of length this.nComponents with membership weights, i.e the probabilities that this datapoint was drawn from the each component
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 modelCompute 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 modelReturns Number the log-likelihood
Compute the optimal GMM components given an array of data.
Parameters
data
Array array of numbers representing the samples to use to optimize the modelmaxIterations
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
Return the model for the GMM as a raw JavaScript Object.
Returns Object the model, with keys nComponents
, weights
, means
, vars
.
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
FAQs
An implementation of a Gaussian Mixture class in one dimension, that allows to fit models with an Expectation Maximization algorithm.
The npm package gaussianMixture receives a total of 2 weekly downloads. As such, gaussianMixture popularity was classified as not popular.
We found that gaussianMixture demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.