jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
perceptron.cpp
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 #include "perceptron.hpp"
18 
19 #include <string>
20 
21 using std::string;
22 
23 namespace jubatus {
24 namespace core {
25 namespace classifier {
26 
28  : linear_classifier(storage) {
29 }
30 
31 void perceptron::train(const common::sfv_t& sfv, const std::string& label) {
32  check_touchable(label);
33 
34  std::string predicted_label = classify(sfv);
35  if (label == predicted_label) {
36  return;
37  }
38  update_weight(sfv, 1.f, label, predicted_label);
39  touch(label);
40 }
41 
42 string perceptron::name() const {
43  return string("perceptron");
44 }
45 
46 } // namespace classifier
47 } // namespace core
48 } // namespace jubatus
jubatus::util::lang::shared_ptr< jubatus::core::storage::storage_base > storage_ptr
void train(const common::sfv_t &sfv, const std::string &label)
Definition: perceptron.cpp:31
void check_touchable(const std::string &label)
std::string classify(const common::sfv_t &fv) const
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
void update_weight(const common::sfv_t &sfv, float step_weigth, const std::string &pos_label, const std::string &neg_class)