Merge pull request #4 from AYESDIE/AYESDIE-updated-syntax
Followed guidelines to update syntax (yet again..) Updated: Syntax styling and added information about Weight Interpolation and Neighbour Search in 'PROGRAM_INFO'
This commit is contained in:
+174
-168
@@ -80,6 +80,18 @@ PROGRAM_INFO("Collaborative Filtering", "This program performs collaborative "
|
||||
" - 'SVDCompleteIncremental' -- SVD complete incremental learning\n"
|
||||
" - 'BiasSVD' -- Bias SVD using a SGD optimizer\n"
|
||||
" - 'SVDPP' -- SVD++ using a SGD optimizer\n"
|
||||
"\n\n"
|
||||
"The following neighbor search algorithms can be specified via" +
|
||||
" the " + PRINT_PARAM_STRING("neighbor_search") + " parameter:"
|
||||
" - 'Cosine' -- Cosine Search Algorithm\n"
|
||||
" - 'Euclidean' -- Euclidean Search Algorithm\n"
|
||||
" - 'Pearson' -- Pearson Search Algorithm\n"
|
||||
"\n\n"
|
||||
"The following weight interpolation algorithms can be specified via" +
|
||||
" the " + PRINT_PARAM_STRING("interpolation") + " parameter:"
|
||||
" - 'Average' -- Average Interpolation Algorithm\n"
|
||||
" - 'Regression' -- Regression Interpolation Algorithm\n"
|
||||
" - 'Similarity' -- Similarity Interpolation Algorithm\n"
|
||||
"\n"
|
||||
"A trained model may be saved to with the " +
|
||||
PRINT_PARAM_STRING("output_model") + " output parameter."
|
||||
@@ -134,19 +146,21 @@ PARAM_INT_IN("recommendations", "Number of recommendations to generate for each"
|
||||
|
||||
PARAM_INT_IN("seed", "Set the random seed (0 uses std::time(NULL)).", "s", 0);
|
||||
|
||||
// Interpolation and Neighbour Search Algorithms
|
||||
// Interpolation and Neighbor Search Algorithms
|
||||
PARAM_STRING_IN("interpolation", "Algorithm used for weight interpolation.",
|
||||
"i", "Average");
|
||||
|
||||
PARAM_STRING_IN("neighbour_search", "Algorithm used for neighbour search.",
|
||||
PARAM_STRING_IN("neighbor_search", "Algorithm used for neighbor search.",
|
||||
"f", "Euclidean");
|
||||
|
||||
void ComputeRecommendations(CFModel* cf,
|
||||
const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations)
|
||||
{
|
||||
const string ns_algo = CLI::GetParam<string>("neighbour_search");
|
||||
const string iw_algo = CLI::GetParam<string>("interpolation");
|
||||
// Taking alternatives
|
||||
const string neighborSearchAlgorithm = CLI::GetParam<string>
|
||||
("neighbor_search");
|
||||
const string interpolationAlgorithm = CLI::GetParam<string>("interpolation");
|
||||
|
||||
// Reading users.
|
||||
if (CLI::HasParam("query"))
|
||||
@@ -157,142 +171,134 @@ void ComputeRecommendations(CFModel* cf,
|
||||
if (users.n_rows > 1)
|
||||
users = users.t();
|
||||
if (users.n_rows > 1)
|
||||
Log::Fatal << "List of query users must be one-dimensional!" << std::endl;
|
||||
Log::Fatal << "List of query users must be one-dimensional!"
|
||||
<< std::endl;
|
||||
|
||||
Log::Info << "Generating recommendations for " << users.n_elem << " users."
|
||||
<< endl;
|
||||
Log::Info << "Generating recommendations for "
|
||||
<< users.n_elem << " users."
|
||||
<< endl;
|
||||
|
||||
// Making All the possible paths
|
||||
if (ns_algo == "Cosine")
|
||||
// All possible alternatives for Recommendations
|
||||
if (neighborSearchAlgorithm == "Cosine")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
AverageInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch, AverageInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
}
|
||||
else if (ns_algo == "Euclidean")
|
||||
else if (neighborSearchAlgorithm == "Euclidean")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
AverageInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, AverageInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
}
|
||||
else if (ns_algo == "Pearson")
|
||||
else if (neighborSearchAlgorithm == "Pearson")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
AverageInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations,
|
||||
users.row(0).t());
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, AverageInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations, users.row(0).t());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::Info << "Generating recommendations for all users." << endl;
|
||||
if (ns_algo == "Cosine")
|
||||
if (neighborSearchAlgorithm == "Cosine")
|
||||
{
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
AverageInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<CosineSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
cf->GetRecommendations<CosineSearch, AverageInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (ns_algo == "Euclidean")
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
AverageInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
cf->GetRecommendations<CosineSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (ns_algo == "Pearson")
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
AverageInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
RegressionInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch,
|
||||
SimilarityInterpolation>(numRecs, recommendations);
|
||||
}
|
||||
cf->GetRecommendations<CosineSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
}
|
||||
else if (neighborSearchAlgorithm == "Euclidean")
|
||||
{
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, AverageInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<EuclideanSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
}
|
||||
else if (neighborSearchAlgorithm == "Pearson")
|
||||
{
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, AverageInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, RegressionInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->GetRecommendations<PearsonSearch, SimilarityInterpolation>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeRMSE(CFModel* cf)
|
||||
{
|
||||
// Interpolation and Neighbour Search
|
||||
|
||||
const string ns_algo = CLI::GetParam<string>("neighbour_search");
|
||||
const string iw_algo = CLI::GetParam<string>("interpolation");
|
||||
// Interpolation and Neighbor Search
|
||||
const string neighborSearchAlgorithm = CLI::GetParam<string>("neighbor_search");
|
||||
const string interpolationAlgorithm = CLI::GetParam<string>("interpolation");
|
||||
|
||||
// Now, compute each test point.
|
||||
arma::mat testData = std::move(CLI::GetParam<arma::mat>("test"));
|
||||
@@ -308,59 +314,59 @@ void ComputeRMSE(CFModel* cf)
|
||||
// Now compute the RMSE.
|
||||
arma::vec predictions;
|
||||
|
||||
if (ns_algo == "Cosine")
|
||||
if (neighborSearchAlgorithm == "Cosine")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->Predict<CosineSearch,
|
||||
AverageInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->Predict<CosineSearch,
|
||||
RegressionInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->Predict<CosineSearch,
|
||||
SimilarityInterpolation>(combinations, predictions);
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->Predict<CosineSearch, AverageInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->Predict<CosineSearch, RegressionInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->Predict<CosineSearch, SimilarityInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
}
|
||||
else if (ns_algo == "Euclidean")
|
||||
else if (neighborSearchAlgorithm == "Euclidean")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->Predict<EuclideanSearch,
|
||||
AverageInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->Predict<EuclideanSearch,
|
||||
RegressionInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->Predict<EuclideanSearch,
|
||||
SimilarityInterpolation>(combinations, predictions);
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->Predict<EuclideanSearch, AverageInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->Predict<EuclideanSearch, RegressionInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->Predict<EuclideanSearch, SimilarityInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
}
|
||||
else if (ns_algo == "Pearson")
|
||||
else if (neighborSearchAlgorithm == "Pearson")
|
||||
{
|
||||
if (iw_algo == "Average")
|
||||
{
|
||||
cf->Predict<PearsonSearch,
|
||||
AverageInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Regression")
|
||||
{
|
||||
cf->Predict<PearsonSearch,
|
||||
RegressionInterpolation>(combinations, predictions);
|
||||
}
|
||||
else if (iw_algo == "Similarity")
|
||||
{
|
||||
cf->Predict<PearsonSearch,
|
||||
SimilarityInterpolation>(combinations, predictions);
|
||||
}
|
||||
if (interpolationAlgorithm == "Average")
|
||||
{
|
||||
cf->Predict<PearsonSearch, AverageInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Regression")
|
||||
{
|
||||
cf->Predict<PearsonSearch, RegressionInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
else if (interpolationAlgorithm == "Similarity")
|
||||
{
|
||||
cf->Predict<PearsonSearch, SimilarityInterpolation>
|
||||
(combinations, predictions);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the root of the sum of the squared errors, divide by the number of
|
||||
@@ -482,12 +488,12 @@ static void mlpackMain()
|
||||
"SVDIncompleteIncremental", "SVDCompleteIncremental", "RegSVD",
|
||||
"RandSVD", "BiasSVD", "SVDPP" }, true, "unknown algorithm");
|
||||
|
||||
// Validate the interpolation and neighbour_search policy
|
||||
// Validate the interpolation and neighbor_search policy
|
||||
RequireParamInSet<string>("interpolation", { "Average",
|
||||
"Regression", "Similarity" }, true, "unknown interpolation algorithm");
|
||||
|
||||
RequireParamInSet<string>("neighbour_search", { "Cosine",
|
||||
"Euclidean", "Pearson" }, true, "unknown neighbour search algorithm");
|
||||
RequireParamInSet<string>("neighbor_search", { "Cosine",
|
||||
"Euclidean", "Pearson" }, true, "unknown neighbor search algorithm");
|
||||
|
||||
ReportIgnoredParam({{ "iteration_only_termination", true }}, "min_residue");
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class GetValueVisitor : public boost::static_visitor<void*>
|
||||
* PredictVisitor uses the CFType object to make predictions on the given
|
||||
* combinations of users and items.
|
||||
*/
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
class PredictVisitor : public boost::static_visitor<void>
|
||||
{
|
||||
@@ -78,7 +78,7 @@ class PredictVisitor : public boost::static_visitor<void>
|
||||
* RecommendationVisitor uses the CFType object to get recommendations for the
|
||||
* given users.
|
||||
*/
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
class RecommendationVisitor : public boost::static_visitor<void>
|
||||
{
|
||||
@@ -146,21 +146,21 @@ class CFModel
|
||||
const bool mit);
|
||||
|
||||
//! Make predictions.
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void Predict(const arma::Mat<size_t>& combinations,
|
||||
arma::vec& predictions);
|
||||
|
||||
//! Compute recommendations for query users.
|
||||
template<typename NeighbourSearchPolicy,
|
||||
template<typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void GetRecommendations(const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations,
|
||||
const arma::Col<size_t>& users);
|
||||
|
||||
//! Compute recommendations for all users.
|
||||
template<typename NeighbourSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template<typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void GetRecommendations(const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations);
|
||||
|
||||
|
||||
@@ -34,19 +34,19 @@ void* GetValueVisitor::operator()(CFType<DecompositionPolicy>* c) const
|
||||
return (void*) c;
|
||||
}
|
||||
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
PredictVisitor<NeighbourSearchPolicy,InterpolationPolicy>::PredictVisitor(
|
||||
PredictVisitor<NeighborSearchPolicy, InterpolationPolicy>::PredictVisitor(
|
||||
const arma::Mat<size_t>& combinations,
|
||||
arma::vec& predictions) :
|
||||
combinations(combinations),
|
||||
predictions(predictions)
|
||||
{ }
|
||||
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template<typename DecompositionPolicy>
|
||||
void PredictVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
void PredictVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
::operator()(CFType<DecompositionPolicy>* c) const
|
||||
{
|
||||
if (!c)
|
||||
@@ -55,13 +55,13 @@ void PredictVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
return;
|
||||
}
|
||||
|
||||
c->template Predict<NeighbourSearchPolicy,
|
||||
c->template Predict<NeighborSearchPolicy,
|
||||
InterpolationPolicy>(combinations, predictions);
|
||||
}
|
||||
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
RecommendationVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
RecommendationVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
::RecommendationVisitor(
|
||||
const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations,
|
||||
@@ -73,10 +73,10 @@ RecommendationVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
usersGiven(usersGiven)
|
||||
{ }
|
||||
|
||||
template <typename NeighbourSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template<typename DecompositionPolicy>
|
||||
void RecommendationVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
void RecommendationVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
::operator()(CFType<DecompositionPolicy>* c) const
|
||||
{
|
||||
if (!c)
|
||||
@@ -86,11 +86,11 @@ void RecommendationVisitor<NeighbourSearchPolicy, InterpolationPolicy>
|
||||
}
|
||||
|
||||
if (usersGiven)
|
||||
c->template GetRecommendations<NeighbourSearchPolicy,
|
||||
InterpolationPolicy>(numRecs, recommendations, users);
|
||||
c->template GetRecommendations<NeighborSearchPolicy, InterpolationPolicy>
|
||||
(numRecs, recommendations, users);
|
||||
else
|
||||
c->template GetRecommendations<NeighbourSearchPolicy,
|
||||
InterpolationPolicy>(numRecs, recommendations);
|
||||
c->template GetRecommendations<NeighborSearchPolicy, InterpolationPolicy>
|
||||
(numRecs, recommendations);
|
||||
}
|
||||
|
||||
CFModel::~CFModel()
|
||||
@@ -117,37 +117,37 @@ void CFModel::Train(const MatType& data,
|
||||
}
|
||||
|
||||
//! Make predictions.
|
||||
template <typename NeighbourSearchPolicy,
|
||||
template <typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void CFModel::Predict(const arma::Mat<size_t>& combinations,
|
||||
arma::vec& predictions)
|
||||
{
|
||||
PredictVisitor<NeighbourSearchPolicy,
|
||||
InterpolationPolicy> predict(combinations, predictions);
|
||||
PredictVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
predict(combinations, predictions);
|
||||
boost::apply_visitor(predict, cf);
|
||||
}
|
||||
|
||||
//! Compute recommendations for queried users.
|
||||
template<typename NeighbourSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template<typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void CFModel::GetRecommendations(const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations,
|
||||
const arma::Col<size_t>& users)
|
||||
{
|
||||
RecommendationVisitor<NeighbourSearchPolicy,
|
||||
InterpolationPolicy> recommendation(numRecs, recommendations, users, true);
|
||||
RecommendationVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
recommendation(numRecs, recommendations, users, true);
|
||||
boost::apply_visitor(recommendation, cf);
|
||||
}
|
||||
|
||||
//! Compute recommendations for all users.
|
||||
template<typename NeighbourSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
template<typename NeighborSearchPolicy,
|
||||
typename InterpolationPolicy>
|
||||
void CFModel::GetRecommendations(const size_t numRecs,
|
||||
arma::Mat<size_t>& recommendations)
|
||||
{
|
||||
arma::Col<size_t> users;
|
||||
RecommendationVisitor<NeighbourSearchPolicy,
|
||||
InterpolationPolicy> recommendation(numRecs, recommendations, users, false);
|
||||
RecommendationVisitor<NeighborSearchPolicy, InterpolationPolicy>
|
||||
recommendation(numRecs, recommendations, users, false);
|
||||
boost::apply_visitor(recommendation, cf);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user