jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
keyword_weights.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2012 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_FV_CONVERTER_KEYWORD_WEIGHTS_HPP_
18 #define JUBATUS_CORE_FV_CONVERTER_KEYWORD_WEIGHTS_HPP_
19 
20 #include <string>
21 #include <msgpack.hpp>
22 #include "jubatus/util/data/unordered_map.h"
23 #include "../common/type.hpp"
24 #include "counter.hpp"
25 
26 namespace jubatus {
27 namespace core {
28 namespace fv_converter {
29 
31  public:
33 
35 
36  size_t get_document_frequency(const std::string& key) const {
37  return document_frequencies_[key];
38  }
39 
40  uint64_t get_document_count() const {
41  return document_count_;
42  }
43 
44  void add_weight(const std::string& key, float weight);
45 
46  float get_user_weight(const std::string& key) const;
47 
48  void merge(const keyword_weights& w);
49 
50  void clear();
51 
53 
54  std::string to_string() const;
55 
56  private:
57  double get_global_weight(const std::string& key) const;
58 
59  uint64_t document_count_;
61  typedef jubatus::util::data::unordered_map<std::string, float> weight_t;
62  weight_t weights_;
63 };
64 
65 } // namespace fv_converter
66 } // namespace core
67 } // namespace jubatus
68 
69 #endif // JUBATUS_CORE_FV_CONVERTER_KEYWORD_WEIGHTS_HPP_
jubatus::util::data::unordered_map< std::string, float > weight_t
float get_user_weight(const std::string &key) const
MSGPACK_DEFINE(document_count_, document_frequencies_, weights_)
double get_global_weight(const std::string &key) const
void update_document_frequency(const common::sfv_t &fv)
void add_weight(const std::string &key, float weight)
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
size_t get_document_frequency(const std::string &key) const