jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
regression.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,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 #include "regression.hpp"
18 
19 #include <map>
20 #include <string>
21 #include <utility>
22 
23 #include "../fv_converter/datum.hpp"
24 #include "../fv_converter/datum_to_fv_converter.hpp"
25 #include "../fv_converter/converter_config.hpp"
26 #include "../regression/regression_base.hpp"
27 #include "../storage/storage_factory.hpp"
28 
29 using std::string;
30 using std::pair;
31 using jubatus::util::lang::shared_ptr;
34 
35 namespace jubatus {
36 namespace core {
37 namespace driver {
38 
40  shared_ptr<storage::storage_base> model_storage,
41  shared_ptr<core::regression::regression_base> regression_method,
42  shared_ptr<fv_converter::datum_to_fv_converter> converter)
43  : converter_(converter)
44  , regression_(regression_method)
45  , mixable_regression_model_(regression_method->get_storage())
46  , wm_(mixable_weight_manager::model_ptr(new weight_manager)) {
49 
50  converter_->set_weight_manager(wm_.get_model());
51 }
52 
54 }
55 
56 void regression::train(const pair<float, fv_converter::datum>& data) {
58  converter_->convert_and_update_weight(data.second, v);
59  regression_->train(v, data.first);
60 }
61 
63  const fv_converter::datum& data) const {
65  converter_->convert(data, v);
66  float value = regression_->estimate(v);
67  return value;
68 }
69 
70 void regression::get_status(std::map<string, string>& status) const {
71  regression_->get_status(status);
72 }
73 
75  regression_->clear();
76  converter_->clear_weights();
77 }
78 
80  pk.pack_array(2);
81  regression_->get_storage()->pack(pk);
82  wm_.get_model()->pack(pk);
83 }
84 
85 void regression::unpack(msgpack::object o) {
86  if (o.type != msgpack::type::ARRAY || o.via.array.size != 2) {
87  throw msgpack::type_error();
88  }
89 
90  // clear before load
91  regression_->clear();
92  converter_->clear_weights();
93  regression_->get_storage()->unpack(o.via.array.ptr[0]);
94  wm_.get_model()->unpack(o.via.array.ptr[1]);
95 }
96 
97 } // namespace driver
98 } // namespace core
99 } // namespace jubatus
jubatus::util::lang::shared_ptr< jubatus::core::regression::regression_base > regression_
Definition: regression.hpp:65
float estimate(const fv_converter::datum &data) const
Definition: regression.cpp:62
void train(const std::pair< float, fv_converter::datum > &data)
Definition: regression.cpp:56
fv_converter::mixable_weight_manager wm_
Definition: regression.hpp:67
regression(jubatus::util::lang::shared_ptr< storage::storage_base > model_storage, jubatus::util::lang::shared_ptr< regression_base > regression_method, jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter)
Definition: regression.cpp:39
void pack(framework::packer &pk) const
Definition: regression.cpp:79
void get_status(std::map< std::string, std::string > &status) const
Definition: regression.cpp:70
framework::linear_mixable_helper< weight_manager, versioned_weight_diff > mixable_weight_manager
void unpack(msgpack::object o)
Definition: regression.cpp:85
std::vector< T > v(size)
framework::linear_function_mixer mixable_regression_model_
Definition: regression.hpp:66
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29
jubatus::util::lang::shared_ptr< fv_converter::datum_to_fv_converter > converter_
Definition: regression.hpp:63
void register_mixable(framework::mixable *mixable)
Definition: driver.cpp:242
storage::mixable_lsh_index_storage::model_ptr model_ptr
Definition: euclid_lsh.cpp:90