Vowpal Wabbit
Public Types | Public Member Functions | Static 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 &, void *, void *)
 
using finish_fptr_type = void(*)(void *)
 

Public Member Functions

void debug_log_message (example &ec, const std::string &msg)
 
void debug_log_message (multi_ex &ec, const std::string &msg)
 
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)
 
template<class L >
void set_predict (void(*u)(T &, L &, E &))
 
template<class L >
void set_learn (void(*u)(T &, L &, E &))
 
template<class L >
void set_multipredict (void(*u)(T &, L &, E &, size_t, size_t, polyprediction *, bool))
 
void update (E &ec, size_t i=0)
 
template<class L >
void set_update (void(*u)(T &data, L &base, E &))
 
void set_sensitivity (float(*u)(T &data, base_learner &base, example &))
 
float sensitivity (example &ec, size_t i=0)
 
void save_load (io_buf &io, const bool read, const bool text)
 
void set_save_load (void(*sl)(T &, io_buf &, bool, bool))
 
void persist_metrics (metric_sink &metrics)
 
void set_persist_metrics (void(*f)(T &, metric_sink &))
 
void set_finish (void(*f)(T &))
 
void finish ()
 
void end_pass ()
 
void set_end_pass (void(*f)(T &))
 
void end_examples ()
 
void set_end_examples (void(*f)(T &))
 
void init_driver ()
 
void set_init_driver (void(*f)(T &))
 
void finish_example (vw &all, E &ec)
 
void set_finish_example (void(*f)(vw &all, T &, E &))
 
void set_print_example (void(*f)(vw &all, T &, E &))
 
void print_example (vw &all, E &ec)
 
base_learnerget_learner_by_name_prefix (std::string reduction_name)
 

Static Public Member Functions

template<class L >
static learner< T, E > & init_learner (T *dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), size_t ws, prediction_type_t pred_type, const std::string &name, bool learn_returns_prediction=false)
 

Public Attributes

prediction_type_t pred_type
 
size_t weights
 
size_t increment
 
bool is_multiline
 
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 various VW::LEARNER::init_learner overloaded functions that chain to the central factor function VW::LEARNER::learner::init_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 VW::LEARNER::learner::init_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

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

Member Function Documentation

template<class T, class E>
void VW::LEARNER::learner< T, E >::debug_log_message ( example ec,
const std::string &  msg 
)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::debug_log_message ( multi_ex ec,
const std::string &  msg 
)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::end_examples ( )
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::end_pass ( )
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::finish ( )
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::finish_example ( vw all,
E &  ec 
)
inline
template<class T, class E>
base_learner* VW::LEARNER::learner< T, E >::get_learner_by_name_prefix ( std::string  reduction_name)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::init_driver ( )
inline
template<class T, class E>
template<class L >
static learner<T, E>& VW::LEARNER::learner< T, E >::init_learner ( T *  dat,
L *  base,
void(*)(T &, L &, E &)  learn,
void(*)(T &, L &, E &)  predict,
size_t  ws,
prediction_type_t  pred_type,
const std::string &  name,
bool  learn_returns_prediction = false 
)
inlinestatic
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.
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
template<class T, class E>
void VW::LEARNER::learner< T, E >::persist_metrics ( metric_sink metrics)
inline
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.
template<class T, class E>
void VW::LEARNER::learner< T, E >::print_example ( vw all,
E &  ec 
)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::save_load ( io_buf io,
const bool  read,
const bool  text 
)
inline
template<class T, class E>
float VW::LEARNER::learner< T, E >::sensitivity ( example ec,
size_t  i = 0 
)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_end_examples ( void(*)(T &)  f)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_end_pass ( void(*)(T &)  f)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_finish ( void(*)(T &)  f)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_finish_example ( void(*)(vw &all, T &, E &)  f)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_init_driver ( void(*)(T &)  f)
inline
template<class T, class E>
template<class L >
void VW::LEARNER::learner< T, E >::set_learn ( void(*)(T &, L &, E &)  u)
inline
template<class T, class E>
template<class L >
void VW::LEARNER::learner< T, E >::set_multipredict ( void(*)(T &, L &, E &, size_t, size_t, polyprediction *, bool)  u)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_persist_metrics ( void(*)(T &, metric_sink &)  f)
inline
template<class T, class E>
template<class L >
void VW::LEARNER::learner< T, E >::set_predict ( void(*)(T &, L &, E &)  u)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_print_example ( void(*)(vw &all, T &, E &)  f)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_save_load ( void(*)(T &, io_buf &, bool, bool)  sl)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::set_sensitivity ( float(*)(T &data, base_learner< T, E > &base, example &)  u)
inline
template<class T, class E>
template<class L >
void VW::LEARNER::learner< T, E >::set_update ( void(*)(T &data, L &base, E &)  u)
inline
template<class T, class E>
void VW::LEARNER::learner< T, E >::update ( E &  ec,
size_t  i = 0 
)
inline

Friends And Related Function Documentation

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

Member Data Documentation

template<class T, class E>
size_t VW::LEARNER::learner< T, E >::increment
template<class T, class E>
bool VW::LEARNER::learner< T, E >::is_multiline
template<class T, class E>
bool VW::LEARNER::learner< T, E >::learn_returns_prediction = false
template<class T, class E>
prediction_type_t VW::LEARNER::learner< T, E >::pred_type
template<class T, class E>
size_t VW::LEARNER::learner< T, E >::weights

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