JWS C Library
C language utility library
|
Gaussian mixture model and parameter fitting using EM. More...
#include <jwsc/config.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <inttypes.h>
#include "jwsc/base/limits.h"
#include "jwsc/vector/vector.h"
#include "jwsc/vector/vector_math.h"
#include "jwsc/matrix/matrix.h"
#include "jwsc/matrix/matrix_math.h"
#include "jwsc/matblock/matblock.h"
#include "jwsc/prob/mv_pdf.h"
#include "jwsc/stat/stat.h"
#include "jwsc/stat/kmeans.h"
#include "jwsc/stat/gmm.h"
Go to the source code of this file.
Functions | |
static void | ensure_non_singular_covariance_d (Matrix_d **m, double min) |
Sets minimum eigenvalues of the matrix to non-negative to ensure matrix non-singularity. | |
static void | gmm_e_step_d (const Matrix_d *mu, const Matblock_d *sigma, const Vector_d *pi, Matrix_d *gamma, const Matrix_d *x) |
E-step in the EM algorithm. | |
static void | gmm_m_step_d (Matrix_d *mu, Matblock_d *sigma, Vector_d *pi, const Matrix_d *gamma, const Matrix_d *x) |
M-step in the EM algorithm. | |
double | gmm_log_likelihood_d (const Matrix_d *mu, const Matblock_d *sigma, const Vector_d *pi, const Matrix_d *x) |
Computes the double precision Gaussian mixture model log-likelihood. | |
void | gmm_kmeans_init_d (Matrix_d **mu_out, Matblock_d **sigma_out, Vector_d **pi_out, const Matrix_d *x, uint32_t K) |
Initializes the double precision Gaussian mixture model means, covariances, and mixture weights using the kmeans clustering algorithm. | |
void | gmm_stats_init_d (Matrix_d **mu_out, Matblock_d **sigma_out, Vector_d **pi_out, const Matrix_d *x, uint32_t K) |
Initializes the double precision Gaussian mixture model means, covariances, and mixture weights with sample statistics. | |
void | train_gmm_d (Matrix_d **mu_out, Matblock_d **sigma_out, Vector_d **pi_out, Matrix_d **gamma_out, const Matrix_d *x, uint32_t K) |
Trains a double precision Gaussian mixture model. |
Gaussian mixture model and parameter fitting using EM.
Definition in file gmm.c.
static void ensure_non_singular_covariance_d | ( | Matrix_d ** | m, |
double | min | ||
) | [static] |
static void gmm_e_step_d | ( | const Matrix_d * | mu, |
const Matblock_d * | sigma, | ||
const Vector_d * | pi, | ||
Matrix_d * | gamma, | ||
const Matrix_d * | x | ||
) | [static] |
static void gmm_m_step_d | ( | Matrix_d * | mu, |
Matblock_d * | sigma, | ||
Vector_d * | pi, | ||
const Matrix_d * | gamma, | ||
const Matrix_d * | x | ||
) | [static] |
double gmm_log_likelihood_d | ( | const Matrix_d * | mu, |
const Matblock_d * | sigma, | ||
const Vector_d * | pi, | ||
const Matrix_d * | x | ||
) |
void gmm_kmeans_init_d | ( | Matrix_d ** | mu_out, |
Matblock_d ** | sigma_out, | ||
Vector_d ** | pi_out, | ||
const Matrix_d * | x, | ||
uint32_t | K | ||
) |
Initializes the double precision Gaussian mixture model means, covariances, and mixture weights using the kmeans clustering algorithm.
If one of the arguments is already allocated, it is assumed to be initialized as well.
Minimum cluster membership is 2 samples.
mu_out | Multivariate Gaussian means. |
sigma_out | Multivariate Gaussian Covariance matrices. |
pi_out | Mixture component weights. |
x | Data. |
K | Number of mixture components. |
void gmm_stats_init_d | ( | Matrix_d ** | mu_out, |
Matblock_d ** | sigma_out, | ||
Vector_d ** | pi_out, | ||
const Matrix_d * | x, | ||
uint32_t | K | ||
) |
Initializes the double precision Gaussian mixture model means, covariances, and mixture weights with sample statistics.
All cluster covariance matrices are set to the sample covariance. One mean is set from the sample mean, and the rest are random samples from a Gaussian using the sample mean and covariance matrix.
If one of the arguments is already allocated, it is assumed to be initialized as well.
mu_out | Multivariate Gaussian means. |
sigma_out | Multivariate Gaussian covariance matrices. |
pi_out | Mixture component weights. |
x | Data. |
K | Number of mixture components. |
void train_gmm_d | ( | Matrix_d ** | mu_out, |
Matblock_d ** | sigma_out, | ||
Vector_d ** | pi_out, | ||
Matrix_d ** | gamma_out, | ||
const Matrix_d * | x, | ||
uint32_t | K | ||
) |
Trains a double precision Gaussian mixture model.
If *mu_out, *sigma_out and *pi_out are not initialized, gmm_kmeans_init_d() is used to do so.
mu_out | Result parameter. Means for each mixture component. |
sigma_out | Result parameter. Covariance matrices for each mixture component. |
pi_out | Result parameter. Mixture component weights. |
gamma_out | Optional result parameter. Responsibilities of each mixture component per sample. If NULL, the variable is ignored. |
x | Data to train the GMM with. |
K | Number of mixture components. |