12 #ifndef MLPACK_METHODS_CF_SIMILARITY_INTERPOLATION_HPP 13 #define MLPACK_METHODS_CF_SIMILARITY_INTERPOLATION_HPP 65 template <
typename VectorType,
66 typename DecompositionPolicy>
68 const DecompositionPolicy& ,
70 const arma::Col<size_t>& neighbors,
71 const arma::vec& similarities,
74 if (similarities.n_elem == 0)
76 Log::Fatal <<
"Require: similarities.n_elem > 0. There should be at " 77 <<
"least one neighbor!" << std::endl;
80 if (weights.n_elem != neighbors.n_elem)
82 Log::Fatal <<
"The size of the first parameter (weights) should " 83 <<
"be set to the number of neighbors before calling GetWeights()." 87 double similaritiesSum = arma::sum(similarities);
88 if (std::fabs(similaritiesSum) < 1e-14)
90 weights.fill(1.0 / similarities.n_elem);
94 weights = similarities / similaritiesSum;
void GetWeights(VectorType &&weights, const DecompositionPolicy &, const size_t, const arma::Col< size_t > &neighbors, const arma::vec &similarities, const arma::sp_mat &)
Interpolation weights are computed as normalized similarities.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
SimilarityInterpolation(const arma::sp_mat &)
This constructor is needed for interface consistency.
With SimilarityInterpolation, interpolation weights are based on similarities between query user and ...
SimilarityInterpolation()