Turi Create  4.0
turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type > Class Template Referencefinal

#include <toolkits/factorization/factorization_model_sgd_interface.hpp>

Public Member Functions

void setup (const v2::ml_data &train_data, const std::map< std::string, flexible_type > &options)
 
double l2_regularization_factor () const
 
double max_step_size () const
 
void setup_iteration (size_t iteration, double step_size)
 
void finalize_iteration ()
 
bool state_is_numerically_stable () const GL_HOT_INLINE_FLATTEN
 
void setup_optimization (size_t random_seed=size_t(-1), bool trial_mode=false)
 
double current_regularization_penalty () const
 
double calculate_loss (const v2::ml_data &data) const
 
double reported_loss_value (double accumulative_loss) const
 
std::string reported_loss_name () const
 
double calculate_fx (size_t thread_idx, const std::vector< v2::ml_data_entry > &x) const GL_HOT_FLATTEN
 
GL_HOT_INLINE_FLATTEN double apply_sgd_step (size_t thread_idx, const std::vector< v2::ml_data_entry > &x, double y, double step_size, bool apply_regularization)
 
GL_HOT_INLINE_FLATTEN double apply_sgd_step (size_t thread_idx, const std::vector< v2::ml_data_entry > &x, double y, double step_size)
 
double apply_pairwise_sgd_step (size_t thread_idx, const std::vector< v2::ml_data_entry > &x_positive, const std::vector< v2::ml_data_entry > &x_negative, double step_size) GL_HOT_FLATTEN
 

Public Attributes

bool currently_in_trial_mode = false
 

Static Public Attributes

static constexpr model_regularization_type regularization_type = _regularization_type
 

Detailed Description

template<typename GLMModel, typename _LossModelProfile, model_regularization_type _regularization_type>
class turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >

This class provides the interface layer for the basic sgd solver, this time for the second_order model. It provides functions to calculate the gradient and apply a gradient update. (In the original design, these were just folded into the model; they are now seperated out to make the original model simpler.)

For documentation on the interface requirements of each of the solvers, see the sgd algorithms; each one requires specific interface functions to be defined.

Definition at line 54 of file factorization_model_sgd_interface.hpp.

Member Function Documentation

◆ apply_pairwise_sgd_step()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::apply_pairwise_sgd_step ( size_t  thread_idx,
const std::vector< v2::ml_data_entry > &  x_positive,
const std::vector< v2::ml_data_entry > &  x_negative,
double  step_size 
)
inline

Calculate the gradient with respect to a single observation, then applies it. Used by the basic sgd solver; this one is used for the first order model.

x is the observation vector, in standard ml_data_entry format, formed by ml_data_iterator.fill_observation(...).

