ot.gmm — POT Python Optimal Transport 0.9.6 documentation
Optimal transport for Gaussian Mixtures
Functions
- ot.gmm.dist_bures_squared(m_s, m_t, C_s, C_t)[source]
Compute the matrix of the squared Bures distances between the components of two Gaussian Mixture Models (GMMs). Used to compute the GMM Optimal Transport distance [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
- Returns:
dist – Matrix of squared Bures distances between the components of the source and target GMMs.
- Return type:
array-like, shape (k_s, k_t)
References
- ot.gmm.gaussian_logpdf(x, m, C)[source]
Compute the log of the probability density function of a multivariate Gaussian distribution.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (d,)) – The mean vector of the Gaussian distribution.
C (array-like, shape (d, d)) – The covariance matrix of the Gaussian distribution.
- Returns:
pdf – The probability density function evaluated at each sample.
- Return type:
array-like, shape (…,)
- ot.gmm.gaussian_pdf(x, m, C)[source]
Compute the probability density function of a multivariate Gaussian distribution.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (d,)) – The mean vector of the Gaussian distribution.
C (array-like, shape (d, d)) – The covariance matrix of the Gaussian distribution.
- Returns:
pdf – The probability density function evaluated at each sample.
- Return type:
array-like, shape (…,)
- ot.gmm.gmm_barycenter_fixed_point(means_list, covs_list, w_list, means_init, covs_init, weights, w_bar=None, iterations=100, log=False, barycentric_proj_method='euclidean')[source]
Solves the Gaussian Mixture Model OT barycenter problem (defined in [69]) using the fixed point algorithm (proposed in [77]). The weights of the barycenter are not optimized, and stay the same as the input w_list or are initialized to uniform.
The algorithm uses barycentric projections of GMM-OT plans, and these can be computed either through Bures Barycenters (slow but accurate, barycentric_proj_method=’bures’) or by convex combination (fast, barycentric_proj_method=’euclidean’, default).
This is a special case of the generic free-support barycenter solver ot.lp.free_support_barycenter_generic_costs.
- Parameters:
means_list (list of array-like) – List of K (m_k, d) GMM means.
covs_list (list of array-like) – List of K (m_k, d, d) GMM covariances.
w_list (list of array-like) – List of K (m_k) arrays of weights.
means_init (array-like) – Initial (n, d) GMM means.
covs_init (array-like) – Initial (n, d, d) GMM covariances.
weights (array-like) – Array (K,) of the barycentre coefficients.
w_bar (array-like, optional) – Initial weights (n) of the barycentre GMM. If None, initialized to uniform.
iterations (int, optional) – Number of iterations (default is 100).
log (bool, optional) – Whether to return the list of iterations (default is False).
barycentric_proj_method (str, optional) – Method to project the barycentre weights: ‘euclidean’ (default) or ‘bures’.
- Returns:
means (array-like) – (n, d) barycentre GMM means.
covs (array-like) – (n, d, d) barycentre GMM covariances.
log_dict (dict, optional) – Dictionary containing the list of iterations if log is True.
References
Examples using ot.gmm.gmm_barycenter_fixed_point
- ot.gmm.gmm_ot_apply_map(x, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, method='bary', seed=None)[source]
Apply Gaussian Mixture Model (GMM) optimal transport (OT) mapping to input data. The ‘barycentric’ mapping corresponds to the barycentric projection of the GMM-OT plan, and is called T_bary in [69]. The ‘random’ mapping takes for each input point a random pair (i,j) of components of the GMMs and applied the Gaussian map, it is called T_rand in [69].
- Parameters:
x (array-like, shape (n_samples, d)) – Input data points.
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM components.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM components.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM components.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM components.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
plan (array-like, shape (k_s, k_t), optional) – Optimal transport plan between the source and target GMM components. If not provided, it will be computed internally.
method ({'bary', 'rand'}, optional) – Method for applying the GMM OT mapping. ‘bary’ uses barycentric mapping, while ‘rand’ uses random sampling. Default is ‘bary’.
seed (int, optional) – Seed for the random number generator. Only used when method=’rand’.
- Returns:
out – Output data points after applying the GMM OT mapping.
- Return type:
array-like, shape (n_samples, d)
References
Examples using ot.gmm.gmm_ot_apply_map
- ot.gmm.gmm_ot_loss(m_s, m_t, C_s, C_t, w_s, w_t, log=False)[source]
Compute the Gaussian Mixture Model (GMM) Optimal Transport distance between two GMMs introduced in [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
log (bool, optional (default=False)) – If True, returns a dictionary containing the cost and dual variables. Otherwise returns only the GMM optimal transportation cost.
- Returns:
loss (float or array-like) – The GMM-OT loss.
log (dict, optional) – If input log is true, a dictionary containing the cost and dual variables and exit status
References
Examples using ot.gmm.gmm_ot_loss
- ot.gmm.gmm_ot_plan(m_s, m_t, C_s, C_t, w_s, w_t, log=False)[source]
Compute the Gaussian Mixture Model (GMM) Optimal Transport plan between two GMMs introduced in [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
log (bool, optional (default=False)) – If True, returns a dictionary containing the cost and dual variables. Otherwise returns only the GMM optimal transportation matrix.
- Returns:
plan (array-like, shape (k_s, k_t)) – The GMM-OT plan.
log (dict, optional) – If input log is true, a dictionary containing the cost and dual variables and exit status
References
- ot.gmm.gmm_ot_plan_density(x, y, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=0.01)[source]
Compute the density of the Gaussian Mixture Model - Optimal Transport coupling between GMMS at given points, as introduced in [69]. Given two arrays of points x and y, the function computes the density at each point (x[i], y[i]) of the product space.
- Parameters:
x (array-like, shape (n, d)) – Entry points in source space for density computation.
y (array-like, shape (m, d)) – Entry points in target space for density computation.
m_s (array-like, shape (k_s, d)) – The means of the source GMM components.
m_t (array-like, shape (k_t, d)) – The means of the target GMM components.
C_s (array-like, shape (k_s, d, d)) – The covariance matrices of the source GMM components.
C_t (array-like, shape (k_t, d, d)) – The covariance matrices of the target GMM components.
w_s (array-like, shape (k_s,)) – The weights of the source GMM components.
w_t (array-like, shape (k_t,)) – The weights of the target GMM components.
plan (array-like, shape (k_s, k_t), optional) – The optimal transport plan between the source and target GMMs. If not provided, it will be computed using gmm_ot_plan.
atol (float, optional) – The absolute tolerance used to determine the support of the GMM-OT coupling.
- Returns:
density – The density of the GMM-OT coupling between the two GMMs.
- Return type:
array-like, shape (n, m)
References
Examples using ot.gmm.gmm_ot_plan_density
- ot.gmm.gmm_pdf(x, m, C, w)[source]
Compute the probability density function (PDF) of a Gaussian Mixture Model (GMM) at given points.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (n_components, d)) – The means of the Gaussian components.
C (array-like, shape (n_components, d, d)) – The covariance matrices of the Gaussian components.
w (array-like, shape (n_components,)) – The weights of the Gaussian components.
- Returns:
out – The PDF values at the given points.
- Return type:
array-like, shape (…,)
Examples using ot.gmm.gmm_pdf
- ot.gmm.dist_bures_squared(m_s, m_t, C_s, C_t)[source]
Compute the matrix of the squared Bures distances between the components of two Gaussian Mixture Models (GMMs). Used to compute the GMM Optimal Transport distance [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
- Returns:
dist – Matrix of squared Bures distances between the components of the source and target GMMs.
- Return type:
array-like, shape (k_s, k_t)
References
- ot.gmm.gaussian_logpdf(x, m, C)[source]
Compute the log of the probability density function of a multivariate Gaussian distribution.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (d,)) – The mean vector of the Gaussian distribution.
C (array-like, shape (d, d)) – The covariance matrix of the Gaussian distribution.
- Returns:
pdf – The probability density function evaluated at each sample.
- Return type:
array-like, shape (…,)
- ot.gmm.gaussian_pdf(x, m, C)[source]
Compute the probability density function of a multivariate Gaussian distribution.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (d,)) – The mean vector of the Gaussian distribution.
C (array-like, shape (d, d)) – The covariance matrix of the Gaussian distribution.
- Returns:
pdf – The probability density function evaluated at each sample.
- Return type:
array-like, shape (…,)
- ot.gmm.gmm_barycenter_fixed_point(means_list, covs_list, w_list, means_init, covs_init, weights, w_bar=None, iterations=100, log=False, barycentric_proj_method='euclidean')[source]
Solves the Gaussian Mixture Model OT barycenter problem (defined in [69]) using the fixed point algorithm (proposed in [77]). The weights of the barycenter are not optimized, and stay the same as the input w_list or are initialized to uniform.
The algorithm uses barycentric projections of GMM-OT plans, and these can be computed either through Bures Barycenters (slow but accurate, barycentric_proj_method=’bures’) or by convex combination (fast, barycentric_proj_method=’euclidean’, default).
This is a special case of the generic free-support barycenter solver ot.lp.free_support_barycenter_generic_costs.
- Parameters:
means_list (list of array-like) – List of K (m_k, d) GMM means.
covs_list (list of array-like) – List of K (m_k, d, d) GMM covariances.
w_list (list of array-like) – List of K (m_k) arrays of weights.
means_init (array-like) – Initial (n, d) GMM means.
covs_init (array-like) – Initial (n, d, d) GMM covariances.
weights (array-like) – Array (K,) of the barycentre coefficients.
w_bar (array-like, optional) – Initial weights (n) of the barycentre GMM. If None, initialized to uniform.
iterations (int, optional) – Number of iterations (default is 100).
log (bool, optional) – Whether to return the list of iterations (default is False).
barycentric_proj_method (str, optional) – Method to project the barycentre weights: ‘euclidean’ (default) or ‘bures’.
- Returns:
means (array-like) – (n, d) barycentre GMM means.
covs (array-like) – (n, d, d) barycentre GMM covariances.
log_dict (dict, optional) – Dictionary containing the list of iterations if log is True.
References
- ot.gmm.gmm_ot_apply_map(x, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, method='bary', seed=None)[source]
Apply Gaussian Mixture Model (GMM) optimal transport (OT) mapping to input data. The ‘barycentric’ mapping corresponds to the barycentric projection of the GMM-OT plan, and is called T_bary in [69]. The ‘random’ mapping takes for each input point a random pair (i,j) of components of the GMMs and applied the Gaussian map, it is called T_rand in [69].
- Parameters:
x (array-like, shape (n_samples, d)) – Input data points.
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM components.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM components.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM components.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM components.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
plan (array-like, shape (k_s, k_t), optional) – Optimal transport plan between the source and target GMM components. If not provided, it will be computed internally.
method ({'bary', 'rand'}, optional) – Method for applying the GMM OT mapping. ‘bary’ uses barycentric mapping, while ‘rand’ uses random sampling. Default is ‘bary’.
seed (int, optional) – Seed for the random number generator. Only used when method=’rand’.
- Returns:
out – Output data points after applying the GMM OT mapping.
- Return type:
array-like, shape (n_samples, d)
References
- ot.gmm.gmm_ot_loss(m_s, m_t, C_s, C_t, w_s, w_t, log=False)[source]
Compute the Gaussian Mixture Model (GMM) Optimal Transport distance between two GMMs introduced in [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
log (bool, optional (default=False)) – If True, returns a dictionary containing the cost and dual variables. Otherwise returns only the GMM optimal transportation cost.
- Returns:
loss (float or array-like) – The GMM-OT loss.
log (dict, optional) – If input log is true, a dictionary containing the cost and dual variables and exit status
References
- ot.gmm.gmm_ot_plan(m_s, m_t, C_s, C_t, w_s, w_t, log=False)[source]
Compute the Gaussian Mixture Model (GMM) Optimal Transport plan between two GMMs introduced in [69].
- Parameters:
m_s (array-like, shape (k_s, d)) – Mean vectors of the source GMM.
m_t (array-like, shape (k_t, d)) – Mean vectors of the target GMM.
C_s (array-like, shape (k_s, d, d)) – Covariance matrices of the source GMM.
C_t (array-like, shape (k_t, d, d)) – Covariance matrices of the target GMM.
w_s (array-like, shape (k_s,)) – Weights of the source GMM components.
w_t (array-like, shape (k_t,)) – Weights of the target GMM components.
log (bool, optional (default=False)) – If True, returns a dictionary containing the cost and dual variables. Otherwise returns only the GMM optimal transportation matrix.
- Returns:
plan (array-like, shape (k_s, k_t)) – The GMM-OT plan.
log (dict, optional) – If input log is true, a dictionary containing the cost and dual variables and exit status
References
- ot.gmm.gmm_ot_plan_density(x, y, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=0.01)[source]
Compute the density of the Gaussian Mixture Model - Optimal Transport coupling between GMMS at given points, as introduced in [69]. Given two arrays of points x and y, the function computes the density at each point (x[i], y[i]) of the product space.
- Parameters:
x (array-like, shape (n, d)) – Entry points in source space for density computation.
y (array-like, shape (m, d)) – Entry points in target space for density computation.
m_s (array-like, shape (k_s, d)) – The means of the source GMM components.
m_t (array-like, shape (k_t, d)) – The means of the target GMM components.
C_s (array-like, shape (k_s, d, d)) – The covariance matrices of the source GMM components.
C_t (array-like, shape (k_t, d, d)) – The covariance matrices of the target GMM components.
w_s (array-like, shape (k_s,)) – The weights of the source GMM components.
w_t (array-like, shape (k_t,)) – The weights of the target GMM components.
plan (array-like, shape (k_s, k_t), optional) – The optimal transport plan between the source and target GMMs. If not provided, it will be computed using gmm_ot_plan.
atol (float, optional) – The absolute tolerance used to determine the support of the GMM-OT coupling.
- Returns:
density – The density of the GMM-OT coupling between the two GMMs.
- Return type:
array-like, shape (n, m)
References
- ot.gmm.gmm_pdf(x, m, C, w)[source]
Compute the probability density function (PDF) of a Gaussian Mixture Model (GMM) at given points.
- Parameters:
x (array-like, shape (..., d)) – The input samples.
m (array-like, shape (n_components, d)) – The means of the Gaussian components.
C (array-like, shape (n_components, d, d)) – The covariance matrices of the Gaussian components.
w (array-like, shape (n_components,)) – The weights of the Gaussian components.
- Returns:
out – The PDF values at the given points.
- Return type:
array-like, shape (…,)