jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
exp3.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2015 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_BANDIT_EXP3_HPP_
18 #define JUBATUS_CORE_BANDIT_EXP3_HPP_
19 
20 #include <string>
21 #include <vector>
22 
23 #include "bandit_base.hpp"
24 #include "summation_storage.hpp"
25 #include "jubatus/util/math/random.h"
26 
27 namespace jubatus {
28 namespace core {
29 namespace bandit {
30 
31 class exp3 : public bandit_base {
32  public:
33  exp3(bool assume_unrewarded, double gamma);
34 
35  std::string select_arm(const std::string& player_id);
36 
37  bool register_arm(const std::string& arm_id);
38  bool delete_arm(const std::string& arm_id);
39 
40  bool register_reward(const std::string& player_id,
41  const std::string& arm_id,
42  double reward);
43 
44  arm_info_map get_arm_info(const std::string& player_id) const;
45 
46  bool reset(const std::string& player_id);
47  void clear();
48 
49  std::string name() const {
50  return "exp3";
51  }
52 
53  void pack(framework::packer& pk) const;
54  void unpack(msgpack::object o);
55 
56  void get_diff(diff_t& diff) const;
57  bool put_diff(const diff_t& diff);
58  void mix(const diff_t& lhs, diff_t& rhs) const;
60 
61  private:
62  double gamma_;
63  jubatus::util::math::random::mtrand rand_;
65 
66  void calc_weights_(const std::string& player_id,
67  std::vector<double>& weights) const;
68 };
69 
70 } // namespace bandit
71 } // namespace core
72 } // namespace jubatus
73 
74 #endif // JUBATUS_CORE_BANDIT_EXP3_HPP_
storage::version get_version() const
Definition: exp3.cpp:123
summation_storage s_
Definition: exp3.hpp:64
std::string select_arm(const std::string &player_id)
Definition: exp3.cpp:60
arm_info_map get_arm_info(const std::string &player_id) const
Definition: exp3.cpp:95
bool register_reward(const std::string &player_id, const std::string &arm_id, double reward)
Definition: exp3.cpp:81
bool put_diff(const diff_t &diff)
Definition: exp3.cpp:116
exp3(bool assume_unrewarded, double gamma)
Definition: exp3.cpp:30
bool register_arm(const std::string &arm_id)
Definition: exp3.cpp:74
jubatus::util::data::unordered_map< std::string, arm_info_map > diff_t
Definition: bandit_base.hpp:65
void mix(const diff_t &lhs, diff_t &rhs) const
Definition: exp3.cpp:119
jubatus::util::data::unordered_map< std::string, arm_info > arm_info_map
Definition: arm_info.hpp:36
bool delete_arm(const std::string &arm_id)
Definition: exp3.cpp:77
void unpack(msgpack::object o)
Definition: exp3.cpp:109
bool reset(const std::string &player_id)
Definition: exp3.cpp:99
void get_diff(diff_t &diff) const
Definition: exp3.cpp:113
std::string name() const
Definition: exp3.hpp:49
void calc_weights_(const std::string &player_id, std::vector< double > &weights) const
Definition: exp3.cpp:38
jubatus::util::math::random::mtrand rand_
Definition: exp3.hpp:63
void pack(framework::packer &pk) const
Definition: exp3.cpp:106