jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
Public Member Functions | Private Attributes | List of all members
jubatus::core::common::portable_mixer< Storage, Diff > Class Template Reference

#include <portable_mixer.hpp>

Collaboration diagram for jubatus::core::common::portable_mixer< Storage, Diff >:
Collaboration graph

Public Member Functions

void add (Storage *storage)
 
void clear ()
 
Storage * get_hash (const std::string &id) const
 
Storage * get_random ()
 
void mix ()
 
 portable_mixer ()
 
 portable_mixer (uint32_t seed)
 

Private Attributes

jubatus::util::math::random::mtrand rand_
 
std::vector< Storage * > storages_
 

Detailed Description

template<typename Storage, typename Diff = std::string>
class jubatus::core::common::portable_mixer< Storage, Diff >

Definition at line 30 of file portable_mixer.hpp.

Constructor & Destructor Documentation

template<typename Storage , typename Diff = std::string>
jubatus::core::common::portable_mixer< Storage, Diff >::portable_mixer ( )
inline

Definition at line 32 of file portable_mixer.hpp.

32  {
33  }
template<typename Storage , typename Diff = std::string>
jubatus::core::common::portable_mixer< Storage, Diff >::portable_mixer ( uint32_t  seed)
inlineexplicit

Definition at line 35 of file portable_mixer.hpp.

36  : rand_(seed) {
37  }
jubatus::util::math::random::mtrand rand_

Member Function Documentation

template<typename Storage , typename Diff = std::string>
void jubatus::core::common::portable_mixer< Storage, Diff >::add ( Storage *  storage)
inline

Definition at line 43 of file portable_mixer.hpp.

References jubatus::core::common::portable_mixer< Storage, Diff >::storages_.

43  {
44  storages_.push_back(storage);
45  }
std::vector< Storage * > storages_
template<typename Storage , typename Diff = std::string>
void jubatus::core::common::portable_mixer< Storage, Diff >::clear ( )
inline

Definition at line 39 of file portable_mixer.hpp.

References jubatus::core::common::portable_mixer< Storage, Diff >::storages_.

39  {
40  storages_.clear();
41  }
std::vector< Storage * > storages_
template<typename Storage , typename Diff = std::string>
Storage* jubatus::core::common::portable_mixer< Storage, Diff >::get_hash ( const std::string &  id) const
inline

Definition at line 51 of file portable_mixer.hpp.

References jubatus::core::common::hash_util::calc_string_hash(), and jubatus::core::common::portable_mixer< Storage, Diff >::storages_.

51  {
52  return storages_[hash_util::calc_string_hash(id) % storages_.size()];
53  }
std::vector< Storage * > storages_
static uint64_t calc_string_hash(const std::string &s)
Definition: hash.hpp:29

Here is the call graph for this function:

template<typename Storage , typename Diff = std::string>
Storage* jubatus::core::common::portable_mixer< Storage, Diff >::get_random ( )
inline
template<typename Storage , typename Diff = std::string>
void jubatus::core::common::portable_mixer< Storage, Diff >::mix ( )
inline

Definition at line 55 of file portable_mixer.hpp.

References jubatus::core::common::portable_mixer< Storage, Diff >::storages_.

55  {
56  if (storages_.empty()) {
57  return;
58  }
59 
60  Diff mixed;
61  storages_[0]->get_diff(mixed);
62 
63  for (size_t i = 1; i < storages_.size(); ++i) {
64  Diff diff;
65  storages_[i]->get_diff(diff);
66  storages_[0]->mix(diff, mixed);
67  }
68 
69  for (size_t i = 0; i < storages_.size(); ++i) {
70  storages_[i]->put_diff(mixed);
71  }
72  }
std::vector< Storage * > storages_

Member Data Documentation

template<typename Storage , typename Diff = std::string>
jubatus::util::math::random::mtrand jubatus::core::common::portable_mixer< Storage, Diff >::rand_
private
template<typename Storage , typename Diff = std::string>
std::vector<Storage*> jubatus::core::common::portable_mixer< Storage, Diff >::storages_
private

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