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 - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

test/barycenter.test.js

15

index.js

@@ -5,2 +5,3 @@ 'use strict';

var gaussian = require('gaussian');
var barycenter = require('./utilities/barycenter');
var _ = require('underscore');

@@ -88,2 +89,3 @@

var memberships = this.memberships(data);
var alpha;

@@ -106,2 +108,13 @@ // Update the mixture weights

}
// If there is a separation prior:
if (this.options.separationPrior && this.options.priorRelevance) {
var separationPrior = this.options.separationPrior;
var priorMeans = _.range(this.nComponents).map(function (a) { return (a * separationPrior); });
var priorCenter = barycenter(priorMeans, this.weights);
var center = barycenter(this.means, this.weights);
for (k = 0; k < this.nComponents; k++) {
alpha = this.weights[k] / (this.weights[k] + this.options.priorRelevance);
this.means[k] = center + alpha * (this.means[k] - center) + (1 - alpha) * (priorMeans[k] - priorCenter);
}
}

@@ -117,3 +130,3 @@ // Update the mixture variances

if (this.options.variancePrior && this.options.priorRelevance) {
var alpha = this.weights[k] / (this.weights[k] + this.options.priorRelevance);
alpha = this.weights[k] / (this.weights[k] + this.options.priorRelevance);
this.vars[k] = alpha * this.vars[k] + (1 - alpha) * this.options.variancePrior;

@@ -120,0 +133,0 @@ }

2

package.json
{
"name": "gaussianMixture",
"version": "0.2.0",
"version": "0.3.0",
"description": "An implementation of a Gaussian Mixture class in one dimension, that allows to fit models with an Expectation Maximization algorithm.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,2 +31,3 @@ # Gaussian Mixture

variancePrior: // Float,
separationPrior: // Float,
priorRelevance: // Positive float.

@@ -40,2 +41,4 @@ };

Similarly, the separation prior allows you to define a prior for the difference between consecutive gaussian mixture means. This prior is mixed with the sale `options.priorRelevance` score.
The mixing weight `alpha` for component `i` is `alpha = weights[i] / (weights[i] + options.priorRelevance)`.

@@ -133,1 +133,29 @@ 'use strict';

});
test('Separation prior', function (t) {
t.plan(3);
var options = {
separationPrior: 3,
priorRelevance: 0.01
};
var options2 = {
separationPrior: 3,
priorRelevance: 1
};
var options3 = {
separationPrior: 3,
priorRelevance: 1000000
};
var gmm = new GMM(3, undefined, [-1, 13, 25], [1, 1, 1], options);
var gmm2 = new GMM(3, undefined, [-1, 13, 25], [1, 1, 1], options2);
var gmm3 = new GMM(3, undefined, [-1, 13, 25], [1, 1, 1], options3);
gmm.optimize(data);
gmm2.optimize(data);
gmm3.optimize(data);
var cropFloat = function (a) { return Number(a.toFixed(1)); };
t.same(gmm.means.map(cropFloat), [0.7, 10.2, 29.8]);
t.same(gmm2.means.map(cropFloat), [11.6, 13.5, 17.8]);
t.same(gmm3.means.map(cropFloat), [11.4, 14.4, 17.4]);
});
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