Commit fecf1b24 authored by Giovanne Marcelo's avatar Giovanne Marcelo

add omega structure

parent 6c078583
Pipeline #6391 passed with stage
in 4 minutes and 44 seconds
......@@ -40,7 +40,7 @@ INCL = -I./include
SRC = ./src
DEPS = ./include/db_interface.h ./include/log.h ./include/main.h ./include/data_prepare.h ./include/matrix.h \
./include/algorithm.h ./include/list.h
OBJ = db_interface.o log.o matrix.o data_prepare.o algorithm.o list.o main.o
OBJ = db_interface.o log.o matrix.o data_prepare.o list.o algorithm.o main.o
APP=recommender
all: $(APP)
......
......@@ -3,27 +3,30 @@
#include "matrix.h"
#include "list.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
typedef struct {
matrix residual;
matrix W;
matrix H;
list(long unsigned int, omegai);
list(long unsigned int, omegaj);
double lamb;
int k;
int T;
long unsigned int k;
long unsigned int T;
}algorithm_args;
void update_residual();
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);
double find_minimun(matrix residual, matrix W, matrix H, double lamb,list(long unsigned int, omega) ,long unsigned int t, long unsigned int i, void (*f)(double, double, double, double*, double*));
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);
void ccd(matrix residual, matrix W, matrix H,list(long unsigned int, omegai), list(long unsigned int, omegaj), double lamb, long unsigned int k,long unsigned int T);
#endif
......@@ -31,6 +31,8 @@
#ifndef _list_h
#define _list_h
#define typeof __typeof__
typedef struct list_head list_head;
typedef struct list_element list_element;
......
......@@ -40,35 +40,37 @@ void s(double r, double w, double h, double *numerator, double *denominator) {
}
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 find_minimun(matrix residual, matrix W, matrix H, double lamb,list(long unsigned int, omega) ,long unsigned int t, long unsigned int i, void (*f)(double, double, double, double*, double*)) {
double rij, wit, hjt, numerator, denominator;
for(int iter=0; iter < 50; iter++) {
rij = matrix_get(i, omega[iter]);
numerator = denominator = .0;
list_each_elem(omega,elem) {
rij = matrix_get(residual,i, *elem);
wit = matrix_get(W, i, t);
hjt = matrix_get(H, omega[iter], t);
hjt = matrix_get(H, *elem, t);
(*f)(rij, wit, hjt,&numerator, &denominator);
}
denominator += lamb;
return ( numerator / denominator );
}
void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T) {
void ccd(matrix residual, matrix W, matrix H, list(long unsigned int, omegai), list(long unsigned int, omegaj), double lamb, long unsigned int k,long unsigned int T) {
double rating, omegai[50], omegaj[50];
double rating;
for(int iter = 0; iter < T ; iter++) {
for(int i = 0; i < residual->size1 ; i++ ) {
for(int t = 0; t < k; t++) {
for(long unsigned int iter = 0; iter < T ; iter++) {
for(long unsigned int i = 0; i < residual->size1 ; i++ ) {
for(long unsigned int t = 0; t < k; t++) {
rating = find_minimun(residual, W, H, lamb, omegai, t, i, z);
update_residual();
matrix_set(W, i, t, rating);
}
}
for(int j = 0; j < residual->size2; j++) {
for(int t = 0; t < k; t++) {
for(long unsigned int j = 0; j < residual->size2; j++) {
for(long unsigned int t = 0; t < k; t++) {
rating = find_minimun(residual, W, H, lamb, omegaj, t, j, s);
update_residual();
matrix_set(H, j, t, rating);
......@@ -88,12 +90,13 @@ void ccd(matrix residual, matrix W, matrix H, double lamb, int k, int T) {
* end for
*/
void ccd_pp(matrix residual, matrix W, matrix H, double lamb, int k) {
/* void ccd_pp(matrix residual, matrix W, matrix H, double lamb, int k) {
}
*/
void perform(algorithm_args *args) {
ccd(args->residual, args->W, args->H, args->lamb, args->k);
ccd(args->residual, args->W, args->H, args->omegai, args->omegaj, args->lamb, args->k, args->T);
}
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