40 const double * c_mean =
c_means[k];
45 for (
int d = 0; d <
D; d++) {
46 double tmp_val = c_x_in[d] - c_mean[d];
47 acc += (tmp_val * tmp_val) * c_diag_cov_inv_etc[d];
62 it_assert(
valid,
"MOG_diag::log_lhood_single_gaus(): model not valid");
63 it_assert(((k >= 0) && (k <
K)),
"MOG::log_lhood_single_gaus(): k specifies a non-existant Gaussian");
72 it_assert(
valid,
"MOG_diag::log_lhood_single_gaus(): model not valid");
73 it_assert(
check_size(x_in),
"MOG_diag::log_lhood_single_gaus(): x has wrong dimensionality");
74 it_assert(((k >= 0) && (k <
K)),
"MOG::log_lhood_single_gaus(): k specifies a non-existant Gaussian");
85 for (
int k = 0;k <
K;k++) {
94 double log_sum = c_tmpvecK[0];
95 for (
int k = 1; k <
K; k++) log_sum =
log_add(log_sum, c_tmpvecK[k]);
100 for (
int k = 0;k <
K;k++)
sum +=
std::exp(c_tmpvecK[k]);
126 it_assert((c_x_in != 0),
"MOG_diag::log_lhood(): c_x_in is a null pointer");
138 for (
int k = 0;k <
K;k++) {
147 double log_sum = c_tmpvecK[0];
148 for (
int k = 1; k <
K; k++) log_sum =
log_add(log_sum, c_tmpvecK[k]);
153 for (
int k = 0;k <
K;k++)
sum +=
std::exp(c_tmpvecK[k]);
174 it_assert((c_x_in != 0),
"MOG_diag::lhood(): c_x_in is a null pointer");
185 it_assert((c_x_in != 0),
"MOG_diag::avg_log_lhood(): c_x_in is a null pointer");
186 it_assert((N >= 0),
"MOG_diag::avg_log_lhood(): N is zero or negative");
199 it_assert(
check_size(X_in),
"MOG_diag::avg_log_lhood(): X is empty or at least one vector has the wrong dimensionality");
201 const int N = X_in.
size();
286 int rows = A_in.
size();
287 double ** A = (
double **)std::malloc(rows *
sizeof(
double *));
288 if (A)
for (
int row = 0;row < rows;row++) A[row] = A_in(row)._data();
294 int rows = A_in.
size();
295 int ** A = (
int **)std::malloc(rows *
sizeof(
int *));
296 if (A)
for (
int row = 0;row < rows;row++) A[row] = A_in(row)._data();
double log_lhood_single_gaus(const double *c_x_in, const int k) const
calculate the log likelihood of C vector c_x_in using only Gaussian k
Diagonal Mixture of Gaussians class - header file.
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b))
void convert_to_diag_internal()
ADD DOCUMENTATION HERE.
int size() const
Returns the number of data elements in the array object.
virtual void setup_covs()
additional processing of covariance vectors/matrices, done as the last step of covariance initialisat...
void load(const std::string &name_in)
Initialise the model by loading the parameters from a model file.
double * c_log_weights
pointer to the log version of the weight vector
double * c_log_det_etc
pointer to the log_det_etc vector
void setup_misc()
additional processing of miscellaneous parameters, done as the last step of overall initialisation ...
double ** c_diag_covs
pointers to the covariance vectors
T sum(const Vec< T > &v)
Sum of all elements in the vector.
double log_lhood_internal(const double *c_x_in)
ADD DOCUMENTATION HERE.
#define it_assert(t, s)
Abort if t is not true.
Logarithmic and exponenential functions - header file.
virtual void setup_misc()
additional processing of miscellaneous parameters, done as the last step of overall initialisation ...
double ** c_means
pointers to the mean vectors
bool check_size(const vec &x_in) const
Check if vector x_in has the same dimensionality as the model.
vec log(const vec &x)
The natural logarithm of the elements.
virtual void setup_weights()
additional processing of the weight vector, done as the last step of weight initialisation ...
double lhood_internal(const double *c_x_in)
ADD DOCUMENTATION HERE.
double lhood(const double *c_x_in)
calculate the likelihood of C vector c_x_in
vec log_weights
Pre-calculated log versions of the weights.
vec exp(const vec &x)
Exp of the elements of a vector x.
bool full
indicates whether we are using full or diagonal covariance matrices
Array< vec > diag_covs_inv_etc
Pre-calcuated inverted version of each diagonal covariance vector, where the covariance elements are ...
void free_all_ptrs()
ADD DOCUMENTATION HERE.
bool do_checks
indicates whether checks on input data are done
double ** disable_c_access(double **A_in)
Disable C style access to an Array of vectors (vec)
double log_lhood_single_gaus_internal(const double *c_x_in, const int k) const
ADD DOCUMENTATION HERE.
virtual void convert_to_diag()
Convert the model to use diagonal covariances.
double ** c_diag_covs_inv_etc
pointers to the inverted covariance vectors
virtual void setup_means()
additional processing of mean vectors, done as the last step of mean initialisation ...
double ** enable_c_access(Array< vec > &A_in)
Enable C style access to an Array of vectors (vec)
void setup_covs()
additional processing of covariance vectors/matrices, done as the last step of covariance initialisat...
void setup_means()
additional processing of mean vectors, done as the last step of mean initialisation ...
virtual void load(const std::string &name_in)
Initialise the model by loading the parameters from a model file.
vec log_det_etc
Gaussian specific pre-calcualted constants.
double avg_log_lhood(const double **c_x_in, int N)
calculate the average log likelihood of an array of C vectors ( c_x_in )
double trunc_exp(double x)
Truncated exponential function.
bool paranoid
indicates whether we are paranoid about numerical stability
void setup_weights()
additional processing of the weight vector, done as the last step of weight initialisation ...
bool valid
indicates whether the parameters are valid
Array< vec > diag_covs
diagonal covariance matrices, stored as vectors
double log_max_K
Pre-calcualted std::log(std::numeric_limits<double>::max() / K), where K is the number of Gaussians...
double * c_weights
pointer to the weight vector
double log_lhood(const double *c_x_in)
calculate the log likelihood of C vector c_x_in
void zero_all_ptrs()
ADD DOCUMENTATION HERE.