Vowpal Wabbit
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Friends | List of all members
VW::LEARNER::learner Class Referencefinal

Defines the interface for a learning algorithm. More...

#include <learner.h>

Inheritance diagram for VW::LEARNER::learner:

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
 
learnerget_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 learnerget_base_learner () const
 
learnerget_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
 

Detailed Description

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.

Member Function Documentation

◆ add()

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 
)

◆ cleanup_example()

void VW::LEARNER::learner::cleanup_example ( polymorphic_ex  ec)

◆ end_examples()

void VW::LEARNER::learner::end_examples ( )

◆ end_pass()

void VW::LEARNER::learner::end_pass ( )

◆ finish()

void VW::LEARNER::learner::finish ( )

◆ finish_example()

void VW::LEARNER::learner::finish_example ( VW::workspace all,
polymorphic_ex  ec 
)

◆ get_base_learner() [1/2]

learner * VW::LEARNER::learner::get_base_learner ( )
inline

◆ get_base_learner() [2/2]

const learner * VW::LEARNER::learner::get_base_learner ( ) const
inline

◆ get_enabled_learners()

void VW::LEARNER::learner::get_enabled_learners ( std::vector< std::string > &  enabled_learners) const

◆ get_input_label_type()

label_type_t VW::LEARNER::learner::get_input_label_type ( ) const
inline

◆ get_input_prediction_type()

prediction_type_t VW::LEARNER::learner::get_input_prediction_type ( ) const
inline

◆ get_internal_type_erased_data_pointer_test_use_only()

void * VW::LEARNER::learner::get_internal_type_erased_data_pointer_test_use_only ( )
inline

◆ get_internal_type_erased_data_pointer_test_use_only_shared()

std::shared_ptr< void > VW::LEARNER::learner::get_internal_type_erased_data_pointer_test_use_only_shared ( )
inline

◆ get_learner_by_name_prefix()

learner * VW::LEARNER::learner::get_learner_by_name_prefix ( const std::string &  learner_name)

◆ get_name()

const std::string & VW::LEARNER::learner::get_name ( ) const
inline

◆ get_output_label_type()

label_type_t VW::LEARNER::learner::get_output_label_type ( ) const
inline

◆ get_output_prediction_type()

prediction_type_t VW::LEARNER::learner::get_output_prediction_type ( ) const
inline

◆ has_add()

bool VW::LEARNER::learner::has_add ( ) const
inline

◆ has_cleanup_example()

bool VW::LEARNER::learner::has_cleanup_example ( ) const
inline

◆ has_legacy_finish()

bool VW::LEARNER::learner::has_legacy_finish ( ) const
inline

◆ has_merge()

bool VW::LEARNER::learner::has_merge ( ) const
inline

◆ has_output_example_prediction()

bool VW::LEARNER::learner::has_output_example_prediction ( ) const
inline

◆ has_print_update()

bool VW::LEARNER::learner::has_print_update ( ) const
inline

◆ has_subtract()

bool VW::LEARNER::learner::has_subtract ( ) const
inline

◆ has_update_stats()

bool VW::LEARNER::learner::has_update_stats ( ) const
inline

◆ init_driver()

void VW::LEARNER::learner::init_driver ( )

◆ is_multiline()

bool VW::LEARNER::learner::is_multiline ( ) const
inline

◆ learn()

void VW::LEARNER::learner::learn ( polymorphic_ex  ec,
size_t  i = 0 
)

Will update the model according to the labels and examples supplied.

Parameters
ecThe 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.
iThis 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.
Returns
While some learner may fill the example::pred, this is not guaranteed and is undefined behavior if accessed.

◆ learner_defines_own_save_load()

bool VW::LEARNER::learner::learner_defines_own_save_load ( )
inline

◆ merge()

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 
)

◆ multipredict()

void VW::LEARNER::learner::multipredict ( polymorphic_ex  ec,
size_t  lo,
size_t  count,
polyprediction pred,
bool  finalize_predictions 
)

◆ output_example_prediction() [1/2]

void VW::LEARNER::learner::output_example_prediction ( VW::workspace all,
const polymorphic_ex  ec 
)

◆ output_example_prediction() [2/2]

void VW::LEARNER::learner::output_example_prediction ( VW::workspace all,
const polymorphic_ex  ec,
VW::io::logger logger 
)

◆ persist_metrics()

void VW::LEARNER::learner::persist_metrics ( metric_sink metrics)

◆ pre_save_load()

void VW::LEARNER::learner::pre_save_load ( VW::workspace all)

◆ predict()

void VW::LEARNER::learner::predict ( polymorphic_ex  ec,
size_t  i = 0 
)

Make a prediction for the given example.

Parameters
ecThe 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.
iThis 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.
Returns
The prediction calculated by this learner be set on example::pred. If the polymorphic_ex is multi_ex then the prediction is set on the 0th item in the list.

◆ print_update() [1/2]

void VW::LEARNER::learner::print_update ( VW::workspace all,
const polymorphic_ex  ec 
)

◆ print_update() [2/2]

void VW::LEARNER::learner::print_update ( VW::workspace all,
VW::shared_data sd,
const polymorphic_ex  ec,
VW::io::logger logger 
)

◆ save_load()

void VW::LEARNER::learner::save_load ( io_buf io,
const bool  read,
const bool  text 
)

◆ sensitivity()

float VW::LEARNER::learner::sensitivity ( example ec,
size_t  i = 0 
)

◆ set_internal_type_erased_data_pointer_does_not_override_funcs()

void VW::LEARNER::learner::set_internal_type_erased_data_pointer_does_not_override_funcs ( std::shared_ptr< void >  data)
inline

◆ subtract()

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 
)

◆ update()

void VW::LEARNER::learner::update ( polymorphic_ex  ec,
size_t  i = 0 
)

◆ update_stats() [1/2]

void VW::LEARNER::learner::update_stats ( const VW::workspace all,
VW::shared_data sd,
const polymorphic_ex  ec,
VW::io::logger logger 
)

◆ update_stats() [2/2]

void VW::LEARNER::learner::update_stats ( VW::workspace all,
const polymorphic_ex  ec 
)

Friends And Related Function Documentation

◆ bottom_learner_builder

template<class DataT , class ExampleT >
friend class bottom_learner_builder
friend

◆ common_learner_builder

template<class FluentBuilderT , class DataT , class ExampleT >
friend class common_learner_builder
friend

◆ reduction_learner_builder

template<class DataT , class ExampleT >
friend class reduction_learner_builder
friend

◆ reduction_no_data_learner_builder

template<class ExampleT >
friend class reduction_no_data_learner_builder
friend

Member Data Documentation

◆ feature_width

size_t VW::LEARNER::learner::feature_width = 1

◆ feature_width_below

size_t VW::LEARNER::learner::feature_width_below = 1

◆ learn_returns_prediction

bool VW::LEARNER::learner::learn_returns_prediction = false

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