-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMatrixFactorization.h
More file actions
executable file
·97 lines (74 loc) · 1.95 KB
/
MatrixFactorization.h
File metadata and controls
executable file
·97 lines (74 loc) · 1.95 KB
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
#ifndef __MATRIX_FACTORIZATION__
#define __MATRIX_FACTORIZATION__
#include "SparseMatrix.h"
#include "LatentFactorModel.h"
#include <pthread.h>
#include <time.h>
#include <string>
#include <math.h>
#include <cstring>
#include <algorithm>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
#define T_REGRESS 1
#define T_CLASSIFY 2
#define LIMITED_EPOCHES 100
#define LIMITED_VALIDATE 10
class LatentFactorModel;
class MfParams{
public:
int type;
int num_factor;
double sigma;
double lambda;
int max_epoch;
double alpha;
int validate;
public:
MfParams();
MfParams(int _type, int _num_factor, double _sigma, double _lambda, int _max_epoch, double _alpha, int _validate);
};
class MatrixFactorization{
public:
static pthread_rwlock_t rwlock;
private:
typedef struct{
int row;
int col;
double val;
}Triplet;
Triplet* data;
double loss_train[LIMITED_EPOCHES];
double loss_validate[LIMITED_EPOCHES];
double clf_err_train[LIMITED_EPOCHES];
double clf_err_validate[LIMITED_EPOCHES];
int num_train;
int num_validate;
MfParams* _params;
SparseMatrix* _matrix;
LatentFactorModel* _model;
public:
MatrixFactorization();
LatentFactorModel* train(MfParams* params, SparseMatrix* matrix, string path);
void validate(int start, int end, int epoch);
double predict(Triplet* p);
void test(string in, string out);
MfParams* getMfParams(){ return _params; }
void setMfParams(MfParams* params){
_params = params;
}
SparseMatrix* getSparseMatrix(){return _matrix;}
void setSparseMatrix(SparseMatrix* matrix){
_matrix = matrix;
}
LatentFactorModel* getLatentFactorModel(){return _model;}
void setLatentFactorModel(LatentFactorModel* model){
_model = model;
}
~MatrixFactorization();
static void* run_helper(void *params);
};
#endif