45 for (
int d = 0; d <
D; 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");
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++) {
100 for (
int k = 0;k <
K;k++)
sum += std::exp(c_tmpvecK[k]);
101 return(std::log(
sum));
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++) {
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");
287 double ** A = (
double **)std::malloc(rows *
sizeof(
double *));
295 int ** A = (
int **)std::malloc(rows *
sizeof(
int *));
int size() const
Returns the number of data elements in the array object.
void setup_means()
additional processing of mean vectors, done as the last step of mean initialisation
void setup_misc()
additional processing of miscellaneous parameters, done as the last step of overall initialisation
void setup_weights()
additional processing of the weight vector, done as the last step of weight initialisation
double log_lhood(const double *c_x_in)
calculate the log likelihood of C vector c_x_in
double ** c_diag_covs_inv_etc
pointers to the inverted covariance vectors
void load(const std::string &name_in)
Initialise the model by loading the parameters from a model file.
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 lhood_internal(const double *c_x_in)
ADD DOCUMENTATION HERE.
double log_lhood_single_gaus_internal(const double *c_x_in, const int k) const
ADD DOCUMENTATION HERE.
double log_lhood_internal(const double *c_x_in)
ADD DOCUMENTATION HERE.
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
void zero_all_ptrs()
ADD DOCUMENTATION HERE.
double ** c_means
pointers to the mean vectors
double ** disable_c_access(double **A_in)
Disable C style access to an Array of vectors (vec)
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...
double * c_log_det_etc
pointer to the log_det_etc vector
double * c_log_weights
pointer to the log version of the weight vector
void free_all_ptrs()
ADD DOCUMENTATION HERE.
double lhood(const double *c_x_in)
calculate the likelihood of C vector c_x_in
double * c_weights
pointer to the weight vector
double ** c_diag_covs
pointers to the covariance vectors
void convert_to_diag_internal()
ADD DOCUMENTATION HERE.
virtual void setup_weights()
additional processing of the weight vector, done as the last step of weight initialisation
bool check_size(const vec &x_in) const
Check if vector x_in has the same dimensionality as the model.
virtual void convert_to_diag()
Convert the model to use diagonal covariances.
bool do_checks
indicates whether checks on input data are done
virtual void setup_covs()
additional processing of covariance vectors/matrices, done as the last step of covariance initialisat...
virtual void setup_means()
additional processing of mean vectors, done as the last step of mean initialisation
virtual void setup_misc()
additional processing of miscellaneous parameters, done as the last step of overall initialisation
bool valid
indicates whether the parameters are valid
Array< vec > diag_covs
diagonal covariance matrices, stored as vectors
Array< vec > diag_covs_inv_etc
Pre-calcuated inverted version of each diagonal covariance vector, where the covariance elements are ...
vec log_weights
Pre-calculated log versions of the weights.
vec log_det_etc
Gaussian specific pre-calcualted constants.
bool full
indicates whether we are using full or diagonal covariance matrices
double log_max_K
Pre-calcualted std::log(std::numeric_limits<double>::max() / K), where K is the number of Gaussians.
virtual void load(const std::string &name_in)
Initialise the model by loading the parameters from a model file.
bool paranoid
indicates whether we are paranoid about numerical stability
#define it_assert(t, s)
Abort if t is not true.
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b))
double trunc_exp(double x)
Truncated exponential function.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
Logarithmic and exponenential functions - header file.
Diagonal Mixture of Gaussians class - header file.