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

#include <summation_storage.hpp>

Collaboration diagram for jubatus::core::bandit::summation_storage:
Collaboration graph

Public Types

typedef bandit_base::diff_t table_t
 

Public Member Functions

void clear ()
 
bool delete_arm (const std::string &arm_id)
 
const std::vector< std::string > & get_arm_ids () const
 
arm_info get_arm_info (const std::string &player_id, const std::string &arm_id) const
 
arm_info_map get_arm_info_map (const std::string &player_id) const
 
void get_diff (table_t &diff) const
 
double get_expectation (const std::string &player_id, const std::string &arm_id) const
 
 MSGPACK_DEFINE (arm_ids_, mixed_, unmixed_)
 
void notify_selected (const std::string &player_id, const std::string &arm_id)
 
bool put_diff (const table_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)
 
 summation_storage (bool assume_unrewarded)
 

Static Public Member Functions

static void mix (const table_t &lhs, table_t &rhs)
 

Private Attributes

std::vector< std::string > arm_ids_
 
const bool assume_unrewarded_
 
table_t mixed_
 
table_t unmixed_
 

Detailed Description

Definition at line 29 of file summation_storage.hpp.

Member Typedef Documentation

Definition at line 31 of file summation_storage.hpp.

Constructor & Destructor Documentation

jubatus::core::bandit::summation_storage::summation_storage ( bool  assume_unrewarded)
explicit

Definition at line 27 of file summation_storage.cpp.

28  : assume_unrewarded_(assume_unrewarded) {
29 }

Member Function Documentation

void jubatus::core::bandit::summation_storage::clear ( )
bool jubatus::core::bandit::summation_storage::delete_arm ( const std::string &  arm_id)

Definition at line 82 of file summation_storage.cpp.

References arm_ids_, mixed_, and unmixed_.

Referenced by jubatus::core::bandit::ucb1::delete_arm(), jubatus::core::bandit::epsilon_greedy::delete_arm(), jubatus::core::bandit::softmax::delete_arm(), and jubatus::core::bandit::exp3::delete_arm().

82  {
83  delete_arm_(mixed_, arm_id);
84  delete_arm_(unmixed_, arm_id);
85 
86  std::vector<std::string>::iterator iter =
87  std::remove(arm_ids_.begin(), arm_ids_.end(), arm_id);
88  if (iter == arm_ids_.end()) {
89  return false;
90  }
91  arm_ids_.erase(iter, arm_ids_.end());
92  return true;
93 }

Here is the caller graph for this function:

const std::vector<std::string>& jubatus::core::bandit::summation_storage::get_arm_ids ( ) const
inline
arm_info jubatus::core::bandit::summation_storage::get_arm_info ( const std::string &  player_id,
const std::string &  arm_id 
) const

Definition at line 137 of file summation_storage.cpp.

References mixed_, jubatus::core::bandit::arm_info::trial_count, unmixed_, and jubatus::core::bandit::arm_info::weight.

Referenced by jubatus::core::bandit::exp3::calc_weights_(), get_arm_info_map(), get_expectation(), and jubatus::core::bandit::ucb1::select_arm().

139  {
140  const arm_info a1 = get_arm_info_(mixed_, player_id, arm_id);
141  const arm_info a2 = get_arm_info_(unmixed_, player_id, arm_id);
142 
143  arm_info result;
144  result.trial_count = a1.trial_count + a2.trial_count;
145  result.weight = a1.weight + a2.weight;
146  return result;
147 }

Here is the caller graph for this function:

arm_info_map jubatus::core::bandit::summation_storage::get_arm_info_map ( const std::string &  player_id) const

Definition at line 159 of file summation_storage.cpp.

References arm_ids_, and get_arm_info().

Referenced by jubatus::core::bandit::ucb1::get_arm_info(), jubatus::core::bandit::epsilon_greedy::get_arm_info(), jubatus::core::bandit::softmax::get_arm_info(), and jubatus::core::bandit::exp3::get_arm_info().

160  {
161  arm_info_map result;
162 
163  for (std::vector<std::string>::const_iterator iter = arm_ids_.begin();
164  iter != arm_ids_.end(); ++iter) {
165  result.insert(std::make_pair(*iter, get_arm_info(player_id, *iter)));
166  }
167 
168  return result;
169 }
jubatus::util::data::unordered_map< std::string, arm_info > arm_info_map
Definition: arm_info.hpp:36
arm_info get_arm_info(const std::string &player_id, const std::string &arm_id) const

Here is the call graph for this function:

Here is the caller graph for this function:

void jubatus::core::bandit::summation_storage::get_diff ( table_t diff) const
double jubatus::core::bandit::summation_storage::get_expectation ( const std::string &  player_id,
const std::string &  arm_id 
) const

Definition at line 149 of file summation_storage.cpp.

References get_arm_info(), jubatus::core::bandit::arm_info::trial_count, and jubatus::core::bandit::arm_info::weight.

Referenced by jubatus::core::bandit::epsilon_greedy::select_arm(), and jubatus::core::bandit::softmax::select_arm().

151  {
152  const arm_info a = get_arm_info(player_id, arm_id);
153  if (a.trial_count == 0) {
154  return 0;
155  }
156  return a.weight / a.trial_count;
157 }
arm_info get_arm_info(const std::string &player_id, const std::string &arm_id) const

Here is the call graph for this function:

Here is the caller graph for this function:

void jubatus::core::bandit::summation_storage::mix ( const table_t lhs,
table_t rhs 
)
static

