| gmm_diag_bones.hpp | | gmm_diag_bones.hpp | |
| | | | |
| skipping to change at line 41 | | skipping to change at line 41 | |
| | | | |
| static const gmm_seed_keep_existing keep_existing; | | static const gmm_seed_keep_existing keep_existing; | |
| static const gmm_seed_static_subset static_subset; | | static const gmm_seed_static_subset static_subset; | |
| static const gmm_seed_static_spread static_spread; | | static const gmm_seed_static_spread static_spread; | |
| static const gmm_seed_random_subset random_subset; | | static const gmm_seed_random_subset random_subset; | |
| static const gmm_seed_random_spread random_spread; | | static const gmm_seed_random_spread random_spread; | |
| | | | |
| namespace gmm_priv | | namespace gmm_priv | |
| { | | { | |
| | | | |
|
| | | struct gmm_empty_arg {}; | |
| | | | |
| #if defined(_OPENMP) | | #if defined(_OPENMP) | |
| struct arma_omp_state | | struct arma_omp_state | |
| { | | { | |
| const int dynamic_state; | | const int dynamic_state; | |
| | | | |
| inline arma_omp_state() : dynamic_state(omp_get_dynamic()) {} | | inline arma_omp_state() : dynamic_state(omp_get_dynamic()) {} | |
| inline ~arma_omp_state() { omp_set_dynamic(dynamic_state); } | | inline ~arma_omp_state() { omp_set_dynamic(dynamic_state); } | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
| skipping to change at line 87 | | skipping to change at line 89 | |
| template<typename T1> inline void set_means(const Base<eT,T1>& in_means); | | template<typename T1> inline void set_means(const Base<eT,T1>& in_means); | |
| template<typename T1> inline void set_dcovs(const Base<eT,T1>& in_dcovs); | | template<typename T1> inline void set_dcovs(const Base<eT,T1>& in_dcovs); | |
| template<typename T1> inline void set_hefts(const Base<eT,T1>& in_hefts); | | template<typename T1> inline void set_hefts(const Base<eT,T1>& in_hefts); | |
| | | | |
| inline uword n_dims() const; | | inline uword n_dims() const; | |
| inline uword n_gaus() const; | | inline uword n_gaus() const; | |
| | | | |
| inline bool load(const std::string name); | | inline bool load(const std::string name); | |
| inline bool save(const std::string name) const; | | inline bool save(const std::string name) const; | |
| | | | |
|
| template<typename T1> inline typename enable_if2<resolves_to_colvector<T1 | | template<typename T1> inline eT log_p(const T1& expr, const gmm_empt | |
| >::value, eT>::result log_p(const T1& expr ) const; | | y_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type<T1>::valu | |
| template<typename T1> inline typename enable_if2<resolves_to_colvector<T1 | | e) && (resolves_to_colvector<T1>::value == true ))>::result* junk2 = 0) con | |
| >::value, eT>::result log_p(const T1& expr, const uword gaus_id) const; | | st; | |
| | | template<typename T1> inline eT log_p(const T1& expr, const uword ga | |
| template<typename T1> inline typename enable_if2< is_arma_type<T1>::value | | us_id, typename enable_if<((is_arma_type<T1>::valu | |
| && (resolves_to_colvector<T1>::value == false), Row<eT> >::result | | e) && (resolves_to_colvector<T1>::value == true ))>::result* junk2 = 0) con | |
| log_p(const T1& expr ) const; | | st; | |
| | | | |
| template<typename T1> inline typename enable_if2< is_arma_type<T1>::value | | | |
| && (resolves_to_colvector<T1>::value == false), Row<eT> >::result | | | |
| log_p(const T1& expr, const uword gaus_id) const; | | | |
| | | | |
|
| template<typename T1> inline eT avg_log_p(const Base<eT,T1>& expr) | | template<typename T1> inline Row<eT> log_p(const T1& expr, const gmm_empt | |
| const; | | y_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type<T1>::valu | |
| template<typename T1> inline eT avg_log_p(const Base<eT,T1>& expr, const | | e) && (resolves_to_colvector<T1>::value == false))>::result* junk2 = 0) con | |
| uword gaus_id) const; | | st; | |
| | | template<typename T1> inline Row<eT> log_p(const T1& expr, const uword ga | |
| | | us_id, typename enable_if<((is_arma_type<T1>::valu | |
| | | e) && (resolves_to_colvector<T1>::value == false))>::result* junk2 = 0) con | |
| | | st; | |
| | | | |
|
| template<typename T1> inline typename enable_if2<resolves_to_colvector<T1 | | template<typename T1> inline eT avg_log_p(const Base<eT,T1>& expr) | |
| >::value, uword>::result | | const; | |
| assign(const T1& expr, const gmm_dist_mode& dist) const; | | template<typename T1> inline eT avg_log_p(const Base<eT,T1>& expr, const | |
| | | uword gaus_id) const; | |
| | | | |
|
| template<typename T1> inline typename enable_if2<is_arma_type<T1>::value | | template<typename T1> inline uword assign(const T1& expr, const gmm_dis | |
| && (resolves_to_colvector<T1>::value == false), urowvec>::result | | t_mode& dist, typename enable_if<((is_arma_type<T1>::value) && (resolves_to | |
| assign(const T1& expr, const gmm_dist_mode& dist) const; | | _colvector<T1>::value == true ))>::result* junk = 0) const; | |
| | | template<typename T1> inline urowvec assign(const T1& expr, const gmm_dis | |
| | | t_mode& dist, typename enable_if<((is_arma_type<T1>::value) && (resolves_to | |
| | | _colvector<T1>::value == false))>::result* junk = 0) const; | |
| | | | |
| template<typename T1> inline urowvec raw_hist(const Base<eT,T1>& expr, c
onst gmm_dist_mode& dist_mode) const; | | template<typename T1> inline urowvec raw_hist(const Base<eT,T1>& expr, c
onst gmm_dist_mode& dist_mode) const; | |
| template<typename T1> inline Row<eT> norm_hist(const Base<eT,T1>& expr, c
onst gmm_dist_mode& dist_mode) const; | | template<typename T1> inline Row<eT> norm_hist(const Base<eT,T1>& expr, c
onst gmm_dist_mode& dist_mode) const; | |
| | | | |
|
| inline bool | | template<typename T1> | |
| | | inline | |
| | | bool | |
| learn | | learn | |
| ( | | ( | |
|
| const Mat<eT>& X, | | const Base<eT,T1>& data, | |
| const uword n_gaus, | | const uword n_gaus, | |
| const gmm_dist_mode& dist_mode, | | const gmm_dist_mode& dist_mode, | |
| const gmm_seed_mode& seed_mode, | | const gmm_seed_mode& seed_mode, | |
| const uword km_iter, | | const uword km_iter, | |
| const uword em_iter, | | const uword em_iter, | |
| const eT var_floor, | | const eT var_floor, | |
| const bool print_mode | | const bool print_mode | |
| ); | | ); | |
| | | | |
| // | | // | |
| | | | |
End of changes. 7 change blocks. |
| 24 lines changed or deleted | | 32 lines changed or added | |
|
| gmm_diag_meat.hpp | | gmm_diag_meat.hpp | |
| | | | |
| skipping to change at line 256 | | skipping to change at line 256 | |
| Q.slice(1).submat(1, 0, size(dcovs)) = dcovs; | | Q.slice(1).submat(1, 0, size(dcovs)) = dcovs; | |
| | | | |
| const bool status = Q.save(name, arma_binary); | | const bool status = Q.save(name, arma_binary); | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2<resolves_to_colvector<T1>::value, eT>::result | | eT | |
| gmm_diag<eT>::log_p(const T1& expr) const | | gmm_diag<eT>::log_p(const T1& expr, const gmm_empty_arg& junk1, typename en | |
| | | able_if<((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == | |
| | | true))>::result* junk2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk1); | |
| | | arma_ignore(junk2); | |
| | | | |
| const quasi_unwrap<T1> tmp(expr); | | const quasi_unwrap<T1> tmp(expr); | |
| | | | |
| arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): inc
ompatible dimensions" ); | | arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): inc
ompatible dimensions" ); | |
| | | | |
| return internal_scalar_log_p( tmp.M.memptr() ); | | return internal_scalar_log_p( tmp.M.memptr() ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2<resolves_to_colvector<T1>::value, eT>::result | | eT | |
| gmm_diag<eT>::log_p(const T1& expr, const uword gaus_id) const | | gmm_diag<eT>::log_p(const T1& expr, const uword gaus_id, typename enable_if | |
| | | <((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == true))> | |
| | | ::result* junk2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk2); | |
| | | | |
| const quasi_unwrap<T1> tmp(expr); | | const quasi_unwrap<T1> tmp(expr); | |
| | | | |
| arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): inc
ompatible dimensions" ); | | arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): inc
ompatible dimensions" ); | |
| | | | |
| arma_debug_check( (gaus_id >= means.n_cols), "gmm_diag::log_p(): specifie
d gaussian is out of range" ); | | arma_debug_check( (gaus_id >= means.n_cols), "gmm_diag::log_p(): specifie
d gaussian is out of range" ); | |
| | | | |
| return internal_scalar_log_p( tmp.M.memptr(), gaus_id ); | | return internal_scalar_log_p( tmp.M.memptr(), gaus_id ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2< is_arma_type<T1>::value && (resolves_to_colvector<T1>: | | Row<eT> | |
| :value == false), Row<eT> >::result | | gmm_diag<eT>::log_p(const T1& expr, const gmm_empty_arg& junk1, typename en | |
| gmm_diag<eT>::log_p(const T1& expr) const | | able_if<((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == | |
| | | false))>::result* junk2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk1); | |
| | | arma_ignore(junk2); | |
| | | | |
| if(is_subview<T1>::value) | | if(is_subview<T1>::value) | |
| { | | { | |
| const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | | const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | |
| | | | |
| return internal_vec_log_p(X); | | return internal_vec_log_p(X); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const unwrap<T1> tmp(expr); | | const unwrap<T1> tmp(expr); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| return internal_vec_log_p(X); | | return internal_vec_log_p(X); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2< is_arma_type<T1>::value && (resolves_to_colvector<T1>: | | Row<eT> | |
| :value == false), Row<eT> >::result | | gmm_diag<eT>::log_p(const T1& expr, const uword gaus_id, typename enable_if | |
| gmm_diag<eT>::log_p(const T1& expr, const uword gaus_id) const | | <((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == false)) | |
| | | >::result* junk2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk2); | |
| | | | |
| if(is_subview<T1>::value) | | if(is_subview<T1>::value) | |
| { | | { | |
| const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | | const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | |
| | | | |
| return internal_vec_log_p(X, gaus_id); | | return internal_vec_log_p(X, gaus_id); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const unwrap<T1> tmp(expr); | | const unwrap<T1> tmp(expr); | |
| | | | |
| skipping to change at line 380 | | skipping to change at line 386 | |
| const unwrap<T1> tmp(expr.get_ref()); | | const unwrap<T1> tmp(expr.get_ref()); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| return internal_avg_log_p(X, gaus_id); | | return internal_avg_log_p(X, gaus_id); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2<resolves_to_colvector<T1>::value, uword>::result | | uword | |
| gmm_diag<eT>::assign(const T1& expr, const gmm_dist_mode& dist) const | | gmm_diag<eT>::assign(const T1& expr, const gmm_dist_mode& dist, typename en | |
| | | able_if<((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == | |
| | | true))>::result* junk) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| if(is_subview_col<T1>::value) | | if(is_subview_col<T1>::value) | |
| { | | { | |
| const subview_col<eT>& X = reinterpret_cast< const subview_col<eT>& >(e
xpr); | | const subview_col<eT>& X = reinterpret_cast< const subview_col<eT>& >(e
xpr); | |
| | | | |
| return internal_scalar_assign(X, dist); | | return internal_scalar_assign(X, dist); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const unwrap<T1> tmp(expr); | | const unwrap<T1> tmp(expr); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| return internal_scalar_assign(X, dist); | | return internal_scalar_assign(X, dist); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
|
| typename enable_if2<is_arma_type<T1>::value && (resolves_to_colvector<T1>:: | | urowvec | |
| value == false), urowvec>::result | | gmm_diag<eT>::assign(const T1& expr, const gmm_dist_mode& dist, typename en | |
| gmm_diag<eT>::assign(const T1& expr, const gmm_dist_mode& dist) const | | able_if<((is_arma_type<T1>::value) && (resolves_to_colvector<T1>::value == | |
| | | false))>::result* junk) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| urowvec out; | | urowvec out; | |
| | | | |
| if(is_subview<T1>::value) | | if(is_subview<T1>::value) | |
| { | | { | |
| const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | | const subview<eT>& X = reinterpret_cast< const subview<eT>& >(expr); | |
| | | | |
| internal_vec_assign(out, X, dist); | | internal_vec_assign(out, X, dist); | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 486 | | skipping to change at line 494 | |
| Row<eT> out(hist_n_elem); | | Row<eT> out(hist_n_elem); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| for(uword i=0; i<hist_n_elem; ++i) { out_mem[i] = eT(hist_mem[i]) / acc;
} | | for(uword i=0; i<hist_n_elem; ++i) { out_mem[i] = eT(hist_mem[i]) / acc;
} | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| gmm_diag<eT>::learn | | gmm_diag<eT>::learn | |
| ( | | ( | |
|
| const Mat<eT>& X, | | const Base<eT,T1>& data, | |
| const uword n_gaus, | | const uword n_gaus, | |
| const gmm_dist_mode& dist_mode, | | const gmm_dist_mode& dist_mode, | |
| const gmm_seed_mode& seed_mode, | | const gmm_seed_mode& seed_mode, | |
| const uword km_iter, | | const uword km_iter, | |
| const uword em_iter, | | const uword em_iter, | |
| const eT var_floor, | | const eT var_floor, | |
| const bool print_mode | | const bool print_mode | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 515 | | skipping to change at line 524 | |
| (seed_mode == keep_existing) | | (seed_mode == keep_existing) | |
| || (seed_mode == static_subset) | | || (seed_mode == static_subset) | |
| || (seed_mode == static_spread) | | || (seed_mode == static_spread) | |
| || (seed_mode == random_subset) | | || (seed_mode == random_subset) | |
| || (seed_mode == random_spread); | | || (seed_mode == random_spread); | |
| | | | |
| arma_debug_check( (dist_mode_ok == false), "gmm_diag::learn(): dist_mode
must be eucl_dist or maha_dist" ); | | arma_debug_check( (dist_mode_ok == false), "gmm_diag::learn(): dist_mode
must be eucl_dist or maha_dist" ); | |
| arma_debug_check( (seed_mode_ok == false), "gmm_diag::learn(): unknown se
ed_mode" ); | | arma_debug_check( (seed_mode_ok == false), "gmm_diag::learn(): unknown se
ed_mode" ); | |
| arma_debug_check( (var_floor < eT(0) ), "gmm_diag::learn(): variance f
loor is negative" ); | | arma_debug_check( (var_floor < eT(0) ), "gmm_diag::learn(): variance f
loor is negative" ); | |
| | | | |
|
| | | const unwrap<T1> tmp_X(data.get_ref()); | |
| | | const Mat<eT>& X = tmp_X.M; | |
| | | | |
| if(X.is_empty() ) { arma_warn(true, "gmm_diag::learn(): given m
atrix is empty" ); reset(); return false; } | | if(X.is_empty() ) { arma_warn(true, "gmm_diag::learn(): given m
atrix is empty" ); reset(); return false; } | |
| if(X.is_finite() == false) { arma_warn(true, "gmm_diag::learn(): given m
atrix has non-finite values"); reset(); return false; } | | if(X.is_finite() == false) { arma_warn(true, "gmm_diag::learn(): given m
atrix has non-finite values"); reset(); return false; } | |
| | | | |
| if(n_gaus == 0) { reset(); return true; } | | if(n_gaus == 0) { reset(); return true; } | |
| | | | |
| if(dist_mode == maha_dist) | | if(dist_mode == maha_dist) | |
| { | | { | |
| mah_aux = var(X,1,1); | | mah_aux = var(X,1,1); | |
| | | | |
| const uword mah_aux_n_elem = mah_aux.n_elem; | | const uword mah_aux_n_elem = mah_aux.n_elem; | |
| | | | |
End of changes. 15 change blocks. |
| 16 lines changed or deleted | | 37 lines changed or added | |
|