-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBatchPoissonWeight.h
100 lines (71 loc) · 2.49 KB
/
BatchPoissonWeight.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
//
// Created by eliezer on 12.12.16.
//
#include <cmath>
#include "BatchPoissonPure.h"
#ifndef POISSON_SCR_CPP_BATCHPOISSONWEIGHT_H
#define POISSON_SCR_CPP_BATCHPOISSONWEIGHT_H
class scalar_gamma_latent {
public:
double a_latent;
double b_latent;
double e_expected;
double elog_expected;
double exp_elog_expected;
double a;
double b;
bool is_learn=false;
scalar_gamma_latent(double a, double b, bool is_learn=false);
scalar_gamma_latent(double val);
scalar_gamma_latent();
void update_latent(double a_val, double b_val);
void update_expected();
double operator *( double val){
return e_expected*val;
}
double operator *( int val){
return e_expected*(double)val;
}
double operator *( size_t val){
return e_expected*(double)val;
}
double elbo_term(){
if(!is_learn)
return 0;
return gamma_term(a,b,a_latent,b_latent,e_expected,elog_expected);
}
friend std::ostream &operator<<(std::ostream &os, const scalar_gamma_latent &var){
os << "{\"a\" : " << var.a
<< ",\"b\":" << var.b ;
os << ",\"a_latent\" : "<< var.a_latent;
os << ",\"b_latent\" : "<< var.b_latent;
os << ",\"exp\" : "<< var.e_expected;
os << ",\"logexp\" : " << var.elog_expected;
os << ",\"is_learn\" : " << "\""+to_string(var.is_learn)+"\""
<<"}";
os << endl;
return os;
}
};
class BatchPoissonWeight : public BatchPoissonNewArray {
public:
bool relative_weight_learn;
scalar_gamma_latent lambda_content;
scalar_gamma_latent lambda_social;
vector< double > sum_items;
BatchPoissonWeight(size_t n_ratings, size_t n_wd_entries, size_t n_users, size_t n_items,
size_t k_feat, size_t n_words, size_t n_max_neighbors,
double lambda_a, double lambda_b, bool learn ,double a, double b,
double c, double d, double e, double f, double g, double h, double k, double l);
void update_latent();
vector<vector<double>> estimate();
double compute_elbo();
double tau_elbo_expected_linear_term();
void init_train(vector<tuple<size_t, size_t, size_t>> r_entries, vector<tuple<size_t, size_t, size_t>> w_entries,
vector<vector<size_t>> user_neighboors);
void update_aux_latent();
virtual ~BatchPoissonWeight(){
}
void train(size_t n_iter, double tol);
};
#endif //POISSON_SCR_CPP_BATCHPOISSONWEIGHT_H