Using the Eigen library

For the first sample, let's see how to implement a collaborative filtering recommender system based on matrix factorization with ALS and with a pure linear algebra library as a backend. In the following sample, we're using the Eigen library. The steps to implement a collaborative filtering recommender system are as follows:

  1. At first, we make base type definitions, as follows:
using DataType = float;// using Eigen::ColMajor is Eigen restriction -  todense method always returns// matrices in ColMajor orderusing Matrix =Eigen::Matrix<DataType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;using SparseMatrix = Eigen::SparseMatrix<DataType, Eigen::ColMajor>;using DiagonalMatrix =Eigen::DiagonalMatrix<DataType, Eigen::Dynamic, ...

Get Hands-On Machine Learning with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.