jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
recommender.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,2012 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_RECOMMENDER_HPP_
18 #define JUBATUS_CORE_DRIVER_RECOMMENDER_HPP_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include "jubatus/util/lang/shared_ptr.h"
24 #include "../recommender/recommender_base.hpp"
25 #include "../framework/mixable.hpp"
26 #include "../framework/diffv.hpp"
27 #include "../fv_converter/mixable_weight_manager.hpp"
28 #include "../fv_converter/datum_to_fv_converter.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 recommender {
38 class recommender_base;
39 } // namespace recommender
40 namespace driver {
41 
42 class recommender : public driver_base {
43  public:
45  jubatus::util::lang::shared_ptr<core::recommender::recommender_base>
46  method,
47  jubatus::util::lang::shared_ptr<fv_converter::datum_to_fv_converter>
48  converter);
49  virtual ~recommender();
50 
51  void clear_row(const std::string& id);
52  void update_row(const std::string& id, const fv_converter::datum& dat);
53  void clear();
54  void pack(framework::packer& pk) const;
55  void unpack(msgpack::object o);
56 
57  fv_converter::datum complete_row_from_id(const std::string& id);
59  std::vector<std::pair<std::string, float> > similar_row_from_id(
60  const std::string& id,
61  size_t ret_num);
62  std::vector<std::pair<std::string, float> > similar_row_from_datum(
63  const fv_converter::datum& data,
64  size_t size);
65 
66  float calc_similality(
67  const fv_converter::datum& l,
68  const fv_converter::datum& r);
69  float calc_l2norm(const fv_converter::datum& q);
70 
71  fv_converter::datum decode_row(const std::string& id);
72  std::vector<std::string> get_all_rows();
73 
74  private:
75  jubatus::util::lang::shared_ptr<fv_converter::datum_to_fv_converter>
77  jubatus::util::lang::shared_ptr<core::recommender::recommender_base>
80 };
81 
82 } // namespace driver
83 } // namespace core
84 } // namespace jubatus
85 
86 #endif // JUBATUS_CORE_DRIVER_RECOMMENDER_HPP_
std::vector< std::pair< std::string, float > > similar_row_from_datum(const fv_converter::datum &data, size_t size)
fv_converter::datum complete_row_from_id(const std::string &id)
Definition: recommender.cpp:76
void unpack(msgpack::object o)
void clear_row(const std::string &id)
Definition: recommender.cpp:59
jubatus::util::lang::shared_ptr< core::recommender::recommender_base > recommender_
Definition: recommender.hpp:78
void pack(framework::packer &pk) const
fv_converter::mixable_weight_manager wm_
Definition: recommender.hpp:79
std::vector< std::string > get_all_rows()
void update_row(const std::string &id, const fv_converter::datum &dat)
Definition: recommender.cpp:63
std::vector< std::pair< std::string, float > > similar_row_from_id(const std::string &id, size_t ret_num)
Definition: recommender.cpp:96
fv_converter::datum decode_row(const std::string &id)
std::string method
recommender(jubatus::util::lang::shared_ptr< core::recommender::recommender_base > method, jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter)
Definition: recommender.cpp:44
float calc_similality(const fv_converter::datum &l, const fv_converter::datum &r)
jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter_
Definition: recommender.hpp:76
float calc_l2norm(const fv_converter::datum &q)
fv_converter::datum complete_row_from_datum(const fv_converter::datum &dat)
Definition: recommender.cpp:85