jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
num_feature_impl.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_FV_CONVERTER_NUM_FEATURE_IMPL_HPP_
18 #define JUBATUS_CORE_FV_CONVERTER_NUM_FEATURE_IMPL_HPP_
19 
20 #include <algorithm>
21 #include <cmath>
22 #include <sstream>
23 #include <string>
24 #include <utility>
25 #include "../common/type.hpp"
26 #include "num_feature.hpp"
27 
28 namespace jubatus {
29 namespace core {
30 namespace fv_converter {
31 
33  public:
34  void add_feature(const std::string& key,
35  double value,
36  common::sfv_t& ret_fv) const {
37  ret_fv.push_back(std::make_pair(key, static_cast<float>(value)));
38  }
39 };
40 
42  public:
43  void add_feature(const std::string& key,
44  double value,
45  common::sfv_t& ret_fv) const {
46  std::stringstream ss;
47  ss << key << "$" << value;
48  ret_fv.push_back(std::make_pair(ss.str(), static_cast<float>(1.0)));
49  }
50 };
51 
52 class num_log_feature : public num_feature {
53  public:
54  void add_feature(const std::string& key,
55  double value,
56  common::sfv_t& ret_fv) const {
57  ret_fv.push_back(std::make_pair(
58  key,
59  static_cast<float>(std::log(std::max(1.0, value)))));
60  }
61 };
62 
63 } // namespace fv_converter
64 } // namespace core
65 } // namespace jubatus
66 
67 #endif // JUBATUS_CORE_FV_CONVERTER_NUM_FEATURE_IMPL_HPP_
void add_feature(const std::string &key, double value, common::sfv_t &ret_fv) const
void add_feature(const std::string &key, double value, common::sfv_t &ret_fv) const
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
void add_feature(const std::string &key, double value, common::sfv_t &ret_fv) const