Commit d83dbcb1 authored by Giovanne Marcelo's avatar Giovanne Marcelo

add first z and s functions

parent 36a89974
Pipeline #6384 failed with stage
in 4 minutes and 59 seconds
......@@ -15,10 +15,8 @@ typedef struct {
void update_residual();
void update_wit();
void update_hjt();
void z();
void s();
void z(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i);
void s(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i);
void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T);
void ccd_pp(matrix residual, matrix W, matrix H, double lamb, int k);
void perform(algorithm_args *args);
......
......@@ -11,6 +11,6 @@ typedef gsl_matrix* matrix;
matrix matrix_alloc(long unsigned int rows, long unsigned int cols);
void print_matrix(matrix m);
void matrix_copy(matrix dest, matrix src);
void matrix_set(matrix m, int i, int j, double x);
double matrix_get(matrix m, int i, int j);
void matrix_set(matrix m, long unsigned int row, long unsigned int col, double x);
double matrix_get(matrix m, long unsigned int row, long unsigned int col);
#endif
......@@ -28,18 +28,57 @@
*/
void update_residual() {}
double z(matrix residual, matrix W, matrix H, double lamb) {}
double s(matrix residual, matrix W, matrix H, double lamb) {}
double z(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i) {
double rij, wit, hjt, aux, aux2;
for(int iter=0; iter < residual->size1; iter++) {
rij = matrix_get(i, omega[iter]);
wit = matrix_get(W, i, t);
hjt = matrix_get(H, omega[iter], t);
aux += (rij + wit * hjt) * hjt;
}
for(int iter=0; iter < residual->size1; iter++) {
hjt = matrix_get(H, omega[iter], t);
aux2 += hjt * hjt;
}
return ( aux / (lamb + aux2) );
}
double s(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i) {
double rij, wit, hjt, aux, aux2;
for(int iter=0; iter < residual->size1; iter++) {
rij = matrix_get(i, omega[iter]);
wit = matrix_get(W, i, t);
hjt = matrix_get(H, omega[iter], t);
aux += (rij + wit * hjt) * wit;
}
for(int iter=0; iter < residual->size1; iter++) {
wit = matrix_get(W, i, t);
aux2 += wit * wit;
}
return ( aux / (lamb + aux2) );
}
void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T) {
double rating;
double rating, omega[50];
for(int iter = 0; iter < T ; iter++) {
for(int i = 0; i < residual->size1 ; i++ ) {
for(int t = 0; t < k; t++) {
rating = z();
rating = z(residual, W, H, lamb, omega, t, i);
update_residual();
matrix_set(W, i, t, rating);
}
......@@ -47,7 +86,7 @@ void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T) {
for(int j = 0; j < residual->size2; j++) {
for(int t = 0; t < k; t++) {
rating = s();
rating = s(residual, W, H, lamb, omega, t, i);
update_residual();
matrix_set(H, j, t, rating);
}
......
......@@ -12,12 +12,12 @@ matrix matrix_alloc(long unsigned int rows, long unsigned int cols) {
return gsl_matrix_alloc(rows, cols);
}
void matrix_set(matrix m, int i, int j, double x) {
gsl_matrix_set(m, i, j, x);
void matrix_set(matrix m, long unsigned int row, long unsigned int col, double x) {
gsl_matrix_set(m, row, col, x);
}
double matrix_get(matrix m, int i, int j) {
return gsl_matrix_get(m, i, j);
double matrix_get(matrix m, long unsigned int row, long unsigned int col) {
return gsl_matrix_get(m, row, col);
}
void print_matrix(matrix m) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment