bayespy.nodes.Mixture

class bayespy.nodes.Mixture(z, node_class, *params, cluster_plate=-1, **kwargs)[source]

Node for exponential family mixture variables.

The node represents a random variable which is sampled from a mixture distribution. It is possible to mix any exponential family distribution. The probability density function is

p(x|z=k,\boldsymbol{\theta}_0,\ldots,\boldsymbol{\theta}_{K-1})
= \phi(x|\boldsymbol{\theta}_k),

where \phi is the probability density function of the mixed exponential family distribution and \boldsymbol{\theta}_0,
\ldots, \boldsymbol{\theta}_{K-1} are the parameters of each cluster. For instance, \phi could be the Gaussian probability density function \mathcal{N} and \boldsymbol{\theta}_k = \{\boldsymbol{\mu}_k,
\mathbf{\Lambda}_k\} where \boldsymbol{\mu}_k and \mathbf{\Lambda}_k are the mean vector and precision matrix for cluster k.

Parameters:
  • z (categorical-like node or array) – z, cluster assignment

  • node_class (stochastic exponential family node class) – Mixed distribution

  • params (types specified by the mixed distribution) – Parameters of the mixed distribution. If some parameters should vary between clusters, those parameters’ plate axis cluster_plate should have a size which equals the number of clusters. For parameters with shared values, that plate axis should have length 1. At least one parameter should vary between clusters.

  • cluster_plate (int, optional) – Negative integer defining which plate axis is used for the clusters in the parameters. That plate axis is ignored from the parameters when considering the plates for this node. By default, mix over the last plate axis.

Examples

A simple 2-dimensional Gaussian mixture model with three clusters for 100 samples can be constructed, for instance, as:

>>> import numpy as np
>>> from bayespy.nodes import (Dirichlet, Categorical, Mixture,
...                            Gaussian, Wishart)
>>> alpha = Dirichlet([1e-3, 1e-3, 1e-3])
>>> Z = Categorical(alpha, plates=(100,))
>>> mu = Gaussian(np.zeros(2), 1e-6*np.identity(2), plates=(3,))
>>> Lambda = Wishart(2, 1e-6*np.identity(2), plates=(3,))
>>> X = Mixture(Z, Gaussian, mu, Lambda)
__init__(z, node_class, *params, cluster_plate=-1, **kwargs)[source]

Methods

__init__(z, node_class, *params[, cluster_plate])

add_plate_axis(to_plate)

broadcasting_multiplier(plates, *args)

delete()

Delete this node and the children

get_gradient(rg)

Computes gradient with respect to the natural parameters.

get_mask()

get_moments()

get_parameters()

Return parameters of the VB distribution.

get_pdf_nodes()

get_riemannian_gradient()

Computes the Riemannian/natural gradient.

get_shape(ind)

has_plotter()

Return True if the node has a plotter

initialize_from_parameters(*args)

initialize_from_prior()

initialize_from_random()

Set the variable to a random sample from the current distribution.

initialize_from_value(x, *args)

integrated_logpdf_from_parents(x, index)

Approximates the posterior predictive pdf int p(x|parents) q(parents) dparents in log-scale as int q(parents_i) exp( int q(parents_i) log p(x|parents) dparents_i ) dparents_i.

load(filename)

logpdf(X[, mask])

Compute the log probability density function Q(X) of this node.

lower_bound_contribution([gradient, ...])

Compute E[ log p(X|parents) - log q(X) ]

lowerbound()

move_plates(from_plate, to_plate)

observe(x, *args[, mask])

Fix moments, compute f and propagate mask.

pdf(X[, mask])

Compute the probability density function of this node.

plot([fig])

Plot the node distribution using the plotter of the node

random()

Draw a random sample from the distribution.

save(filename)

set_parameters(x)

Set the parameters of the VB distribution.

set_plotter(plotter)

show()

Print the distribution using standard parameterization.

unobserve()

update([annealing])

Attributes

dims

plates

plates_multiplier

Plate multiplier is applied to messages to parents