Turi Create  4.0
turi::factorization::factorization_model Class Referenceabstract

#include <toolkits/factorization/factorization_model.hpp>

Public Member Functions

std::map< std::string, variant_typeget_training_stats () const
 
double calculate_loss (const v2::ml_data &data) const
 
sframe predict (const v2::ml_data &test_data) const
 
virtual void score_all_items (std::vector< std::pair< size_t, double > > &scores, const std::vector< v2::ml_data_entry > &query_row, size_t top_k, const std::shared_ptr< v2::ml_data_side_features > &known_side_features) const =0
 
virtual void reset_state (size_t random_seed, double sd)=0
 
virtual std::map< std::string, variant_typeget_coefficients () const =0
 
virtual void calculate_intracolumn_similarity (vector_type &dest, size_t column_index, size_t ref_index) const =0
 
void setup (const std::string &loss_model_name, const v2::ml_data &train_data, const std::map< std::string, flexible_type > &opts)
 
virtual size_t get_version () const =0
 
virtual void save_impl (turi::oarchive &oarc) const =0
 
void local_save_impl (turi::oarchive &oarc) const
 
virtual std::map< std::string, variant_typeget_serialization_parameters () const =0
 

Static Public Member Functions

static std::shared_ptr< factorization_modelfactory_train (const std::string &factor_mode, const v2::ml_data &train_data, std::map< std::string, flexible_type > options)
 
static void add_options (option_manager &options, const std::vector< std::string > &option_flags)
 
static std::shared_ptr< factorization_modelfactory_load (size_t version, const std::map< std::string, variant_type > &serialization_parameters, turi::iarchive &iarc)
 

Protected Member Functions

virtual double calculate_fx (size_t thread_idx, const std::vector< v2::ml_data_entry > &x) const =0
 
virtual double calculate_fx (const std::vector< v2::ml_data_entry > &x) const =0
 

Detailed Description

Factorization model class.

This class is the base model for all the factorization models. All interaction with these models should go through this class.

This class is intended to be embedded within other models as the matrix factorization interface. For example, the recommender model holds a std::shared_ptr<factorization_model> pointer. The matrix factorization class exposed to the user as a standalone model will also embed this class.

The details of the model are implemented in a subclass of factorization_model with template parameters controlling some aspects of the model's functionality. In particular, if the model is a matrix factorization model, only the first two dimensions have latent factors, whereas a factorization model has latent factors for all dimensions. This is in factorization_model_impl.hpp.

To train a model, use the static train(...) function below. Similarly, to load such a model, use the static load(...) function below. These instantiate the correct type of subclass, then return a pointer to this class.

Definition at line 65 of file factorization_model.hpp.

Member Function Documentation

◆ add_options()

static void turi::factorization::factorization_model::add_options ( option_manager options,
const std::vector< std::string > &  option_flags 
)
static

Call the following function to insert the option definitions needed for the factorization_model class into an option manager.

The option_flags parameter is used to control what options are enabled and what the factorization_model class is expected to support. Possible flags are as follows:

ranking: Include options for ranking-based optimization. This is required for implicit rating optimization.

Parameters
[in,out]optionsThe option manager to add the options to.
[in]option_flagsThe functionality that the factorization_model class is expected to support.

This function is defined in factorization_model_options.cpp.

◆ calculate_fx() [1/2]

virtual double turi::factorization::factorization_model::calculate_fx ( size_t  thread_idx,
const std::vector< v2::ml_data_entry > &  x 
) const
protectedpure virtual

Calculate the linear function value at the given point wrt the current state.

◆ calculate_fx() [2/2]

virtual double turi::factorization::factorization_model::calculate_fx ( const std::vector< v2::ml_data_entry > &  x) const
protectedpure virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ calculate_intracolumn_similarity()

virtual void turi::factorization::factorization_model::calculate_intracolumn_similarity ( vector_type &  dest,
size_t  column_index,
size_t  ref_index 
) const
pure virtual

Computes the cosine similarity between a particular factor within a column and all the other factors within that column.

◆ calculate_loss()

double turi::factorization::factorization_model::calculate_loss ( const v2::ml_data &  data) const

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

◆ factory_load()

static std::shared_ptr<factorization_model> turi::factorization::factorization_model::factory_load ( size_t  version,
const std::map< std::string, variant_type > &  serialization_parameters,
turi::iarchive iarc 
)
static

Instantiate and load a factorization model from a stream.

◆ factory_train()

static std::shared_ptr<factorization_model> turi::factorization::factorization_model::factory_train ( const std::string &  factor_mode,
const v2::ml_data &  train_data,
std::map< std::string, flexible_type options 
)
static

Create and train a factorization model with the given options. Uses the factory method pattern.

The training method constructs an

Parameters
[in]factor_modeOne of "linear_model", "matrix_factorization", or "factorization_model". If "linear_model", then the class is essentially linear regression; if "matrix_factorization", then only the first two columns have latent factors, and if "factorization_model", then the full factorization machine model is used.
[in]train_dataThe training data for the model.
[in]optionsThe options used in the current model as well as training parameters.

◆ get_coefficients()

virtual std::map<std::string, variant_type> turi::factorization::factorization_model::get_coefficients ( ) const
pure virtual

Returns a map of all the different coefficients of the model, as given by the current model.

◆ get_serialization_parameters()

virtual std::map<std::string, variant_type> turi::factorization::factorization_model::get_serialization_parameters ( ) const
pure virtual

Return all the parameters needed by factory_load to determine what model to instantiate.

◆ get_training_stats()

std::map<std::string, variant_type> turi::factorization::factorization_model::get_training_stats ( ) const

Returns a map of the training statistics of the model.

◆ get_version()

virtual size_t turi::factorization::factorization_model::get_version ( ) const
pure virtual

Return the serialization version.

◆ local_save_impl()

void turi::factorization::factorization_model::local_save_impl ( turi::oarchive oarc) const

Serialization of this base class.

◆ predict()

sframe turi::factorization::factorization_model::predict ( const v2::ml_data &  test_data) const

Make a prediction for every observation in test_data. Returns a single-column SFrame with a prediction for every observation.

◆ reset_state()

virtual void turi::factorization::factorization_model::reset_state ( size_t  random_seed,
double  sd 
)
pure virtual

Resets the state with an initial random seed and standard deviation.

◆ save_impl()

virtual void turi::factorization::factorization_model::save_impl ( turi::oarchive oarc) const
pure virtual

Serialization in factorization_model_impl. These methods allow the child class to have specific parameters that need to be serialized and deserialized.

◆ score_all_items()

virtual void turi::factorization::factorization_model::score_all_items ( std::vector< std::pair< size_t, double > > &  scores,
const std::vector< v2::ml_data_entry > &  query_row,
size_t  top_k,
const std::shared_ptr< v2::ml_data_side_features > &  known_side_features 
) const
pure virtual

Scores all the items in scores, updating the score. Used by the recommender system.

◆ setup()

void turi::factorization::factorization_model::setup ( const std::string &  loss_model_name,
const v2::ml_data &  train_data,
const std::map< std::string, flexible_type > &  opts 
)

Set up the model with the correct index sizes, etc.

Here, only should be called from the training functions in factorization_model_training. However, these are implemented outside of this class, so we have to keep this method public.


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