Definition at line 181 of file summation_storage.cpp.

References jubatus::core::bandit::arm_info::trial_count, and jubatus::core::bandit::arm_info::weight.

Referenced by jubatus::core::bandit::ucb1::mix(), jubatus::core::bandit::epsilon_greedy::mix(), jubatus::core::bandit::softmax::mix(), jubatus::core::bandit::exp3::mix(), and put_diff().

181  {
182  for (table_t::const_iterator iter = lhs.begin();
183  iter != lhs.end(); ++iter) {
184  arm_info_map& as0 = rhs[iter->first];
185  const arm_info_map& as1 = iter->second;
186  for (arm_info_map::const_iterator jter = as1.begin();
187  jter != as1.end(); ++jter) {
188  arm_info& a0 = as0[jter->first];
189  const arm_info& a1 = jter->second;
190  a0.trial_count += a1.trial_count;
191  a0.weight += a1.weight;
192  }
193  }
194 }
jubatus::util::data::unordered_map< std::string, arm_info > arm_info_map
Definition: arm_info.hpp:36

Here is the caller graph for this function:

jubatus::core::bandit::summation_storage::MSGPACK_DEFINE ( arm_ids_  ,
mixed_  ,
unmixed_   
)
void jubatus::core::bandit::summation_storage::notify_selected ( const std::string &  player_id,
const std::string &  arm_id 
)

Definition at line 95 of file summation_storage.cpp.

References arm_ids_, assume_unrewarded_, jubatus::core::bandit::arm_info::trial_count, and unmixed_.

Referenced by jubatus::core::bandit::ucb1::select_arm(), jubatus::core::bandit::epsilon_greedy::select_arm(), jubatus::core::bandit::softmax::select_arm(), and jubatus::core::bandit::exp3::select_arm().

97  {
98  if (!assume_unrewarded_) {
99  return;
100  }
101  arm_info& a = get_arm_info_(unmixed_, arm_ids_, player_id, arm_id);
102  a.trial_count += 1;
103 }

Here is the caller graph for this function:

bool jubatus::core::bandit::summation_storage::put_diff ( const table_t diff)

Definition at line 175 of file summation_storage.cpp.

References mix(), mixed_, and unmixed_.

Referenced by jubatus::core::bandit::ucb1::put_diff(), jubatus::core::bandit::epsilon_greedy::put_diff(), jubatus::core::bandit::softmax::put_diff(), and jubatus::core::bandit::exp3::put_diff().

175  {
176  mix(diff, mixed_);
177  unmixed_.clear();
178  return true;
179 }
static void mix(const table_t &lhs, table_t &rhs)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 31 of file summation_storage.cpp.

References arm_ids_, and unmixed_.

Referenced by jubatus::core::bandit::ucb1::register_arm(), jubatus::core::bandit::epsilon_greedy::register_arm(), jubatus::core::bandit::softmax::register_arm(), and jubatus::core::bandit::exp3::register_arm().

31  {
32  if (std::find(arm_ids_.begin(), arm_ids_.end(), arm_id) != arm_ids_.end()) {
33  // arm_id is already in arms_
34  return false;
35  }
36  arm_ids_.push_back(arm_id);
37  const arm_info a0 = {0, 0.0};
38  for (table_t::iterator iter = unmixed_.begin();
39  iter != unmixed_.end(); ++iter) {
40  arm_info_map& as = iter->second;
41  as.insert(std::make_pair(arm_id, a0));
42  }
43  return true;
44 }
jubatus::util::data::unordered_map< std::string, arm_info > arm_info_map
Definition: arm_info.hpp:36

Here is the caller graph for this function:

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

Definition at line 105 of file summation_storage.cpp.

References arm_ids_, assume_unrewarded_, jubatus::core::bandit::arm_info::trial_count, unmixed_, and jubatus::core::bandit::arm_info::weight.

Referenced by jubatus::core::bandit::ucb1::register_reward(), jubatus::core::bandit::epsilon_greedy::register_reward(), jubatus::core::bandit::softmax::register_reward(), and jubatus::core::bandit::exp3::register_reward().

108  {
109  arm_info& a = get_arm_info_(unmixed_, arm_ids_, player_id, arm_id);
110  if (!assume_unrewarded_) {
111  a.trial_count += 1;
112  }
113  a.weight += reward;
114  return true;
115 }

Here is the caller graph for this function:

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

Definition at line 196 of file summation_storage.cpp.

References mixed_, and unmixed_.

Referenced by jubatus::core::bandit::ucb1::reset(), jubatus::core::bandit::epsilon_greedy::reset(), jubatus::core::bandit::softmax::reset(), and jubatus::core::bandit::exp3::reset().

196  {
197  bool result1 = mixed_.erase(player_id) > 0;
198  bool result2 = unmixed_.erase(player_id) > 0;
199  return result1 || result2;
200 }

Here is the caller graph for this function:

Member Data Documentation

std::vector<std::string> jubatus::core::bandit::summation_storage::arm_ids_
private
const bool jubatus::core::bandit::summation_storage::assume_unrewarded_
private

Definition at line 64 of file summation_storage.hpp.

Referenced by notify_selected(), and register_reward().

table_t jubatus::core::bandit::summation_storage::mixed_
private

Definition at line 66 of file summation_storage.hpp.

Referenced by clear(), delete_arm(), get_arm_info(), put_diff(), and reset().

table_t jubatus::core::bandit::summation_storage::unmixed_
private

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