jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
Public Member Functions | Private Attributes | List of all members
jubatus::core::bandit::epsilon_greedy Class Reference

#include <epsilon_greedy.hpp>

Inheritance diagram for jubatus::core::bandit::epsilon_greedy:
Inheritance graph
Collaboration diagram for jubatus::core::bandit::epsilon_greedy:
Collaboration graph

Public Member Functions

void clear ()
 
bool delete_arm (const std::string &arm_id)
 
 epsilon_greedy (bool assume_unrewarded, double eps)
 
arm_info_map get_arm_info (const std::string &player_id) const
 
void get_diff (diff_t &diff) const
 
storage::version get_version () const
 
void mix (const diff_t &lhs, diff_t &rhs) const
 
std::string name () const
 
void pack (framework::packer &pk) const
 
bool put_diff (const diff_t &diff)
 
bool register_arm (const std::string &arm_id)
 
bool register_reward (const std::string &player_id, const std::string &arm_id, double reward)
 
bool reset (const std::string &player_id)
 
std::string select_arm (const std::string &player_id)
 
void unpack (msgpack::object o)
 
- Public Member Functions inherited from jubatus::core::bandit::bandit_base
 bandit_base ()
 
virtual ~bandit_base ()
 

Private Attributes

double eps_
 
jubatus::util::math::random::mtrand rand_
 
summation_storage s_
 

Additional Inherited Members

- Public Types inherited from jubatus::core::bandit::bandit_base
typedef jubatus::util::data::unordered_map< std::string, arm_info_mapdiff_t
 

Detailed Description

Definition at line 30 of file epsilon_greedy.hpp.

Constructor & Destructor Documentation

jubatus::core::bandit::epsilon_greedy::epsilon_greedy ( bool  assume_unrewarded,
double  eps 
)

Definition at line 29 of file epsilon_greedy.cpp.

References JUBATUS_EXCEPTION.

30  : eps_(eps), s_(assume_unrewarded) {
31  if (eps < 0 || 1 < eps) {
32  throw JUBATUS_EXCEPTION(
33  common::invalid_parameter("0 <= epsilon <= 1"));
34  }
35 }
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79

Member Function Documentation

void jubatus::core::bandit::epsilon_greedy::clear ( )
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 84 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::clear(), and s_.

Here is the call graph for this function:

bool jubatus::core::bandit::epsilon_greedy::delete_arm ( const std::string &  arm_id)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 67 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::delete_arm(), and s_.

67  {
68  return s_.delete_arm(arm_id);
69 }
bool delete_arm(const std::string &arm_id)

Here is the call graph for this function:

arm_info_map jubatus::core::bandit::epsilon_greedy::get_arm_info ( const std::string &  player_id) const
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 77 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::get_arm_info_map(), and s_.

77  {
78  return s_.get_arm_info_map(player_id);
79 }
arm_info_map get_arm_info_map(const std::string &player_id) const

Here is the call graph for this function:

void jubatus::core::bandit::epsilon_greedy::get_diff ( diff_t diff) const
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 95 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::get_diff(), and s_.

95  {
96  s_.get_diff(diff);
97 }

Here is the call graph for this function:

storage::version jubatus::core::bandit::epsilon_greedy::get_version ( ) const
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 105 of file epsilon_greedy.cpp.

105  {
106  return storage::version();
107 }
void jubatus::core::bandit::epsilon_greedy::mix ( const diff_t lhs,
diff_t rhs 
) const
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 101 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::mix(), and s_.

101  {
102  s_.mix(lhs, rhs);
103 }
static void mix(const table_t &lhs, table_t &rhs)

Here is the call graph for this function:

std::string jubatus::core::bandit::epsilon_greedy::name ( ) const
inlinevirtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 48 of file epsilon_greedy.hpp.

48  {
49  return "epsilon_greedy";
50  }
void jubatus::core::bandit::epsilon_greedy::pack ( framework::packer pk) const
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 88 of file epsilon_greedy.cpp.

References s_.

88  {
89  pk.pack(s_);
90 }
bool jubatus::core::bandit::epsilon_greedy::put_diff ( const diff_t diff)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 98 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::put_diff(), and s_.

98  {
99  return s_.put_diff(diff);
100 }

Here is the call graph for this function:

bool jubatus::core::bandit::epsilon_greedy::register_arm ( const std::string &  arm_id)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 64 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::register_arm(), and s_.

64  {
65  return s_.register_arm(arm_id);
66 }
bool register_arm(const std::string &arm_id)

Here is the call graph for this function:

bool jubatus::core::bandit::epsilon_greedy::register_reward ( const std::string &  player_id,
const std::string &  arm_id,
double  reward 
)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 71 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::register_reward(), and s_.

73  {
74  return s_.register_reward(player_id, arm_id, reward);
75 }
bool register_reward(const std::string &player_id, const std::string &arm_id, double reward)

Here is the call graph for this function:

bool jubatus::core::bandit::epsilon_greedy::reset ( const std::string &  player_id)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 81 of file epsilon_greedy.cpp.

References jubatus::core::bandit::summation_storage::reset(), and s_.

81  {
82  return s_.reset(player_id);
83 }
bool reset(const std::string &player_id)

Here is the call graph for this function:

std::string jubatus::core::bandit::epsilon_greedy::select_arm ( const std::string &  player_id)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 37 of file epsilon_greedy.cpp.

References eps_, jubatus::core::bandit::summation_storage::get_arm_ids(), jubatus::core::bandit::summation_storage::get_expectation(), JUBATUS_EXCEPTION, jubatus::core::bandit::summation_storage::notify_selected(), rand_, and s_.

37  {
38  const std::vector<std::string>& arms = s_.get_arm_ids();
39  if (arms.empty()) {
40  throw JUBATUS_EXCEPTION(
41  common::exception::runtime_error("arm is not registered"));
42  }
43 
44  std::string result;
45  if (rand_.next_double() < eps_) {
46  // exploration
47  result = arms[rand_.next_int(arms.size())];
48  } else {
49  // exploitation
50  result = arms[0];
51  double exp_max = s_.get_expectation(player_id, arms[0]);
52  for (size_t i = 1; i < arms.size(); ++i) {
53  double exp = s_.get_expectation(player_id, arms[i]);
54  if (exp > exp_max) {
55  result = arms[i];
56  exp_max = exp;
57  }
58  }
59  }
60  s_.notify_selected(player_id, result);
61  return result;
62 }
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79
double get_expectation(const std::string &player_id, const std::string &arm_id) const
const std::vector< std::string > & get_arm_ids() const
void notify_selected(const std::string &player_id, const std::string &arm_id)
jubatus::util::math::random::mtrand rand_

Here is the call graph for this function:

void jubatus::core::bandit::epsilon_greedy::unpack ( msgpack::object  o)
virtual

Implements jubatus::core::bandit::bandit_base.

Definition at line 91 of file epsilon_greedy.cpp.

References s_.

91  {
92  o.convert(&s_);
93 }

Member Data Documentation

double jubatus::core::bandit::epsilon_greedy::eps_
private

Definition at line 61 of file epsilon_greedy.hpp.

Referenced by select_arm().

jubatus::util::math::random::mtrand jubatus::core::bandit::epsilon_greedy::rand_
private

Definition at line 62 of file epsilon_greedy.hpp.

Referenced by select_arm().

summation_storage jubatus::core::bandit::epsilon_greedy::s_
private

The documentation for this class was generated from the following files: