#ifndef __TREF_HPP__ #define __TREF_HPP__ #include typedef long unsigned int objectID; typedef long unsigned int userID; namespace tref { class rating { public: objectID o; userID u; double value; rating(objectID _o, userID _u, double _value); }; // class __tref // Base class for all iterative refinement algorithms. // Contains only minimally needed info and functions. class __tref { protected: bool verbose; std::vector ratings; std::vector quality; std::vector weight; double beta; double epsilon; double convergence; virtual void addLink(objectID o, userID u); virtual void iterationInit(); virtual double qualityUpdate(); virtual void weightUpdate(); public: __tref(long unsigned int _objects, long unsigned int _users, long unsigned int _links, double _beta, double _epsilon, double _convergence, bool _verbose); void addRating(objectID o, userID u, double value); unsigned int iterationCycle(); long unsigned int objects(); long unsigned int users(); long unsigned int links(); double objectQuality(objectID o); double userWeight(userID u); void printRatings(); }; // class smalltref : public __tref // Memory-efficient but slow algorithm. class smalltref : public __tref { protected: std::vector qualityLast; std::vector weightSum; std::vector userLinks; virtual void addLink(objectID o, userID u); virtual double qualityUpdate(); virtual void weightUpdate(); public: smalltref(long unsigned int _objects, long unsigned int _users, long unsigned int _links, double _beta, double _epsilon, double _convergence, bool _verbose); }; // class bigtref : public __tref // Supposedly faster algorithm, but needs more memory. // Extra allocation required may actually make it slower // in many cases. class bigtref : public __tref { protected: std::vector< std::vector > objectRatings; std::vector< std::vector > userRatings; std::vector objectLinks; std::vector userLinks; virtual void iterationInit(); virtual double qualityUpdate(); virtual void weightUpdate(); public: bigtref(long unsigned int _objects, long unsigned int _users, long unsigned int _links, double _beta, double _epsilon, double _convergence, bool _verbose); }; } #endif /* __TREF_HPP__ */