-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathctr.h
More file actions
executable file
·94 lines (81 loc) · 2.8 KB
/
ctr.h
File metadata and controls
executable file
·94 lines (81 loc) · 2.8 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
// class for ctr
//
#ifndef CTR_H
#define CTR_H
#include "utils.h"
#include "corpus.h"
#include "data.h"
struct ctr_hyperparameter {
double a;
double b;
double lambda_u;
double lambda_v;
double learning_rate;
double alpha_smooth;
int random_seed;
int max_iter;
int save_lag;
int theta_opt;
int ctr_run;
int lda_regression;
void set(double aa, double bb,
double lu, double lv,
double lr, double as,
int rs, int mi, int sl,
int to, int cr, int lda_r) {
a = aa; b = bb;
lambda_u = lu; lambda_v = lv;
learning_rate = lr;
alpha_smooth = as;
random_seed = rs; max_iter = mi;
save_lag = sl; theta_opt = to;
ctr_run = cr; lda_regression = lda_r;
}
void save(char* filename) {
FILE * file = fopen(filename, "w");
fprintf(file, "a = %.4f\n", a);
fprintf(file, "b = %.4f\n", b);
fprintf(file, "lambda_u = %.4f\n", lambda_u);
fprintf(file, "lambda_v = %.4f\n", lambda_v);
fprintf(file, "learning_rate = %.6f\n", learning_rate);
fprintf(file, "alpha_smooth = %.6f\n", alpha_smooth);
fprintf(file, "random seed = %d\n", (int)random_seed);
fprintf(file, "max iter = %d\n", max_iter);
fprintf(file, "save lag = %d\n", save_lag);
fprintf(file, "theta opt = %d\n", theta_opt);
fprintf(file, "ctr run = %d\n", ctr_run);
fprintf(file, "lda_regression = %d\n", lda_regression);
fclose(file);
}
};
class c_ctr {
public:
c_ctr();
~c_ctr();
void read_init_information(const char* theta_init_path,
const char* beta_init_path,
const c_corpus* c, double alpha_smooth);
void set_model_parameters(int num_factors,
int num_users,
int num_items);
void learn_map_estimate(const c_data* users, const c_data* items,
const c_corpus* c, const ctr_hyperparameter* param,
const char* directory);
void stochastic_learn_map_estimate(const c_data* users, const c_data* items,
const c_corpus* c, const ctr_hyperparameter* param,
const char* directory);
void init_model(int ctr_run);
double doc_inference(const c_document* doc, const gsl_vector* theta_v,
const gsl_matrix* log_beta, gsl_matrix* phi,
gsl_vector* gamma, gsl_matrix* word_ss,
bool update_word_ss);
public:
gsl_matrix* m_beta;
gsl_matrix* m_theta;
gsl_matrix* m_U;
gsl_matrix* m_V;
int m_num_factors; // m_num_topics
int m_num_items; // m_num_docs
int m_num_users; // num of users
};
#endif // CTR_H