Vowpal Wabbit
|
Defines the interface for a learning algorithm. More...
#include <learner.h>
Public Member Functions | |
void * | get_internal_type_erased_data_pointer_test_use_only () |
std::shared_ptr< void > | get_internal_type_erased_data_pointer_test_use_only_shared () |
void | set_internal_type_erased_data_pointer_does_not_override_funcs (std::shared_ptr< void > data) |
void | learn (polymorphic_ex ec, size_t i=0) |
Will update the model according to the labels and examples supplied. More... | |
void | predict (polymorphic_ex ec, size_t i=0) |
Make a prediction for the given example. More... | |
void | multipredict (polymorphic_ex ec, size_t lo, size_t count, polyprediction *pred, bool finalize_predictions) |
void | update (polymorphic_ex ec, size_t i=0) |
float | sensitivity (example &ec, size_t i=0) |
void | save_load (io_buf &io, const bool read, const bool text) |
void | pre_save_load (VW::workspace &all) |
void | persist_metrics (metric_sink &metrics) |
void | finish () |
void | end_pass () |
void | end_examples () |
void | init_driver () |
void | finish_example (VW::workspace &all, polymorphic_ex ec) |
void | update_stats (const VW::workspace &all, VW::shared_data &sd, const polymorphic_ex ec, VW::io::logger &logger) |
void | update_stats (VW::workspace &all, const polymorphic_ex ec) |
void | output_example_prediction (VW::workspace &all, const polymorphic_ex ec, VW::io::logger &logger) |
void | output_example_prediction (VW::workspace &all, const polymorphic_ex ec) |
void | print_update (VW::workspace &all, VW::shared_data &sd, const polymorphic_ex ec, VW::io::logger &logger) |
void | print_update (VW::workspace &all, const polymorphic_ex ec) |
void | cleanup_example (polymorphic_ex ec) |
void | get_enabled_learners (std::vector< std::string > &enabled_learners) const |
learner * | get_learner_by_name_prefix (const std::string &learner_name) |
void | merge (const std::vector< float > &per_model_weighting, const std::vector< const VW::workspace * > &all_workspaces, const std::vector< const learner * > &all_learners, VW::workspace &output_workspace, learner &output_learner) |
void | add (const VW::workspace &base_ws, const VW::workspace &delta_ws, const learner *base_l, const learner *delta_l, VW::workspace &output_ws, learner *output_l) |
void | subtract (const VW::workspace &ws1, const VW::workspace &ws2, const learner *l1, const learner *l2, VW::workspace &output_ws, learner *output_l) |
bool | has_legacy_finish () const |
bool | has_update_stats () const |
bool | has_print_update () const |
bool | has_output_example_prediction () const |
bool | has_cleanup_example () const |
bool | has_merge () const |
bool | has_add () const |
bool | has_subtract () const |
prediction_type_t | get_output_prediction_type () const |
prediction_type_t | get_input_prediction_type () const |
label_type_t | get_output_label_type () const |
label_type_t | get_input_label_type () const |
bool | is_multiline () const |
const std::string & | get_name () const |
const learner * | get_base_learner () const |
learner * | get_base_learner () |
bool | learner_defines_own_save_load () |
Public Attributes | |
size_t | feature_width = 1 |
size_t | feature_width_below = 1 |
bool | learn_returns_prediction = false |
Friends | |
template<class FluentBuilderT , class DataT , class ExampleT > | |
class | common_learner_builder |
template<class DataT , class ExampleT > | |
class | bottom_learner_builder |
template<class DataT , class ExampleT > | |
class | reduction_learner_builder |
template<class ExampleT > | |
class | reduction_no_data_learner_builder |
Defines the interface for a learning algorithm.
VW has two types of learners: reduction learners and bottom learners. The same learner class is used to implement both. A reduction stack is created as a chain of learners, starting from a bottom learner at the bottom of the stack. Each learner after it is a reduction learner and holds a shared_ptr to its base, the learner immediately below it in the stack. The final VW workspace holds a shared_ptr to the topmost learner. The difference between a reduction and a bottom learner is that a reduction will recursively call its base, whereas a bottom learner has no base and will simply return its result.
The learner class is not meant to be inherited from. Instead, it implements a sort of virtual inheritance via std::function objects. Each type of learner can have its own data object that stores the learner's internal state. When a learner is created, the function objects are bound to the data object, and the data object is stored in a std::shared_ptr<void>. The end result is that the data type representing the learner's state is type-erased, thus allowing for arbitrary learner types to be implemented by the same learner class.
The learner class itself has a private constructor. Learners should be created only through the make_reduction_learner and make_bottom_learner functions and their associated learner builder template classes. The templates enforce consistency of types at compile time, before types-erasure occurs to make the acutal learner object.
void VW::LEARNER::learner::add | ( | const VW::workspace & | base_ws, |
const VW::workspace & | delta_ws, | ||
const learner * | base_l, | ||
const learner * | delta_l, | ||
VW::workspace & | output_ws, | ||
learner * | output_l | ||
) |
void VW::LEARNER::learner::cleanup_example | ( | polymorphic_ex | ec | ) |
void VW::LEARNER::learner::end_examples | ( | ) |
void VW::LEARNER::learner::end_pass | ( | ) |
void VW::LEARNER::learner::finish | ( | ) |
void VW::LEARNER::learner::finish_example | ( | VW::workspace & | all, |
polymorphic_ex | ec | ||
) |
|
inline |
|
inline |
void VW::LEARNER::learner::get_enabled_learners | ( | std::vector< std::string > & | enabled_learners | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
learner * VW::LEARNER::learner::get_learner_by_name_prefix | ( | const std::string & | learner_name | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void VW::LEARNER::learner::init_driver | ( | ) |
|
inline |
void VW::LEARNER::learner::learn | ( | polymorphic_ex | ec, |
size_t | i = 0 |
||
) |
Will update the model according to the labels and examples supplied.
ec | The example object or multi_ex to be operated on. This object must have a valid label set for every example in the field example::l that corresponds to the type this learner expects. |
i | This is the offset used for the feature_width in this call. If using multiple regressors/learners you can feature_width_below this value for each call. |
|
inline |
void VW::LEARNER::learner::merge | ( | const std::vector< float > & | per_model_weighting, |
const std::vector< const VW::workspace * > & | all_workspaces, | ||
const std::vector< const learner * > & | all_learners, | ||
VW::workspace & | output_workspace, | ||
learner & | output_learner | ||
) |
void VW::LEARNER::learner::multipredict | ( | polymorphic_ex | ec, |
size_t | lo, | ||
size_t | count, | ||
polyprediction * | pred, | ||
bool | finalize_predictions | ||
) |
void VW::LEARNER::learner::output_example_prediction | ( | VW::workspace & | all, |
const polymorphic_ex | ec | ||
) |
void VW::LEARNER::learner::output_example_prediction | ( | VW::workspace & | all, |
const polymorphic_ex | ec, | ||
VW::io::logger & | logger | ||
) |
void VW::LEARNER::learner::persist_metrics | ( | metric_sink & | metrics | ) |
void VW::LEARNER::learner::pre_save_load | ( | VW::workspace & | all | ) |
void VW::LEARNER::learner::predict | ( | polymorphic_ex | ec, |
size_t | i = 0 |
||
) |
Make a prediction for the given example.
ec | The example object or multi_ex to be operated on. This object must have a valid prediction allocated in the field example::pred that corresponds to this learner type. |
i | This is the offset used for the feature_width in this call. If using multiple regressors/learners you can feature_width_below this value for each call. |
void VW::LEARNER::learner::print_update | ( | VW::workspace & | all, |
const polymorphic_ex | ec | ||
) |
void VW::LEARNER::learner::print_update | ( | VW::workspace & | all, |
VW::shared_data & | sd, | ||
const polymorphic_ex | ec, | ||
VW::io::logger & | logger | ||
) |
void VW::LEARNER::learner::save_load | ( | io_buf & | io, |
const bool | read, | ||
const bool | text | ||
) |
float VW::LEARNER::learner::sensitivity | ( | example & | ec, |
size_t | i = 0 |
||
) |
|
inline |
void VW::LEARNER::learner::subtract | ( | const VW::workspace & | ws1, |
const VW::workspace & | ws2, | ||
const learner * | l1, | ||
const learner * | l2, | ||
VW::workspace & | output_ws, | ||
learner * | output_l | ||
) |
void VW::LEARNER::learner::update | ( | polymorphic_ex | ec, |
size_t | i = 0 |
||
) |
void VW::LEARNER::learner::update_stats | ( | const VW::workspace & | all, |
VW::shared_data & | sd, | ||
const polymorphic_ex | ec, | ||
VW::io::logger & | logger | ||
) |
void VW::LEARNER::learner::update_stats | ( | VW::workspace & | all, |
const polymorphic_ex | ec | ||
) |
|
friend |
|
friend |
|
friend |
|
friend |
size_t VW::LEARNER::learner::feature_width = 1 |
size_t VW::LEARNER::learner::feature_width_below = 1 |
bool VW::LEARNER::learner::learn_returns_prediction = false |