22 #include "../common/exception.hpp"
23 #include "../common/jsonconfig.hpp"
24 #include "../storage/storage_base.hpp"
25 #include "../unlearner/unlearner_factory.hpp"
26 #include "../nearest_neighbor/nearest_neighbor_factory.hpp"
30 using jubatus::util::lang::shared_ptr;
34 namespace classifier {
37 struct unlearner_config {
38 jubatus::util::data::optional<std::string>
unlearner;
43 ar & JUBA_MEMBER(unlearner) & JUBA_MEMBER(unlearner_parameter);
47 struct unlearning_classifier_config
48 :
public classifier_config, unlearner_config {
56 struct nearest_neighbor_classifier_config
57 :
public unlearner_config {
65 ar & JUBA_MEMBER(method)
66 & JUBA_MEMBER(parameter)
67 & JUBA_MEMBER(nearest_neighbor_num)
68 & JUBA_MEMBER(local_sensitivity);
73 jubatus::util::lang::shared_ptr<unlearner::unlearner_base>
76 if (!conf.unlearner_parameter) {
78 "Unlearner is set but unlearner_parameter is not found"));
81 *conf.unlearner, *conf.unlearner_parameter);
83 return jubatus::util::lang::shared_ptr<unlearner::unlearner_base>();
90 const std::string& name,
92 jubatus::util::lang::shared_ptr<storage::storage_base> storage) {
93 jubatus::util::lang::shared_ptr<unlearner::unlearner_base>
unlearner;
94 shared_ptr<classifier_base> res;
95 if (name ==
"perceptron") {
97 if (param.
type() != jubatus::util::text::json::json::Null) {
98 unlearner_config conf = config_cast_check<unlearner_config>(param);
102 }
else if (name ==
"PA" || name ==
"passive_aggressive") {
104 if (param.
type() != jubatus::util::text::json::json::Null) {
105 unlearner_config conf = config_cast_check<unlearner_config>(param);
109 }
else if (name ==
"PA1" || name ==
"passive_aggressive_1") {
110 if (param.
type() == jubatus::util::text::json::json::Null) {
113 "parameter block is not specified in config"));
115 unlearning_classifier_config conf
116 = config_cast_check<unlearning_classifier_config>(param);
119 }
else if (name ==
"PA2" || name ==
"passive_aggressive_2") {
120 if (param.
type() == jubatus::util::text::json::json::Null) {
123 "parameter block is not specified in config"));
125 unlearning_classifier_config conf
126 = config_cast_check<unlearning_classifier_config>(param);
129 }
else if (name ==
"CW" || name ==
"confidence_weighted") {
130 if (param.
type() == jubatus::util::text::json::json::Null) {
133 "parameter block is not specified in config"));
135 unlearning_classifier_config conf
136 = config_cast_check<unlearning_classifier_config>(param);
139 }
else if (name ==
"AROW" || name ==
"arow") {
140 if (param.
type() == jubatus::util::text::json::json::Null) {
143 "parameter block is not specified in config"));
145 unlearning_classifier_config conf
146 = config_cast_check<unlearning_classifier_config>(param);
148 res.reset(
new arow(conf, storage));
149 }
else if (name ==
"NHERD" || name ==
"normal_herd") {
150 if (param.
type() == jubatus::util::text::json::json::Null) {
153 "parameter block is not specified in config"));
155 unlearning_classifier_config conf
156 = config_cast_check<unlearning_classifier_config>(param);
159 }
else if (name ==
"NN" || name ==
"nearest_neighbor") {
160 if (param.
type() == jubatus::util::text::json::json::Null) {
163 "parameter block is not specified in config"));
165 nearest_neighbor_classifier_config conf
166 = config_cast_check<nearest_neighbor_classifier_config>(param);
169 shared_ptr<nearest_neighbor::nearest_neighbor_base>
171 conf.method, conf.parameter, table,
""));
174 conf.nearest_neighbor_num,
175 conf.local_sensitivity));
182 res->set_label_unlearner(unlearner);
T config_cast_check(const config &c)
void serialize(member_collector &mem, jubatus::util::data::serialization::named_value< T > &v)
static jubatus::util::lang::shared_ptr< classifier_base > create_classifier(const std::string &name, const common::jsonconfig::config ¶m, jubatus::util::lang::shared_ptr< storage::storage_base > storage)
shared_ptr< unlearner_base > create_unlearner(const std::string &name, const common::jsonconfig::config &config)
jubatus::util::data::optional< std::string > unlearner
jubatus::util::text::json::json::json_type_t type() const
#define JUBATUS_EXCEPTION(e)
jubatus::util::data::optional< config > unlearner_parameter
shared_ptr< nearest_neighbor_base > create_nearest_neighbor(const std::string &name, const common::jsonconfig::config &config, shared_ptr< storage::column_table > table, const std::string &id)