fn_kmeans.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_kmeans
  16. //! @{
  17. template<typename T1>
  18. inline
  19. typename enable_if2<is_real<typename T1::elem_type>::value, bool>::result
  20. kmeans
  21. (
  22. Mat<typename T1::elem_type>& means,
  23. const Base<typename T1::elem_type,T1>& data,
  24. const uword k,
  25. const gmm_seed_mode& seed_mode,
  26. const uword n_iter,
  27. const bool print_mode
  28. )
  29. {
  30. arma_extra_debug_sigprint();
  31. typedef typename T1::elem_type eT;
  32. gmm_priv::gmm_diag<eT> model;
  33. const bool status = model.kmeans_wrapper(means, data.get_ref(), k, seed_mode, n_iter, print_mode);
  34. if(status == true)
  35. {
  36. means = model.means;
  37. }
  38. else
  39. {
  40. means.soft_reset();
  41. }
  42. return status;
  43. }
  44. //! @}