Skip to contents

The exact first two moments of a mixture: $$\mu = \sum_k w_k \mu_k, \qquad \Sigma = \sum_k w_k \left(\Sigma_k + \mu_k \mu_k^\top\right) - \mu \mu^\top.$$

Usage

gmm_mean(g)

gmm_cov(g)

Arguments

g

A gmm (or gmm_fit).

Value

gmm_mean() returns a length-p numeric vector; gmm_cov() returns a p by p numeric matrix.

Examples

g <- gmm(weights = c(0.3, 0.7), means = list(c(-1, 0), c(1, 2)),
         covariances = list(diag(2), 0.5 * diag(2)))
gmm_mean(g)
#> [1] 0.4 1.4
gmm_cov(g)
#>      [,1] [,2]
#> [1,] 1.49 0.84
#> [2,] 0.84 1.49