average_interpolation.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_CF_AVERAGE_INTERPOLATION_HPP
13 #define MLPACK_METHODS_CF_AVERAGE_INTERPOLATION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace cf {
19 
40 {
41  public:
42  // Empty constructor.
44 
48  AverageInterpolation(const arma::sp_mat& /* cleanedData */) { }
49 
63  template <typename VectorType,
64  typename DecompositionPolicy>
65  void GetWeights(VectorType&& weights,
66  const DecompositionPolicy& /* decomposition */,
67  const size_t /* queryUser */,
68  const arma::Col<size_t>& neighbors,
69  const arma::vec& /* similarities */,
70  const arma::sp_mat& /* cleanedData */)
71  {
72  if (neighbors.n_elem == 0)
73  {
74  Log::Fatal << "Require: neighbors.n_elem > 0. There should be at "
75  << "least one neighbor!" << std::endl;
76  }
77 
78  if (weights.n_elem != neighbors.n_elem)
79  {
80  Log::Fatal << "The size of the first parameter (weights) should "
81  << "be set to the number of neighbors before calling GetWeights()."
82  << std::endl;
83  }
84 
85  weights.fill(1.0 / neighbors.n_elem);
86  }
87 };
88 
89 } // namespace cf
90 } // namespace mlpack
91 
92 #endif
AverageInterpolation(const arma::sp_mat &)
This constructor is needed for interface consistency.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
This class performs average interpolation to generate interpolation weights for neighborhood-based co...
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
void GetWeights(VectorType &&weights, const DecompositionPolicy &, const size_t, const arma::Col< size_t > &neighbors, const arma::vec &, const arma::sp_mat &)
Interoplation weights are identical and sum up to one.