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:
- 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, ...