-
Notifications
You must be signed in to change notification settings - Fork 0
/
InferenceEngineNG.h
executable file
·107 lines (86 loc) · 2.51 KB
/
InferenceEngineNG.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef INFERENCEENGINENG_H_
#define INFERENCEENGINENG_H_
#include "NetflixDataNG.h"
#include "MassGaussianNode.h"
#include "Constant.h"
#include "DotProductGaussianAddNG.h"
#include "GaussianNode.h"
#include "PreProc.h"
#include "GammaNode.h"
#include <string>
#include <math.h>
#include <vector>
using namespace model;
using namespace utils;
using namespace std;
namespace infer {
class InferenceEngineNG {
private:
// Data accessor
NetflixDataNG data;
// Model elements
MassGaussianNode* DPusers;
MassGaussianNode* DPmovies;
MassGaussianNode* W;
MassGaussianNode* userAddition;
MassGaussianNode* movieAddition;
MassGaussianNode* userHistoryMultiplier1;
MassGaussianNode* userHistoryMultiplier3;
MassGaussianNode* userHistoryMultiplier5;
MassGaussianNode* userHistoryMultiplier10;
MassGaussianNode* userHistoryMultiplier30;
GaussianNode* allAdds;
GammaNode* precision;
DotProductGaussianAddNG* castFreeDPGA;
// Variables for internal use
bool debug;
bool test;
int startIteration;
double oldBound;
// Training dataset variables
q** qsByUser;
ushort* noViewingsPerUser;
user** usersByMovie;
rate** ratingsByMovie;
ushort** whatIndexAMovieIsToAUser;
ulong* noViewingsPerMovie;
public:
// Constructor and Destructor
InferenceEngineNG(bool isDebug, bool isTest, bool isOldSave,
string &loadPath, int xiStartIteration);
~InferenceEngineNG();
// This is really the main function
int go();
private:
// Important functions for the engine
void init();
void joinMeUp();
// Helper functions to get output file names.
string getKString();
string getSubmissionFileName(int iterations);
string getStatsFileName(int iterations);
string getSaveFileName(int iterations);
// IO Helper functions
void makeSubAndStatsFiles(int iterations);
void doSave(int its);
void save(string fileName);
void loadThisModel(string fileName, bool loadPriors);
void loadPreviousModel(string fileName, bool loadPriors);
void IO(string fileName, bool isSave, bool loadPriors);
void MakeStringStreamsSameLength(vector<stringstream*> xiSS);
void AppendToAll(vector<stringstream*> xiSS, string xiContent);
void OutputCurrentModelSummary();
// Inference functions
void update(int numIterations);
double calculateBound(int itNumber);
void getRMSEandBoundForObservedDataMatrix(double &bound, double &rmse,
double &obsVariance);
// Text output functions
void nB(string output);
void nb(string output);
// Ratings data helper functions
void readInViewings();
void dataIntegrityCheck();
};
}
#endif /*INFERENCEENGINENG_H_*/