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, y, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=1e-2)
| 370 | |
| 371 | |
| 372 | def gmm_ot_plan_density(x, y, m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=1e-2): |
| 373 | """ |
| 374 | Compute the density of the Gaussian Mixture Model - Optimal Transport |
| 375 | coupling between GMMS at given points, as introduced in [69]. |
| 376 | Given two arrays of points x and y, the function computes the density at |
| 377 | each point `(x[i], y[i])` of the product space. |
| 378 | |
| 379 | Parameters |
| 380 | ---------- |
| 381 | x : array-like, shape (n, d) |
| 382 | Entry points in source space for density computation. |
| 383 | y : array-like, shape (m, d) |
| 384 | Entry points in target space for density computation. |
| 385 | m_s : array-like, shape (k_s, d) |
| 386 | The means of the source GMM components. |
| 387 | m_t : array-like, shape (k_t, d) |
| 388 | The means of the target GMM components. |
| 389 | C_s : array-like, shape (k_s, d, d) |
| 390 | The covariance matrices of the source GMM components. |
| 391 | C_t : array-like, shape (k_t, d, d) |
| 392 | The covariance matrices of the target GMM components. |
| 393 | w_s : array-like, shape (k_s,) |
| 394 | The weights of the source GMM components. |
| 395 | w_t : array-like, shape (k_t,) |
| 396 | The weights of the target GMM components. |
| 397 | plan : array-like, shape (k_s, k_t), optional |
| 398 | The optimal transport plan between the source and target GMMs. |
| 399 | If not provided, it will be computed using `gmm_ot_plan`. |
| 400 | atol : float, optional |
| 401 | The absolute tolerance used to determine the support of the GMM-OT |
| 402 | coupling. |
| 403 | |
| 404 | Returns |
| 405 | ------- |
| 406 | density : array-like, shape (n, m) |
| 407 | The density of the GMM-OT coupling between the two GMMs. |
| 408 | |
| 409 | References |
| 410 | ---------- |
| 411 | .. [69] Delon, J., & Desolneux, A. (2020). A Wasserstein-type distance in the space of Gaussian mixture models. SIAM Journal on Imaging Sciences, 13(2), 936-970. |
| 412 | |
| 413 | """ |
| 414 | assert ( |
| 415 | x.shape[-1] == y.shape[-1] |
| 416 | ), "x (n, d) and y (m, d) must have the same dimension d" |
| 417 | n, m = x.shape[0], y.shape[0] |
| 418 | nx = get_backend(x, y, m_s, m_t, C_s, C_t, w_s, w_t) |
| 419 | |
| 420 | # hand-made d-variate meshgrid in ij indexing |
| 421 | xx = x[:, None, :] * nx.ones((1, m, 1)) # shapes (n, m, d) |
| 422 | yy = y[None, :, :] * nx.ones((n, 1, 1)) # shapes (n, m, d) |
| 423 | |
| 424 | if plan is None: |
| 425 | plan = gmm_ot_plan(m_s, m_t, C_s, C_t, w_s, w_t) |
| 426 | |
| 427 | def Tk0k1(k0, k1): |
| 428 | A, b = bures_wasserstein_mapping(m_s[k0], m_t[k1], C_s[k0], C_t[k1]) |
| 429 | Tx = xx @ A + b |