struct ml_data_entry { size_t column_index; // Column id size_t index; // Local index within the column. double value; // Value };

Definition at line 1505 of file factorization_model_sgd_interface.hpp.

◆ apply_sgd_step() [1/2]

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
GL_HOT_INLINE_FLATTEN double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::apply_sgd_step ( size_t  thread_idx,
const std::vector< v2::ml_data_entry > &  x,
double  y,
double  step_size,
bool  apply_regularization 
)
inline

Calculate the gradient with respect to a single observation, then applies it. Used by the basic sgd solver; this one is used for the second_order model.

x is the observation vector, in standard ml_data_entry format, formed by ml_data_iterator.fill_observation(...).

struct ml_data_entry { size_t column_index; // Column id size_t index; // Local index within the column. double value; // Value };

Definition at line 1335 of file factorization_model_sgd_interface.hpp.

◆ apply_sgd_step() [2/2]

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
GL_HOT_INLINE_FLATTEN double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::apply_sgd_step ( size_t  thread_idx,
const std::vector< v2::ml_data_entry > &  x,
double  y,
double  step_size 
)
inlinevirtual

Calculate the gradient with respect to a single observation, then applies it. Used by the basic sgd solver; this one is used for the second_order model.

x is the observation vector, in standard ml_data_entry format, formed by ml_data_iterator.fill_observation(...).

struct ml_data_entry { size_t column_index; // Column id size_t index; // Local index within the column. double value; // Value };

Implements turi::sgd::sgd_interface_base.

Definition at line 1483 of file factorization_model_sgd_interface.hpp.

◆ calculate_fx()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::calculate_fx ( size_t  thread_idx,
const std::vector< v2::ml_data_entry > &  x 
) const
inline

Calculate the gradient with respect to a single observation, then applies it. Used by the basic sgd solver; this one is used for the second_order model.

x is the observation vector, in standard ml_data_entry format, formed by ml_data_iterator.fill_observation(...).

struct ml_data_entry { size_t column_index; // Column id size_t index; // Local index within the column. double value; // Value };

Definition at line 1288 of file factorization_model_sgd_interface.hpp.

◆ calculate_loss()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::calculate_loss ( const v2::ml_data &  data) const
inlinevirtual

Calculate the value of the objective function as determined by the loss function, for a full data set, minus the regularization penalty.

Implements turi::sgd::sgd_interface_base.

Definition at line 693 of file factorization_model_sgd_interface.hpp.

◆ current_regularization_penalty()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::current_regularization_penalty ( ) const
inlinevirtual

Calculate the current regularization penalty.

Implements turi::sgd::sgd_interface_base.

Definition at line 622 of file factorization_model_sgd_interface.hpp.

◆ finalize_iteration()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
void turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::finalize_iteration ( )
inlinevirtual

Finalizes the iteration. Called after each pass through the data.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 510 of file factorization_model_sgd_interface.hpp.

◆ l2_regularization_factor()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::l2_regularization_factor ( ) const
inlinevirtual

Returns the l2 regularization coefficient.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 376 of file factorization_model_sgd_interface.hpp.

◆ max_step_size()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::max_step_size ( ) const
inlinevirtual

Returns an upper bound on the sgd step size.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 385 of file factorization_model_sgd_interface.hpp.

◆ reported_loss_name()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
std::string turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::reported_loss_name ( ) const
inlinevirtual

The name of the loss to report on each iteration.

For example, if squared error loss is used, reported_loss_name() could give RMSE, and then reported_loss_value(v) would be std::sqrt(v).

Implements turi::sgd::sgd_interface_base.

Definition at line 754 of file factorization_model_sgd_interface.hpp.

◆ reported_loss_value()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
double turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::reported_loss_value ( double  accumulative_loss) const
inlinevirtual

The value of the reported loss. The apply_sgd_step accumulates estimated loss values between samples. This function is called with this accumulated value to get a value

For example, if squared error loss is used, reported_loss_name() could give RMSE, and then reported_loss_value(v) would be std::sqrt(v).

Implements turi::sgd::sgd_interface_base.

Definition at line 744 of file factorization_model_sgd_interface.hpp.

◆ setup()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
void turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::setup ( const v2::ml_data &  train_data,
const std::map< std::string, flexible_type > &  options 
)
inlinevirtual

Set up all the stuff needed for processing the data at each iteration.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 268 of file factorization_model_sgd_interface.hpp.

◆ setup_iteration()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
void turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::setup_iteration ( size_t  iteration,
double  step_size 
)
inlinevirtual

Set up the class and constants before every iteration.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 403 of file factorization_model_sgd_interface.hpp.

◆ setup_optimization()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
void turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::setup_optimization ( size_t  random_seed = size_t(-1),
bool  trial_mode = false 
)
inlinevirtual

Sets up the optimization run. Called at the beginning of an optimization run or to reset the state.

Implements turi::sgd::sgd_interface_base.

Definition at line 602 of file factorization_model_sgd_interface.hpp.

◆ state_is_numerically_stable()

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
bool turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::state_is_numerically_stable ( ) const
inlinevirtual

Test whether the current state is numerically stable or not; if not, it needs to be reset.

Reimplemented from turi::sgd::sgd_interface_base.

Definition at line 580 of file factorization_model_sgd_interface.hpp.

Member Data Documentation

◆ currently_in_trial_mode

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
bool turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::currently_in_trial_mode = false

Trial mode is used to find the sgd step size.

Definition at line 88 of file factorization_model_sgd_interface.hpp.

◆ regularization_type

template<typename GLMModel , typename _LossModelProfile , model_regularization_type _regularization_type>
constexpr model_regularization_type turi::factorization::factorization_sgd_interface< GLMModel, _LossModelProfile, _regularization_type >::regularization_type = _regularization_type
static

The model_regularization_type.

Definition at line 92 of file factorization_model_sgd_interface.hpp.


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