jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
num_filter_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_FILTER_IMPL_HPP_
18 #define JUBATUS_CORE_FV_CONVERTER_NUM_FILTER_IMPL_HPP_
19 
20 #include <cmath>
21 #include "num_filter.hpp"
22 #include "../common/exception.hpp"
23 #include "../common/assert.hpp"
24 
25 namespace jubatus {
26 namespace core {
27 namespace fv_converter {
28 
29 class add_filter : public num_filter {
30  public:
31  explicit add_filter(double value)
32  : value_(value) {
33  }
34 
35  double filter(double value) const {
36  return value + value_;
37  }
38 
39  private:
40  double value_;
41 };
42 
44  public:
46  double max,
47  bool truncate)
48  : min_(min), max_(max), truncate_(truncate) {
49  if (max_ <= min_) {
50  throw JUBATUS_EXCEPTION(
51  common::invalid_parameter("maximum must be bigger than mininum"));
52  }
53  }
54 
55  double filter(double value) const {
56  if (truncate_) {
57  if (max_ < value) {
58  return 1.0;
59  } else if (value < min_) {
60  return 0.0;
61  }
62  }
63  JUBATUS_ASSERT_LT(min_, max_, "maximum must be bigger than minimum");
64  return (value - min_) / (max_ - min_);
65  }
66 
67  private:
68  double min_;
69  double max_;
70  bool truncate_;
71 };
72 
74  public:
76  double standard_deviation)
77  : average_(average), standard_deviation_(standard_deviation) {
78  if (standard_deviation_ < 0) {
79  throw JUBATUS_EXCEPTION(
80  common::invalid_parameter("standard deviation must be non-negative"));
81  }
82  }
83 
84  double filter(double value) const {
85  return (value - average_) / standard_deviation_;
86  }
87  private:
88  double average_;
90 };
91 
93  public:
95  double bias)
96  : bias_(bias), gain_(gain) {
97  if (gain_ == 0.0) {
98  throw JUBATUS_EXCEPTION(
99  common::invalid_parameter("gain must not be zero"));
100  }
101  }
102 
103  double filter(double value) const {
104  return 1.0 / (1 + std::exp(-gain_ * (value - bias_)));
105  }
106 
107  private:
108  double bias_;
109  double gain_;
110 };
111 
112 } // namespace fv_converter
113 } // namespace core
114 } // namespace jubatus
115 
116 #endif // JUBATUS_CORE_FV_CONVERTER_NUM_FILTER_IMPL_HPP_
linear_normalization_filter(double min, double max, bool truncate)
double filter(double value) const
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79
gaussian_normalization_filter(double average, double standard_deviation)
#define JUBATUS_ASSERT_LT(a, b, messages)
Definition: assert.hpp:69