jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
nearest_neighbor.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_DRIVER_NEAREST_NEIGHBOR_HPP_
18 #define JUBATUS_CORE_DRIVER_NEAREST_NEIGHBOR_HPP_
19 
20 #include <stdint.h>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 #include "jubatus/util/lang/shared_ptr.h"
25 
26 #include "../framework/mixable.hpp"
27 #include "../fv_converter/mixable_weight_manager.hpp"
28 #include "../unlearner/unlearner_base.hpp"
29 #include "driver.hpp"
30 
31 namespace jubatus {
32 namespace core {
33 namespace fv_converter {
34 class datum;
35 class datum_to_fv_converter;
36 } // namespace fv_converter
37 namespace storage {
38 class column_table;
39 } // namespace storage
40 namespace nearest_neighbor {
41 class nearest_neighbor_base;
42 } // namespace nearest_neighbor
43 namespace driver {
44 
45 class nearest_neighbor : public driver_base {
46  public:
48  jubatus::util::lang::shared_ptr<
50  jubatus::util::lang::shared_ptr<
52 
54  jubatus::util::lang::shared_ptr<
56  jubatus::util::lang::shared_ptr<
58  jubatus::util::lang::shared_ptr<unlearner::unlearner_base> unlearner);
59 
60  jubatus::util::lang::shared_ptr<storage::column_table> get_table();
61  jubatus::util::lang::shared_ptr<const storage::column_table>
62  get_const_table() const;
63 
64  void set_row(const std::string& id, const fv_converter::datum& datum);
65 
66  std::vector<std::pair<std::string, float> >
67  neighbor_row_from_id(const std::string& id, size_t size);
68 
69  std::vector<std::pair<std::string, float> >
70  neighbor_row_from_datum(const fv_converter::datum& datum, size_t size);
71 
72  std::vector<std::pair<std::string, float> >
73  similar_row(const std::string& id, size_t ret_num);
74 
75  std::vector<std::pair<std::string, float> >
76  similar_row(const core::fv_converter::datum& datum, size_t ret_num);
77 
78  std::vector<std::string> get_all_rows();
79 
80  void clear();
81  void pack(framework::packer& pk) const;
82  void unpack(msgpack::object o);
83 
84  private:
85  jubatus::util::lang::shared_ptr<fv_converter::datum_to_fv_converter>
87  jubatus::util::lang::shared_ptr<core::nearest_neighbor::nearest_neighbor_base>
88  nn_;
89  jubatus::util::lang::shared_ptr<unlearner::unlearner_base> unlearner_;
91 };
92 
93 } // namespace driver
94 } // namespace core
95 } // namespace jubatus
96 
97 #endif // JUBATUS_CORE_DRIVER_NEAREST_NEIGHBOR_HPP_
jubatus::util::lang::shared_ptr< unlearner::unlearner_base > unlearner_
fv_converter::mixable_weight_manager wm_
void set_row(const std::string &id, const fv_converter::datum &datum)
jubatus::util::lang::shared_ptr< core::nearest_neighbor::nearest_neighbor_base > nn_
jubatus::util::data::optional< std::string > unlearner
std::vector< std::pair< std::string, float > > neighbor_row_from_datum(const fv_converter::datum &datum, size_t size)
jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter_
std::vector< std::pair< std::string, float > > similar_row(const std::string &id, size_t ret_num)
nearest_neighbor(jubatus::util::lang::shared_ptr< core::nearest_neighbor::nearest_neighbor_base > nn, jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter)
jubatus::util::lang::shared_ptr< const storage::column_table > get_const_table() const
jubatus::util::lang::shared_ptr< storage::column_table > get_table()
std::vector< std::string > get_all_rows()
std::vector< std::pair< std::string, float > > neighbor_row_from_id(const std::string &id, size_t size)
void pack(framework::packer &pk) const