@mapbox/trajectory-mixture
An implementation of a Gaussian Mixture class in one dimension, that allows to fit models with an Expectation Maximization algorithm.
Last updated 3 years ago by uvollmer .
UNLICENSED · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mapbox/trajectory-mixture 
SYNC missed versions from official npm registry.

Gaussian Mixture

Build Status

This module is a fork of gaussian-mixture which is adapted to the trajectory-map needs.

image

Install

npm install trajectory-mixture

Require

var GMM = require('trajectory-mixture');

Table of Contents

TrajectoryGMM

Instantiate a new Trajectory mixture model.

Parameters

  • nLaneComponents Number number of lane components in the mixture
  • nNoiseComponents Number number of noise invariant components in the mixture
  • 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 TrajectoryGMM(3, 2, {noiseMeans: [1, 3], noiseVars: [1.2, 0.8]});

Returns TrajectoryGMM a gmm object

allMeans

Return a concatenated array of lane and noise means.

Returns Array an array of gaussian means.

allVars

Return a concatenated array of lane and noise variances.

Returns Array an array of gaussian variances.

laneWeights

Return an array of the lane components' weights in the overall model.

Returns Array an array of lane gaussian weights.

normalizedLaneWeights

Return an array of normalized lane components' weights.

Returns Array an array of lane gaussian weights.

noiseWeights

Return an array of the noise components' weights in the overall model.

Returns Array an array of noise gaussian weights.

normalizedNoiseWeights

Return an array of normalized noise components' weights.

Returns Array an array of noise gaussian weights.

sample

Randomly sample from a set of distribution.

Parameters

  • nSamples Number desired number of samples
  • gaussians
  • weights

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

laneSample

Randomly sample from the lane distribution.

Parameters

  • nSamples Number desired number of samples

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

noiseSample

Randomly sample from the noise distribution.

Parameters

  • nSamples Number desired number of samples

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

memberships

Given an array of data, determine their memberships for each given gaussian.

Parameters

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

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

laneMemberships

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

Parameters

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

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

noiseMemberships

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

Parameters

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

Returns Array (data.length * this.nNoiseComponents) 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
  • gaussians Array (optional) an Array of length nComponents that contains the gaussians for the GMM

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

laneMembership

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

Parameters

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

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

noiseMembership

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

Parameters

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

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

logLikelihood

Compute the log-likelihood for the GMM given data.

Parameters

Returns Number the log-likelihood

laneLogLikelihood

Compute the log-likelihood for the GMM given data.

Parameters

Returns Number the log-likelihood

optimize

Compute the optimal GMM components given an array of data. If options has a true flag for initialize, the optimization will begin with a K-means++ initialization. This allows to have a data-dependent initialization and should converge quicker and to a better model. The initialization is agnostic to the other priors that the options might contain.

Parameters

  • data (Array | Histogram) the data array or histogram
  • 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)

Returns Number the number of steps to reach the converged solution

allModel

Return the lane + noise model for the GMM as a raw JavaScript Object.

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

laneModel

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

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

noiseModel

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

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

fromModel

Instantiate a TrajectoryGMM from models and options.

Parameters

  • nLaneComponents Number number of lane components
  • nNoiseComponents Number number of noise components
  • model Object the model, with keys nComponents, weights, means, vars
  • options Object options for the GMM such as priors

Returns GMM the GMM corresponding to the given model

Histogram

Instantiate a new Histogram.

Parameters

  • h Object an object with keys 'counts' and 'bins'. Both are optional. An observation x will be counted for the key i if bins[i][0] <= x < bins[i][1]. If bins are not specified, the bins will be corresponding to one unit in the scale of the data. The keys of the 'counts' hash will be stringified integers. (optional, default {})

Examples

var h = new Histogram({counts: {'a': 3, 'b': 2, 'c': 5}, bins: {'a': [0, 2], 'b': [2, 4], 'c': [4, 7]}});
var h = new Histogram({counts: {'1': 3, '2': 2, '3': 5}});
var h = new Histogram();

Returns Histogram a histogram object. It has keys 'bins' (possibly null) and 'counts'.

add

Add an observation to an histogram.

Parameters

  • x Array observation to add tos the histogram

Returns Histogram the histogram with added value.

flatten

Return a data array from a histogram.

Returns Array an array of observations derived from the histogram counts.

value

Return the median value for the given key, derived from the bins.

Parameters

  • key

Returns Number the value for the provided key.

fromData

Instantiate a new Histogram.

Parameters

  • data Array array of observations to include in the histogram. Observations that do not correspond to any bin will be discarded. (optional, default [])
  • bins Object a map from key to range (a range being an array of two elements) An observation x will be counted for the key i if bins[i][0] <= x < bins[i][1]. If not specified, the bins will be corresponding to one unit in the scale of the data. (optional, default {})

Examples

var h = Histogram.fromData([1, 2, 2, 2, 5, 5], {A: [0, 1], B: [1, 5], C: [5, 10]});
// {bins: {A: [0, 1], B: [1, 5], C: [5, 10]}, counts: {A: 0, B: 4, C: 2}}
var h = Histogram.fromData([1, 2, 2, 2, 2.4, 2.5, 5, 5]);
// {counts: {'1': 1, '2': 4, '3': 1, '5': 2}}

Returns Histogram a histogram object It has keys 'bins' (possibly null) and 'counts'.

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |