jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
gmm_clustering_method.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2013 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
18 
19 #include <utility>
20 #include <vector>
21 #include "../common/exception.hpp"
22 #include "util.hpp"
23 
24 using std::vector;
25 
26 namespace jubatus {
27 namespace core {
28 namespace clustering {
29 
31  : k_(k), kcenters_(), mapper_(), gmm_() {
32 }
33 
35 }
36 
38  if (points.empty()) {
39  *this = gmm_clustering_method(k_);
40  return;
41  }
42  mapper_.clear();
43  eigen_wsvec_list_t data = mapper_.convert(points, true);
44  gmm_.batch(data, mapper_.get_dimension(), k_);
46 }
47 
49 }
50 
51 std::vector<common::sfv_t> gmm_clustering_method::get_k_center() const {
52  return kcenters_;
53 }
54 
56  const common::sfv_t& point) const {
58 }
59 
61  const common::sfv_t& point) const {
63 }
64 
66  size_t cluster_id,
67  const wplist& points) const {
68  return get_clusters(points)[cluster_id];
69 }
70 
72  const wplist& points) const {
73  std::vector<wplist> ret(k_);
74  for (wplist::const_iterator it = points.begin(); it != points.end(); ++it) {
75  int64_t c = get_nearest_center_index(it->data);
76  ret[c].push_back(*it);
77  }
78  return ret;
79 }
80 
81 } // namespace clustering
82 } // namespace core
83 } // namespace jubatus
void batch(const eigen_wsvec_list_t &data, int d, int k)
Definition: gmm.cpp:40
eigen_svec_t convertc(const common::sfv_t &src) const
wplist get_cluster(size_t cluster_id, const wplist &points) const
int64_t get_nearest_center_index(const eigen_svec_t &p) const
Definition: gmm.cpp:95
std::vector< wplist > get_clusters(const wplist &points) const
wplist revert(const eigen_wsvec_list_t &src) const
eigen_svec_t get_nearest_center(const eigen_svec_t &p) const
Definition: gmm.cpp:91
eigen_svec_list_t get_centers()
Definition: gmm.hpp:29
int64_t get_nearest_center_index(const common::sfv_t &point) const
common::sfv_t get_nearest_center(const common::sfv_t &point) const
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
std::vector< common::sfv_t > get_k_center() const
std::vector< eigen_wsvec_t > eigen_wsvec_list_t
Definition: gmm_types.hpp:42
eigen_wsvec_list_t convert(const wplist &src, bool update_map=true)
std::vector< weighted_point > wplist
Definition: types.hpp:55