Commit f69b999a authored by Giovanne Marcelo's avatar Giovanne Marcelo

improve z and s functions#1

parent d83dbcb1
Pipeline #6385 failed with stage
in 4 minutes and 53 seconds
......@@ -14,9 +14,12 @@ typedef struct {
void update_residual();
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);
double find_minimun(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i, void (*f)(double, double, double, double*, double*));
void z(double r, double w, double h, double *numerator, double *denominator);
void s(double r, double w, double h, double *numerator, double *denominator);
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);
......
......@@ -29,64 +29,47 @@
void update_residual() {}
void z(double r, double w, double h, double *numerator, double *denominator ) {
*numerator += (r + w * h) * h;
*denominator += h * h;
}
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) );
void s(double r, double w, double h, double *numerator, double *denominator) {
*numerator += (r + h * w) * w;
*denominator += w * w;
}
double s(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i) {
double rij, wit, hjt, aux, aux2;
double find_minimun(matrix residual, matrix W, matrix H, double lamb, double omega[50], int t, int i, void (*f)(double, double, double, double*, double*)) {
double rij, wit, hjt, numerator, denominator;
for(int iter=0; iter < residual->size1; iter++) {
for(int iter=0; iter < 50; 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;
(*f)(rij, wit, hjt,&numerator, &denominator);
}
for(int iter=0; iter < residual->size1; iter++) {
wit = matrix_get(W, i, t);
aux2 += wit * wit;
}
return ( aux / (lamb + aux2) );
denominator += lamb;
return ( numerator / denominator );
}
void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T) {
double rating, omega[50];
double rating, omegai[50], omegaj[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(residual, W, H, lamb, omega, t, i);
rating = find_minimun(residual, W, H, lamb, omegai, t, i, z);
update_residual();
matrix_set(W, i, t, rating);
matrix_set(W, i, t, rating);
}
}
for(int j = 0; j < residual->size2; j++) {
for(int t = 0; t < k; t++) {
rating = s(residual, W, H, lamb, omega, t, i);
rating = find_minimun(residual, W, H, lamb, omegaj, t, j, s);
update_residual();
matrix_set(H, j, t, rating);
}
......
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