r""" 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
(x, m, C, w)
| 72 | |
| 73 | |
| 74 | def gmm_pdf(x, m, C, w): |
| 75 | r""" |
| 76 | Compute the probability density function (PDF) of a |
| 77 | Gaussian Mixture Model (GMM) at given points. |
| 78 | |
| 79 | Parameters |
| 80 | ---------- |
| 81 | x : array-like, shape (..., d) |
| 82 | The input samples. |
| 83 | m : array-like, shape (n_components, d) |
| 84 | The means of the Gaussian components. |
| 85 | C : array-like, shape (n_components, d, d) |
| 86 | The covariance matrices of the Gaussian components. |
| 87 | w : array-like, shape (n_components,) |
| 88 | The weights of the Gaussian components. |
| 89 | |
| 90 | Returns |
| 91 | ------- |
| 92 | out : array-like, shape (...,) |
| 93 | The PDF values at the given points. |
| 94 | |
| 95 | """ |
| 96 | assert ( |
| 97 | m.shape[0] == C.shape[0] == w.shape[0] |
| 98 | ), "All GMM parameters must have the same amount of components" |
| 99 | nx = get_backend(x, m, C, w) |
| 100 | out = nx.zeros((x.shape[:-1])) |
| 101 | for k in range(m.shape[0]): |
| 102 | out = out + w[k] * gaussian_pdf(x, m[k], C[k]) |
| 103 | return out |
| 104 | |
| 105 | |
| 106 | def dist_bures_squared(m_s, m_t, C_s, C_t): |