Vowpal Wabbit
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
VW::LEARNER::learner< T, E > Struct Template Reference

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

#include <reductions_fwd.h>

Public Types

using end_fptr_type = void(*)(VW::workspace &, void *, void *)
 
using finish_fptr_type = void(*)(void *)
 

Public Member Functions

void * get_internal_type_erased_data_pointer_test_use_only ()
 
void learn (E &ec, size_t i=0)
 Will update the model according to the labels and examples supplied. More...
 
void predict (E &ec, size_t i=0)
 Make a prediction for the given example. More...
 
void multipredict (E &ec, size_t lo, size_t count, polyprediction *pred, bool finalize_predictions)
 
void update (E &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 persist_metrics (metric_sink &metrics)
 
void finish ()
 
void end_pass ()
 
void end_examples ()
 
void init_driver ()
 
void finish_example (VW::workspace &all, E &ec)
 
void print_example (VW::workspace &all, E &ec)
 
void get_enabled_reductions (std::vector< std::string > &enabled_reductions) const
 
base_learnerget_learner_by_name_prefix (const std::string &reduction_name)
 
prediction_type_t get_output_prediction_type ()
 
prediction_type_t get_input_prediction_type ()
 
label_type_t get_output_label_type ()
 
label_type_t get_input_label_type ()
 
bool is_multiline ()
 
const std::string & get_name ()
 

Public Attributes

size_t weights
 
size_t increment
 
bool learn_returns_prediction = false
 

Friends

template<class FluentBuilderT , class DataT , class ExampleT , class BaseLearnerT >
struct common_learner_builder
 
template<class DataT , class ExampleT >
struct base_learner_builder
 
template<class DataT , class ExampleT , class BaseLearnerT >
struct reduction_learner_builder
 
template<class ExampleT , class BaseLearnerT >
struct reduction_no_data_learner_builder
 

Detailed Description

template<class T, class E>
struct VW::LEARNER::learner< T, E >

Defines the interface for a learning algorithm.

Learner is implemented as a struct of pointers, and associated methods. It implements a sort of virtual inheritance through the use of bundling function pointers with the associated objects to call them with. A reduction will recursively call the base given to it, whereas a base learner will not recurse and will simply return the result. Learner is not intended to be inherited from. Instead it is used through composition, and created through the make_reduction_learner and make_base_learner. The state of this learner, or reduction, is stored in the learner_data field. A std::shared_pointer<void> is used as this class uses type erasure to allow for an arbitrary reduction to be implemented. It is extremely important that the function pointers given to the class match the expected types of the object. If the learner is constructed using make_reduction_learner or make_base_learner and assembled before it is transformed into a VW::LEARNER::base_learner with VW::LEARNER::make_base then the usage of the templated functions should ensure types are correct.

Template Parameters
TType of the reduction data object stored. This allows this specific reduction to have it's own state.
EExample type this reduction supports. Must be one of example or multi_ex

Member Typedef Documentation

◆ end_fptr_type

template<class T, class E>
using VW::LEARNER::learner< T, E >::end_fptr_type = void (*)(VW::workspace&, void*, void*)

◆ finish_fptr_type

template<class T, class E>
using VW::LEARNER::learner< T, E >::finish_fptr_type = void (*)(void*)

Member Function Documentation

◆ end_examples()

template<class T, class E>
void VW::LEARNER::learner< T, E >::end_examples ( )
inline

◆ end_pass()

template<class T, class E>
void VW::LEARNER::learner< T, E >::end_pass ( )
inline

◆ finish()

template<class T, class E>
void VW::LEARNER::learner< T, E >::finish ( )
inline

◆ finish_example()

template<class T, class E>
void VW::LEARNER::learner< T, E >::finish_example ( VW::workspace all,
E &  ec 
)
inline

◆ get_enabled_reductions()

template<class T, class E>
void VW::LEARNER::learner< T, E >::get_enabled_reductions ( std::vector< std::string > &  enabled_reductions) const
inline

◆ get_input_label_type()

template<class T, class E>
label_type_t VW::LEARNER::learner< T, E >::get_input_label_type ( )
inline

◆ get_input_prediction_type()

template<class T, class E>
prediction_type_t VW::LEARNER::learner< T, E >::get_input_prediction_type ( )
inline

◆ get_internal_type_erased_data_pointer_test_use_only()

template<class T, class E>
void* VW::LEARNER::learner< T, E >::get_internal_type_erased_data_pointer_test_use_only ( )
inline

◆ get_learner_by_name_prefix()

template<class T, class E>
base_learner* VW::LEARNER::learner< T, E >::get_learner_by_name_prefix ( const std::string &  reduction_name)
inline

◆ get_name()

template<class T, class E>
const std::string& VW::LEARNER::learner< T, E >::get_name ( )
inline

◆ get_output_label_type()

template<class T, class E>
label_type_t VW::LEARNER::learner< T, E >::get_output_label_type ( )
inline

◆ get_output_prediction_type()

template<class T, class E>
prediction_type_t VW::LEARNER::learner< T, E >::get_output_prediction_type ( )
inline

◆ init_driver()

template<class T, class E>
void VW::LEARNER::learner< T, E >::init_driver ( )
inline

◆ is_multiline()

template<class T, class E>
bool VW::LEARNER::learner< T, E >::is_multiline ( )
inline

◆ learn()

template<class T, class E>
void VW::LEARNER::learner< T, E >::learn ( E &  ec,
size_t  i = 0 
)
inline

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 reduction expects.
iThis is the offset used for the weights in this call. If using multiple regressors/learners you can increment this value for each call.
Returns
While some reductions may fill the example::pred, this is not guaranteed and is undefined behavior if accessed.

◆ multipredict()

template<class T, class E>
void VW::LEARNER::learner< T, E >::multipredict ( E &  ec,
size_t  lo,
size_t  count,
polyprediction pred,
bool  finalize_predictions 
)
inline

◆ persist_metrics()

template<class T, class E>
void VW::LEARNER::learner< T, E >::persist_metrics ( metric_sink metrics)
inline

◆ predict()

template<class T, class E>
void VW::LEARNER::learner< T, E >::predict ( E &  ec,
size_t  i = 0 
)
inline

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 reduction type.
iThis is the offset used for the weights in this call. If using multiple regressors/learners you can increment this value for each call.
Returns
The prediction calculated by this reduction be set on example::pred. If E is multi_ex then the prediction is set on the 0th item in the list.

◆ print_example()

template<class T, class E>
void VW::LEARNER::learner< T, E >::print_example ( VW::workspace all,
E &  ec 
)
inline

◆ save_load()

template<class T, class E>
void VW::LEARNER::learner< T, E >::save_load ( io_buf io,
const bool  read,
const bool  text 
)
inline

◆ sensitivity()

template<class T, class E>
float VW::LEARNER::learner< T, E >::sensitivity ( example ec,
size_t  i = 0 
)
inline

◆ update()

template<class T, class E>
void VW::LEARNER::learner< T, E >::update ( E &  ec,
size_t  i = 0 
)
inline

Friends And Related Function Documentation

◆ base_learner_builder

template<class T, class E>
template<class DataT , class ExampleT >
friend struct base_learner_builder
friend

◆ common_learner_builder

template<class T, class E>
template<class FluentBuilderT , class DataT , class ExampleT , class BaseLearnerT >
friend struct common_learner_builder
friend

◆ reduction_learner_builder

template<class T, class E>
template<class DataT , class ExampleT , class BaseLearnerT >
friend struct reduction_learner_builder
friend

◆ reduction_no_data_learner_builder

template<class T, class E>
template<class ExampleT , class BaseLearnerT >
friend struct reduction_no_data_learner_builder
friend

Member Data Documentation

◆ increment

template<class T, class E>
size_t VW::LEARNER::learner< T, E >::increment

◆ learn_returns_prediction

template<class T, class E>
bool VW::LEARNER::learner< T, E >::learn_returns_prediction = false

◆ weights

template<class T, class E>
size_t VW::LEARNER::learner< T, E >::weights

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