-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KUMAZAKI Hiroki
committed
Mar 23, 2015
1 parent
bc14cd1
commit 9771cc0
Showing
27 changed files
with
259 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Jubatus: Online machine learning framework for distributed environment | ||
// Copyright (C) 2012 Preferred Networks and Nippon Telegraph and Telephone Corporation. | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License version 2.1 as published by the Free Software Foundation. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
#include "classifier_config.hpp" | ||
|
||
#include "jubatus/util/data/serialization.h" | ||
#include "jubatus/util/data/optional.h" | ||
#include "jubatus/util/lang/shared_ptr.h" | ||
#include "../common/jsonconfig.hpp" | ||
#include "../unlearner/unlearner_config.hpp" | ||
#include "../storage/column_table.hpp" | ||
#include "../nearest_neighbor/nearest_neighbor_base.hpp" | ||
|
||
using jubatus::util::lang::shared_ptr; | ||
|
||
namespace jubatus { | ||
namespace core { | ||
namespace classifier { | ||
classifier_config::classifier_config(const std::string& method, | ||
const common::jsonconfig::config& param) { | ||
typedef util::lang::shared_ptr<detail::classifier_config_base> conf_ptr; | ||
|
||
if (method == "perceptron" || | ||
method == "PA" || method == "passive_aggressive") { | ||
// perceptron passive_aggressive doesn't have parameter | ||
conf_ = conf_ptr(new classifier_parameter( | ||
common::config::config_cast_check<unlearning_classifier_config>(param))); | ||
} else if (name == "PA1" || name == "passive_aggressive_1") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
} | ||
|
||
unlearning_classifier_conf_ conf | ||
= config_cast_check<unlearning_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
res.reset(new passive_aggressive_1(conf, storage)); | ||
} else if (name == "PA2" || name == "passive_aggressive_2") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
} | ||
unlearning_classifier_config conf | ||
= config_cast_check<unlearning_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
res.reset(new passive_aggressive_2(conf, storage)); | ||
} else if (name == "CW" || name == "confidence_weighted") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
} | ||
unlearning_classifier_config conf | ||
= config_cast_check<unlearning_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
res.reset(new confidence_weighted(conf, storage)); | ||
} else if (name == "AROW" || name == "arow") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
} | ||
unlearning_classifier_config conf | ||
= config_cast_check<unlearning_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
res.reset(new arow(conf, storage)); | ||
} else if (name == "NHERD" || name == "normal_herd") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
|
||
} | ||
unlearning_classifier_config conf | ||
= config_cast_check<unlearning_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
res.reset(new normal_herd(conf, storage)); | ||
} else if (name == "NN" || name == "nearest_neighbor") { | ||
if (param.type() == jubatus::util::text::json::json::Null) { | ||
throw JUBATUS_EXCEPTION( | ||
common::config_exception() << common::exception::error_message( | ||
"parameter block is not specified in config")); | ||
} | ||
nearest_neighbor_classifier_config conf | ||
= config_cast_check<nearest_neighbor_classifier_config>(param); | ||
unlearner = create_unlearner(conf); | ||
shared_ptr<storage::column_table> table(new storage::column_table); | ||
shared_ptr<nearest_neighbor::nearest_neighbor_base> | ||
nearest_neighbor_engine(nearest_neighbor::create_nearest_neighbor( | ||
conf.method, conf.parameter, table, "")); | ||
res.reset( | ||
new nearest_neighbor_classifier(nearest_neighbor_engine, | ||
conf.nearest_neighbor_num, | ||
conf.local_sensitivity)); | ||
} else { | ||
throw JUBATUS_EXCEPTION( | ||
common::unsupported_method("classifier(" + name + ")")); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace classifier | ||
} // namespace core | ||
} // namespace jubatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.