jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
Public Member Functions | Private Member Functions | Private Attributes | List of all members
jubatus::core::classifier::normal_herd Class Reference

#include <normal_herd.hpp>

Inheritance diagram for jubatus::core::classifier::normal_herd:
Inheritance graph
Collaboration diagram for jubatus::core::classifier::normal_herd:
Collaboration graph

Public Member Functions

std::string name () const
 
 normal_herd (storage_ptr storage)
 
 normal_herd (const classifier_config &config, storage_ptr storage)
 
void train (const common::sfv_t &fv, const std::string &label)
 
- Public Member Functions inherited from jubatus::core::classifier::linear_classifier
std::string classify (const common::sfv_t &fv) const
 
void classify_with_scores (const common::sfv_t &fv, classify_result &scores) const
 
void clear ()
 
bool delete_label (const std::string &label)
 
std::vector< std::string > get_labels () const
 
framework::mixableget_mixable ()
 
virtual void get_status (std::map< std::string, std::string > &status) const
 
jubatus::util::lang::shared_ptr< unlearner::unlearner_baselabel_unlearner () const
 
 linear_classifier (storage_ptr storage)
 
void pack (framework::packer &pk) const
 
bool set_label (const std::string &label)
 
void set_label_unlearner (jubatus::util::lang::shared_ptr< unlearner::unlearner_base > label_unlearner)
 
bool unlearn_label (const std::string &label)
 
void unpack (msgpack::object o)
 
virtual ~linear_classifier ()
 
- Public Member Functions inherited from jubatus::core::classifier::classifier_base
 classifier_base ()
 
virtual ~classifier_base ()
 

Private Member Functions

void update (const common::sfv_t &sfv, float margin, float variance, const std::string &pos_label, const std::string &neg_label)
 

Private Attributes

classifier_config config_
 

Additional Inherited Members

- Protected Member Functions inherited from jubatus::core::classifier::linear_classifier
float calc_margin (const common::sfv_t &sfv, const std::string &label, std::string &incorrect_label) const
 
float calc_margin_and_variance (const common::sfv_t &sfv, const std::string &label, std::string &incorrect_label, float &variance) const
 
void check_touchable (const std::string &label)
 
std::string get_largest_incorrect_label (const common::sfv_t &sfv, const std::string &label, classify_result &scores) const
 
void touch (const std::string &label)
 
void update_weight (const common::sfv_t &sfv, float step_weigth, const std::string &pos_label, const std::string &neg_class)
 
- Static Protected Member Functions inherited from jubatus::core::classifier::linear_classifier
static float squared_norm (const common::sfv_t &sfv)
 
- Protected Attributes inherited from jubatus::core::classifier::linear_classifier
framework::linear_function_mixer mixable_storage_
 
storage_ptr storage_
 
jubatus::util::lang::shared_ptr< unlearner::unlearner_baseunlearner_
 

Detailed Description

Definition at line 28 of file normal_herd.hpp.

Constructor & Destructor Documentation

jubatus::core::classifier::normal_herd::normal_herd ( storage_ptr  storage)
explicit
jubatus::core::classifier::normal_herd::normal_herd ( const classifier_config config,
storage_ptr  storage 
)

Definition at line 38 of file normal_herd.cpp.

References JUBATUS_EXCEPTION, and jubatus::core::classifier::classifier_config::regularization_weight.

41  : linear_classifier(storage),
42  config_(config) {
43 
44  if (!(0.f < config.regularization_weight)) {
45  throw JUBATUS_EXCEPTION(
46  common::invalid_parameter("0.0 < regularization_weight"));
47  }
48 }
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79

Member Function Documentation

std::string jubatus::core::classifier::normal_herd::name ( ) const
virtual

Implements jubatus::core::classifier::linear_classifier.

Definition at line 111 of file normal_herd.cpp.

111  {
112  return string("normal_herd");
113 }
void jubatus::core::classifier::normal_herd::train ( const common::sfv_t fv,
const std::string &  label 
)
virtual

Implements jubatus::core::classifier::linear_classifier.

Definition at line 50 of file normal_herd.cpp.

References jubatus::core::classifier::linear_classifier::calc_margin_and_variance(), jubatus::core::classifier::linear_classifier::check_touchable(), jubatus::core::classifier::linear_classifier::storage_, and update().

50  {
51  check_touchable(label);
52 
53  string incorrect_label;
54  float variance = 0.f;
55  float margin = -calc_margin_and_variance(sfv, label, incorrect_label,
56  variance);
57  if (margin >= 1.f) {
58  storage_->register_label(label);
59  return;
60  }
61  update(sfv, margin, variance, label, incorrect_label);
62 }
void update(const common::sfv_t &sfv, float margin, float variance, const std::string &pos_label, const std::string &neg_label)
Definition: normal_herd.cpp:64
float calc_margin_and_variance(const common::sfv_t &sfv, const std::string &label, std::string &incorrect_label, float &variance) const
void check_touchable(const std::string &label)

Here is the call graph for this function:

void jubatus::core::classifier::normal_herd::update ( const common::sfv_t sfv,
float  margin,
float  variance,
const std::string &  pos_label,
const std::string &  neg_label 
)
private

Definition at line 64 of file normal_herd.cpp.

References config_, jubatus::core::classifier::ClassifierUtil::get_two(), jubatus::core::classifier::classifier_config::regularization_weight, jubatus::core::classifier::linear_classifier::storage_, jubatus::core::classifier::linear_classifier::touch(), jubatus::core::storage::val2_t::v1, and jubatus::core::storage::val2_t::v2.

Referenced by train().

69  {
70  util::concurrent::scoped_lock lk(storage_->get_lock());
71  for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
72  const string& feature = it->first;
73  float val = it->second;
75  storage_->get2_nolock(feature, ret);
76 
77  storage::val2_t pos_val(0.f, 1.f);
78  storage::val2_t neg_val(0.f, 1.f);
79  ClassifierUtil::get_two(ret, pos_label, neg_label, pos_val, neg_val);
80 
81  float val_covariance_pos = val * pos_val.v2;
82  float val_covariance_neg = val * neg_val.v2;
83 
84  const float C = config_.regularization_weight;
85  storage_->set2_nolock(
86  feature,
87  pos_label,
88  storage::val2_t(
89  pos_val.v1
90  + (1.f - margin) * val_covariance_pos
91  / (variance + 1.f / C),
92  1.f
93  / ((1.f / pos_val.v2) + (2 * C + C * C * variance)
94  * val * val)));
95  if (neg_label != "") {
96  storage_->set2_nolock(
97  feature,
98  neg_label,
99  storage::val2_t(
100  neg_val.v1
101  - (1.f - margin) * val_covariance_neg
102  / (variance + 1.f / C),
103  1.f
104  / ((1.f / neg_val.v2) + (2 * C + C * C * variance)
105  * val * val)));
106  }
107  }
108  touch(pos_label);
109 }
static void get_two(const T &t, const std::string &label1, const std::string &label2, U &u1, U &u2)
std::vector< std::pair< std::string, val2_t > > feature_val2_t

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

classifier_config jubatus::core::classifier::normal_herd::config_
private

Definition at line 43 of file normal_herd.hpp.

Referenced by normal_herd(), and update().


The documentation for this class was generated from the following files: