jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
clustering.hpp
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 
17 #ifndef JUBATUS_CORE_CLUSTERING_CLUSTERING_HPP_
18 #define JUBATUS_CORE_CLUSTERING_CLUSTERING_HPP_
19 
20 #include <stdint.h>
21 #include <cstdlib>
22 #include <map>
23 #include <string>
24 #include <vector>
25 #include "jubatus/util/concurrent/rwmutex.h"
26 #include "jubatus/util/data/unordered_map.h"
27 #include "jubatus/util/lang/shared_ptr.h"
28 #include "../common/exception.hpp"
29 #include "../common/type.hpp"
30 #include "../framework/mixable.hpp"
31 #include "clustering_method.hpp"
32 #include "clustering_config.hpp"
33 #include "storage.hpp"
34 #include "types.hpp"
35 
36 namespace jubatus {
37 namespace core {
38 namespace clustering {
39 
41  public:
42  explicit clustering_error(const std::string& msg)
43  : runtime_error(msg) {
44  }
45 };
46 
47 class clustering {
48  public:
49  clustering(
50  const std::string& name,
51  const std::string& method,
52  const clustering_config& cfg);
53  virtual ~clustering();
54 
55  bool push(const std::vector<weighted_point>& points);
56  wplist get_coreset() const;
57  std::vector<wplist> get_core_members() const;
58  wplist get_nearest_members(const common::sfv_t& point) const;
59  std::vector<common::sfv_t> get_k_center() const;
61 
62  size_t get_revision() const;
63 
64  void set_storage(jubatus::util::lang::shared_ptr<storage> storage);
65  jubatus::util::lang::shared_ptr<storage> get_storage();
66 
68  jubatus::util::lang::shared_ptr<clustering_method> clustering_method);
69 
71  std::string type() const;
72 
73  void pack(framework::packer& pk) const;
74  void unpack(msgpack::object o);
75  void clear();
76 
77  // for test only
78  void do_clustering();
79 
80  private:
81  void init();
82  void update_clusters(const wplist& points, bool batch);
83  wplist get_coreset_mine() const;
84 
86  std::string name_;
87  std::string method_;
88 
89  jubatus::util::lang::shared_ptr<clustering_method> clustering_method_;
90  jubatus::util::lang::shared_ptr<mixable_storage> storage_;
91 };
92 
93 } // namespace clustering
94 } // namespace core
95 } // namespace jubatus
96 
97 #endif // JUBATUS_CORE_CLUSTERING_CLUSTERING_HPP_
std::vector< wplist > get_core_members() const
Definition: clustering.cpp:165
clustering_error(const std::string &msg)
Definition: clustering.hpp:42
jubatus::util::lang::shared_ptr< storage > get_storage()
Definition: clustering.cpp:119
void set_storage(jubatus::util::lang::shared_ptr< storage > storage)
Definition: clustering.cpp:109
common::sfv_t get_nearest_center(const common::sfv_t &point) const
Definition: clustering.cpp:153
clustering(const std::string &name, const std::string &method, const clustering_config &cfg)
Definition: clustering.cpp:37
wplist get_nearest_members(const common::sfv_t &point) const
Definition: clustering.cpp:157
void pack(framework::packer &pk) const
Definition: clustering.cpp:181
std::vector< common::sfv_t > get_k_center() const
Definition: clustering.cpp:149
void unpack(msgpack::object o)
Definition: clustering.cpp:185
std::string method
jubatus::util::lang::shared_ptr< clustering_method > clustering_method_
Definition: clustering.hpp:89
void update_clusters(const wplist &points, bool batch)
Definition: clustering.cpp:123
void set_clustering_method(jubatus::util::lang::shared_ptr< clustering_method > clustering_method)
Definition: clustering.cpp:131
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
jubatus::util::lang::shared_ptr< mixable_storage > storage_
Definition: clustering.hpp:90
std::vector< weighted_point > wplist
Definition: types.hpp:55
bool push(const std::vector< weighted_point > &points)
Definition: clustering.cpp:136
framework::mixable * get_mixable() const
Definition: clustering.cpp:173