jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
random_unlearner.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2013 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_UNLEARNER_RANDOM_UNLEARNER_HPP_
18 #define JUBATUS_CORE_UNLEARNER_RANDOM_UNLEARNER_HPP_
19 
20 #include <string>
21 #include <vector>
22 #include "jubatus/util/data/optional.h"
23 #include "jubatus/util/data/serialization.h"
24 #include "jubatus/util/data/unordered_map.h"
25 #include "jubatus/util/math/random.h"
26 #include "unlearner_base.hpp"
27 
28 namespace jubatus {
29 namespace core {
30 namespace unlearner {
31 
32 // Unlearner that chooses an item to be removed by uniformly random sampling.
34  public:
35  struct config {
36  int32_t max_size;
37  jubatus::util::data::optional<int64_t> seed;
38 
39  template<typename Ar>
40  void serialize(Ar& ar) {
41  ar & JUBA_MEMBER(max_size) & JUBA_MEMBER(seed);
42  }
43  };
44 
45  std::string type() const {
46  return "random_unlearner";
47  }
48 
49  void clear() {
50  id_map_.clear();
51  ids_.clear();
52  }
53 
54  explicit random_unlearner(const config& conf);
55 
56  bool can_touch(const std::string& id);
57  bool touch(const std::string& id);
58  bool remove(const std::string& id);
59  bool exists_in_memory(const std::string& id) const;
60 
61  private:
65  jubatus::util::data::unordered_map<std::string, size_t> id_map_;
66 
70  std::vector<std::string> ids_;
71 
75  size_t max_size_;
76 
80  jubatus::util::math::random::mtrand mtr_;
81 };
82 
83 } // namespace unlearner
84 } // namespace core
85 } // namespace jubatus
86 
87 #endif // JUBATUS_CORE_UNLEARNER_RANDOM_UNLEARNER_HPP_
88 
jubatus::util::math::random::mtrand mtr_
jubatus::util::data::optional< std::string > unlearner
bool exists_in_memory(const std::string &id) const
jubatus::util::data::unordered_map< std::string, size_t > id_map_
jubatus::util::data::optional< int64_t > seed