# 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 where is the probability density function of the mixed exponential family distribution and are the parameters of each cluster. For instance, could be the Gaussian probability density function and where and are the mean vector and precision matrix for cluster .

Parameters: z : categorical-like node or array , 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]

Initialize self. See help(type(self)) for accurate signature.

Methods

 __init__(z, node_class, *params[, cluster_plate]) Initialize self. add_plate_axis(to_plate) broadcasting_multiplier(*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