// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup gmm_full //! @{ namespace gmm_priv { template class gmm_full { public: arma_aligned const Mat means; arma_aligned const Cube fcovs; arma_aligned const Row hefts; // // inline ~gmm_full(); inline gmm_full(); inline gmm_full(const gmm_full& x); inline gmm_full& operator=(const gmm_full& x); inline explicit gmm_full(const gmm_diag& x); inline gmm_full& operator=(const gmm_diag& x); inline gmm_full(const uword in_n_dims, const uword in_n_gaus); inline void reset(const uword in_n_dims, const uword in_n_gaus); inline void reset(); template inline void set_params(const Base& in_means, const BaseCube& in_fcovs, const Base& in_hefts); template inline void set_means(const Base & in_means); template inline void set_fcovs(const BaseCube& in_fcovs); template inline void set_hefts(const Base & in_hefts); inline uword n_dims() const; inline uword n_gaus() const; inline bool load(const std::string name); inline bool save(const std::string name) const; inline Col generate() const; inline Mat generate(const uword N) const; template inline eT log_p(const T1& expr, const gmm_empty_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk2 = nullptr) const; template inline eT log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk2 = nullptr) const; template inline Row log_p(const T1& expr, const gmm_empty_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2 = nullptr) const; template inline Row log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2 = nullptr) const; template inline eT sum_log_p(const Base& expr) const; template inline eT sum_log_p(const Base& expr, const uword gaus_id) const; template inline eT avg_log_p(const Base& expr) const; template inline eT avg_log_p(const Base& expr, const uword gaus_id) const; template inline uword assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk = nullptr) const; template inline urowvec assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk = nullptr) const; template inline urowvec raw_hist(const Base& expr, const gmm_dist_mode& dist_mode) const; template inline Row norm_hist(const Base& expr, const gmm_dist_mode& dist_mode) const; template inline bool learn ( const Base& data, const uword n_gaus, const gmm_dist_mode& dist_mode, const gmm_seed_mode& seed_mode, const uword km_iter, const uword em_iter, const eT var_floor, const bool print_mode ); // protected: arma_aligned Cube inv_fcovs; arma_aligned Row log_det_etc; arma_aligned Row log_hefts; arma_aligned Col mah_aux; arma_aligned Cube chol_fcovs; // inline void init(const gmm_full& x); inline void init(const gmm_diag& x); inline void init(const uword in_n_dim, const uword in_n_gaus); inline void init_constants(const bool calc_chol = true); inline umat internal_gen_boundaries(const uword N) const; inline eT internal_scalar_log_p(const eT* x ) const; inline eT internal_scalar_log_p(const eT* x, const uword gaus_id) const; inline Row internal_vec_log_p(const Mat& X ) const; inline Row internal_vec_log_p(const Mat& X, const uword gaus_id) const; inline eT internal_sum_log_p(const Mat& X ) const; inline eT internal_sum_log_p(const Mat& X, const uword gaus_id) const; inline eT internal_avg_log_p(const Mat& X ) const; inline eT internal_avg_log_p(const Mat& X, const uword gaus_id) const; inline uword internal_scalar_assign(const Mat& X, const gmm_dist_mode& dist_mode) const; inline void internal_vec_assign(urowvec& out, const Mat& X, const gmm_dist_mode& dist_mode) const; inline void internal_raw_hist(urowvec& hist, const Mat& X, const gmm_dist_mode& dist_mode) const; // template inline void generate_initial_means(const Mat& X, const gmm_seed_mode& seed); template inline void generate_initial_params(const Mat& X, const eT var_floor); template inline bool km_iterate(const Mat& X, const uword max_iter, const bool verbose); // inline bool em_iterate(const Mat& X, const uword max_iter, const eT var_floor, const bool verbose); inline void em_update_params(const Mat& X, const umat& boundaries, field< Mat >& t_acc_means, field< Cube >& t_acc_fcovs, field< Col >& t_acc_norm_lhoods, field< Col >& t_gaus_log_lhoods, Col& t_progress_log_lhoods, const eT var_floor); inline void em_generate_acc(const Mat& X, const uword start_index, const uword end_index, Mat& acc_means, Cube& acc_fcovs, Col& acc_norm_lhoods, Col& gaus_log_lhoods, eT& progress_log_lhood) const; inline void em_fix_params(const eT var_floor); }; } typedef gmm_priv::gmm_full gmm_full; typedef gmm_priv::gmm_full fgmm_full; //! @}