jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
inverted_index_storage.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011 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_STORAGE_INVERTED_INDEX_STORAGE_HPP_
18 #define JUBATUS_CORE_STORAGE_INVERTED_INDEX_STORAGE_HPP_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include <msgpack.hpp>
24 #include "jubatus/util/data/unordered_map.h"
25 #include "storage_type.hpp"
26 #include "../common/version.hpp"
27 #include "../common/type.hpp"
28 #include "../common/unordered_map.hpp"
29 #include "../common/key_manager.hpp"
30 #include "../framework/mixable_helper.hpp"
32 
33 namespace jubatus {
34 namespace core {
35 namespace storage {
36 
38  public:
39  struct diff_type {
42 
43  MSGPACK_DEFINE(inv, column2norm);
44  };
45 
48 
49  void set(const std::string& row, const std::string& column, float val);
50  float get(const std::string& row, const std::string& column) const;
51  void remove(const std::string& row, const std::string& column);
52  void clear();
53  void get_all_column_ids(std::vector<std::string>& ids) const;
54 
55  void calc_scores(
56  const common::sfv_t& sfv,
57  std::vector<std::pair<std::string, float> >& scores,
58  size_t ret_num) const;
59 
60  void get_diff(diff_type& diff_str) const;
61  bool put_diff(const diff_type& mixed_diff);
62  void mix(const diff_type& lhs_str, diff_type& rhs_str) const;
63 
65  return storage::version();
66  }
67 
68  std::string name() const;
69 
70  void pack(framework::packer& packer) const;
71  void unpack(msgpack::object o);
72 
74 
75  private:
76  static float calc_l2norm(const common::sfv_t& sfv);
77  float calc_columnl2norm(uint64_t column_id) const;
78  float get_from_tbl(
79  const std::string& row,
80  uint64_t column_id,
81  const tbl_t& tbl,
82  bool& exist) const;
83 
84  void add_inp_scores(
85  const std::string& row,
86  float val,
87  std::vector<float>& scores) const;
88 
94 };
95 
99 
100 } // namespace storage
101 } // namespace core
102 } // namespace jubatus
103 
104 #endif // JUBATUS_CORE_STORAGE_INVERTED_INDEX_STORAGE_HPP_
MSGPACK_DEFINE(inv_, inv_diff_, column2norm_, column2norm_diff_, column2id_)
void calc_scores(const common::sfv_t &sfv, std::vector< std::pair< std::string, float > > &scores, size_t ret_num) const
void set(const std::string &row, const std::string &column, float val)
framework::linear_mixable_helper< inverted_index_storage, inverted_index_storage::diff_type > mixable_inverted_index_storage
void pack(framework::packer &packer) const
float get_from_tbl(const std::string &row, uint64_t column_id, const tbl_t &tbl, bool &exist) const
jubatus::util::data::unordered_map< uint64_t, float > imap_float_t
static float calc_l2norm(const common::sfv_t &sfv)
msgpack::packer< jubatus_packer > packer
Definition: bandit_base.hpp:31
jubatus::util::data::unordered_map< std::string, float > map_float_t
void get_all_column_ids(std::vector< std::string > &ids) const
jubatus::util::data::unordered_map< std::string, row_t > tbl_t
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
void mix(const diff_type &lhs_str, diff_type &rhs_str) const
void add_inp_scores(const std::string &row, float val, std::vector< float > &scores) const