Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
44 lines (40 loc) · 1.39 KB

File metadata and controls

44 lines (40 loc) · 1.39 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include "predictor.h"
Predictor::Predictor(int nu, int nm, int nf) {
srand(0);
//srand(time(0));
num_users = nu; num_movies = nm; num_features = nf;
movie_features = new float[(nm+nu)*nf];
user_features = movie_features + (nm*nf);
for (int i=0; i<(nm+nu)*nf; i++)
movie_features[i] = rndn();
movie_avg = new double[nu+nm];
load_averages(movie_avg);
user_avg = movie_avg + nm;
average = 3.6033;
}
Predictor::~Predictor() {
delete [] movie_features;
// delete [] user_features;
delete [] movie_avg;
}
float Predictor::predict(int user, short movie) {
float sum = average + movie_avg[movie] + user_avg[user];
sum += cblas_sdot(num_features, &movie_features[movie*num_features],
1, &user_features[user*num_features], 1);
// for (int f=0; f<num_features; f++)
// sum += movie_features[movie][f] * user_features[user][f];
if (sum > 5) sum = 5;
if (sum < 1) sum = 1;
return sum;
}
double rndn() {
return 3*((double)rand()/RAND_MAX/5 - .1);
// the below uses the boost library to get normal random numbers
// not really necessary
/* using namespace boost;
static mt19937 rng(static_cast<unsigned> (time(0)));
normal_distribution<double> norm_dist(0, .1);
variate_generator<mt19937&, normal_distribution<double> >
normal_sampler(rng, norm_dist);
return normal_sampler(); */
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.