Turi Create
4.0
|
#include <toolkits/factorization/factorization_model.hpp>
Public Member Functions | |
std::map< std::string, variant_type > | get_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_type > | get_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_type > | get_serialization_parameters () const =0 |
Static Public Member Functions | |
static std::shared_ptr< factorization_model > | factory_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_model > | factory_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 |
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.
|
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.
[in,out] | options | The option manager to add the options to. |
[in] | option_flags | The functionality that the factorization_model class is expected to support. |
This function is defined in factorization_model_options.cpp.
|
protectedpure virtual |
Calculate the linear function value at the given point wrt the current state.
|
protectedpure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
pure virtual |
Computes the cosine similarity between a particular factor within a column and all the other factors within that column.
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.
|
static |
Instantiate and load a factorization model from a stream.
|
static |
Create and train a factorization model with the given options. Uses the factory method pattern.
The training method constructs an
[in] | factor_mode | One 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_data | The training data for the model. |
[in] | options | The options used in the current model as well as training parameters. |
|
pure virtual |
Returns a map of all the different coefficients of the model, as given by the current model.
|
pure virtual |
Return all the parameters needed by factory_load to determine what model to instantiate.
std::map<std::string, variant_type> turi::factorization::factorization_model::get_training_stats | ( | ) | const |
Returns a map of the training statistics of the model.
|
pure virtual |
Return the serialization version.
void turi::factorization::factorization_model::local_save_impl | ( | turi::oarchive & | oarc | ) | const |
Serialization of this base class.
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.
|
pure virtual |
Resets the state with an initial random seed and standard deviation.
|
pure virtual |
Serialization in factorization_model_impl. These methods allow the child class to have specific parameters that need to be serialized and deserialized.
|
pure virtual |
Scores all the items in scores, updating the score. Used by the recommender system.
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.