Coder Social home page Coder Social logo

unofficialjuliamirror / dirichletprocessmixtures.jl-45408861-6e75-55ae-b01d-c0d3f903bc50 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 23 KB

Last mirrored from https://github.com/sbos/DirichletProcessMixtures.jl.git on 2019-10-07T21:47:15.09-04:00 by @UnofficialJuliaMirrorBot via Travis job 475.9 , triggered by Travis cron job on branch "master"

License: Other

Julia 100.00%

dirichletprocessmixtures.jl-45408861-6e75-55ae-b01d-c0d3f903bc50's Introduction

Build Status DirichletProcessMixtures

DirichletProcessMixtures.jl

This package implements Dirichlet Process Mixture Models in Julia using variational inference for truncated stick-breaking representation of Dirichlet Process.

(almost) infinite mixture of Gaussians

Most likely you need this package especially for this purpose, this is how to do Gaussian clustering. You may check demo code which contains almost all functionality you may need.

First off, you define your prior over parameters of mixture component (i.e. mean and precision matrix) using NormalWishart distribution:

using DirichletProcessMixtures
using Distributions

prior = NormalWishart(zeros(2), 1e-7, eye(2) / 4, 4.0001)

Then you generate your mixture

x = ... # your data, x[:, i] - is i-th data point
T = 20 # truncation level
alpha = 0.1 # Dirichlet process parameter, controls how many clusters you need a priori
gm, theta, predictive_likelihood = gaussian_mixture(prior, T, alpha, x)

gm is an internal representation of mixture model. theta is array of size T whose elements refer to parameters of posterior NormalWishart's. Finally, predictive_likelihood is a function which takes a matrix containing test data and returns per-point test loglikelihood. Now we can perform inference in our model

function iter_callback(mix::TSBPMM, iter::Int64, lower_bound::Float64)
    pl = sum(predictive_likelihood(xtest)) / M
    println("iteration $iter test likelihood=$pl, lower_bound=$lower_bound")
end

maxiter = 200
ltol = 1e-5
niter = infer(gm, maxiter, ltol; iter_callback=iter_callback)

You may see that infer method performs not more than maxiter iterations until lower bound tolerance reaches ltol value, calling iter_callback at each iteration if provided.

Another useful quantities you may need from mixture model:

  • gm.z - TxN array with expected mixture component assignments
  • gm.qv - posterior Beta distributions for stick-breaking proportions

General interface

It is also possible to implement custom mixture models with conjugate priors for mixture components, but this remains to be documented yet. For a reference implementation of custom mixture model use mixture of Gaussians.

dirichletprocessmixtures.jl-45408861-6e75-55ae-b01d-c0d3f903bc50's People

Contributors

sbos avatar hassaku avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.