#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include “math.h“#include #include using namespace std;//_DIFFUSE_ _RANDOM_ _HEAT_ _UCF_ _ICF_//AMAZON NETFLIX DELICIOUS DELICIOUS2 MOVIELENS/****#define _ICF_ //定义各种算法#define AMAZON#define LENGTH 5#define INFILE “Data/Amazon/train.txt“#define OUTDIR “Result/Recommendation/Amazon/“****/#define _ICF_#define AMAZON#define LENGTH 1#define INFILE “Data/Test/training.txt“#define OUTDIR “Result/Recommendation/Amazon/“typedef set IDList;typedef vector IntList;typedef vector MovieList;typedef vector UserList;typedef map IDMap; // String to inttypedef vector IDVector;typedef vector DoubleVector;struct Edge{ string UID; string PID;};struct Rank{ long int ID; double Value;};struct RankCompare{ bool operator()(const Rank & d1 const Rank & d2) //操作符重载 { return ( (d1.Value > d2.Value) ); };};bool Greater(const Rank & d1 const Rank & d2){ return d1.Value < d2.Value;};//typedef set PredictionSet;typedef vector< Rank > PredictionSet; typedef vector< IntList > UserRecommendation;class Recommender {private: long int userNumber; long int movieNumber; double globalSeed; IDMap userMap; IDMap movieMap; MovieList movies; UserList users; DoubleVector userVector; DoubleVector movieVector; PredictionSet preSet; IDList diffuseUsers; IDList diffuseMovies; IntList recommendation; UserRecommendation userRList;public: IDVector uidVector; IDVector pidVector;public: Recommender(void); ~Recommender(void){}; // process the data void ReadTrainingData(const char* fileName); //读取数据 void Initial(); long int GetUserNumber(); long int GetMovieNumber(); IntList DiffusePrediction(long int uid); IntList HeatPrediction(long int uid); IntList UCFPrediction(long int uid); IntList ICFPrediction(long int uid); void Run(); UserRecommendation GetURList(); void WriteBipartite(char * fileName); void WriteInfo(); void PrintUsers(); void PrintMovies(); template void PrintList(dataType mList);};Recommender::Recommender(void){ string s; IDVector uidVector; IDVector pidVector; uidVector.push_back(s); pidVector.push_back(s); IDList temp1; UserList users(1temp1); MovieList movies(1temp1); this->userNumber = 0; this->movieNumber = 0; this->users = users; this->movies = movies; this->uidVector = uidVector; this->pidVector = pidVector; this->globalSeed = 0;}#if defined(NETFLIX) || defined(MOVIELENS) || defined(DELICIOUS2) || defined(AMAZON)void Recommender::Read
共有 条评论
评论
共有 条评论