6 #ifndef TURI_UNITY_ITEM_SIMILARITY_LOOKUP_H_ 7 #define TURI_UNITY_ITEM_SIMILARITY_LOOKUP_H_ 9 #include <core/data/flexible_type/flexible_type.hpp> 10 #include <model_server/lib/extensions/option_manager.hpp> 15 template <
typename T>
class sarray;
87 static std::shared_ptr<sparse_similarity_lookup>
88 create(
const std::string& similarity,
const std::map<std::string, flexible_type>& options);
99 virtual std::map<std::string, flexible_type>
102 const std::shared_ptr<
sarray<std::vector<std::pair<size_t, double> > > >& data) = 0;
120 const sframe& _interaction_data,
121 const std::string& item_column,
122 const std::string& similar_item_column,
123 const std::string& similarity,
124 bool add_reverse =
false) = 0;
142 virtual size_t score_items(std::vector<std::pair<size_t, double> >& item_predictions,
143 const std::vector<std::pair<size_t, double> >& user_item_data)
const = 0;
151 std::vector<std::pair<size_t, flexible_type> >& similar_items_dest,
152 size_t item,
size_t top_k)
const = 0;
157 virtual size_t get_version()
const = 0;
192 static const size_t verification_number = 0x36fe3812b00eddb0ULL;
195 arc << m->similarity_name();
198 arc << m->current_options();
203 arc << verification_number;
207 } END_OUT_OF_PLACE_SAVE()
211 arc >> is_not_nullptr;
214 static const size_t verification_number = 0x36fe3812b00eddb0ULL;
219 std::map<std::string, flexible_type>
options;
222 std::shared_ptr<sparse_similarity_lookup> new_m
227 size_t test_verification_number = 0;
228 arc >> test_verification_number;
230 ASSERT_MSG(test_verification_number == verification_number,
231 "Unknown error loading similarity model.");
236 m = std::shared_ptr<sparse_similarity_lookup>();
238 } END_OUT_OF_PLACE_LOAD()
#define BEGIN_OUT_OF_PLACE_LOAD(arc, tname, tval)
Macro to make it easy to define out-of-place loads.
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
static std::shared_ptr< sparse_similarity_lookup > create(const std::string &similarity, const std::map< std::string, flexible_type > &options)
const std::map< std::string, flexible_type > & current_options() const
virtual void save(turi::oarchive &oarc) const =0
virtual std::map< std::string, flexible_type > train_from_sparse_matrix_sarray(size_t num_items, const std::shared_ptr< sarray< std::vector< std::pair< size_t, double > > > > &data)=0
std::map< std::string, flexible_type > options
virtual void setup_by_raw_similarity(size_t num_items, const flex_list &item_data, const sframe &_interaction_data, const std::string &item_column, const std::string &similar_item_column, const std::string &similarity, bool add_reverse=false)=0
static void add_options(option_manager &options)
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
virtual std::string similarity_name() const =0
virtual size_t score_items(std::vector< std::pair< size_t, double > > &item_predictions, const std::vector< std::pair< size_t, double > > &user_item_data) const =0
std::vector< flexible_type > flex_list
virtual void get_similar_items(std::vector< std::pair< size_t, flexible_type > > &similar_items_dest, size_t item, size_t top_k) const =0
#define BEGIN_OUT_OF_PLACE_SAVE(arc, tname, tval)
Macro to make it easy to define out-of-place saves.
virtual bool _debug_check_equal(const sparse_similarity_lookup &other) const =0