Commit c8828594 authored by Giovanne Marcelo's avatar Giovanne Marcelo

change list

parent 08aa217a
Pipeline #6402 failed with stage
in 5 minutes and 58 seconds
......@@ -23,7 +23,6 @@ CFLAGS = -std=c99 -g -O3 \
-Wold-style-definition \
-Woverlength-strings \
-Wpacked \
-Wpadded \
-Wpointer-arith \
-Wredundant-decls \
-Wshadow \
......@@ -34,13 +33,15 @@ CFLAGS = -std=c99 -g -O3 \
-Wundef \
-Wunsafe-loop-optimizations \
-Wvolatile-register-var \
-Wwrite-strings
LFLAGS = -lpq -ljansson -lgsl -lgslcblas -lm
-Wwrite-strings
CFLAGS += `pkg-config --cflags glib-2.0`
LFLAGS = -lpq -ljansson -lgsl -lgslcblas -lm
LFLAGS += `pkg-config --libs glib-2.0`
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 list.o algorithm.o main.o
./include/algorithm.h
OBJ = db_interface.o log.o matrix.o data_prepare.o algorithm.o main.o
APP=recommender
all: $(APP)
......
......@@ -2,19 +2,15 @@
#define _ALGORITHM_H
#include "matrix.h"
#include "list.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <glib.h>
#define double_args double, double, double, double*, double*
typedef struct {
list(long unsigned int, *data);
}omega;
#define omega GSList**
typedef struct {
matrix residual;
......@@ -31,16 +27,16 @@ typedef struct {
void ccd(algorithm_args *args);
void ccd_pp(matrix residual, matrix W, matrix H, double lamb, int k);
void perform(algorithm_args *args);
void update_row_residual(matrix residual, list(long unsigned int, omegaj),
void update_row_residual(matrix residual, GSList * omegaj,
double s, matrix W, matrix H, long unsigned int j,
long unsigned int t);
void update_col_residual(matrix residual, list(long unsigned int, omegai),
void update_col_residual(matrix residual, GSList * omegai,
double z, matrix W, matrix H, long unsigned int i,
long unsigned int t);
void z(double r, double w, double h, double *numerator, double *denominator);
void s(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, om) ,long unsigned int t,
GSList * om ,long unsigned int t,
long unsigned int i, void (*f)(double_args));
#endif
This diff is collapsed.
......@@ -4,5 +4,6 @@
#include "db_interface.h"
#include "data_prepare.h"
#include "log.h"
#include <glib.h>
#endif
......@@ -37,8 +37,8 @@ void ccd(algorithm_args *args) {
for(long unsigned int i = 0; i < args->residual->size1 ; i++ ) {
for(long unsigned int t = 0; t < args->k; t++) {
rating = find_minimun(args->residual, args->W, args->H, args->lamb, \
args->omegai.data[i], t, i, z);
update_col_residual(args->residual, args->omegai.data[i], rating, \
args->omegai[i], t, i, z);
update_col_residual(args->residual, args->omegai[i], rating, \
args->W, args->H, i, t ) ;
matrix_set(args->W, i, t, rating);
}
......@@ -47,8 +47,8 @@ void ccd(algorithm_args *args) {
for(long unsigned int j = 0; j < args->residual->size2; j++) {
for(long unsigned int t = 0; t < args->k; t++) {
rating = find_minimun(args->residual, args->W, args->H, args->lamb, \
args->omegaj.data[j], t, j, s);
update_row_residual(args->residual, args->omegaj.data[j], rating, \
args->omegaj[j], t, j, s);
update_row_residual(args->residual, args->omegaj[j], rating, \
args->W, args->H, j, t);
matrix_set(args->H, j, t, rating);
}
......@@ -73,16 +73,15 @@ void ccd(algorithm_args *args) {
*/
void perform(algorithm_args *args) {
ccd(args);
}
void update_col_residual(matrix residual, list(long unsigned int, omegai),
void update_col_residual(matrix residual, GSList * omegai,
double z, matrix W, matrix H, long unsigned int i,
long unsigned int t) {
list_each_elem(omegai, elem) {
for(guint iter = 0; iter < g_slist_length(omegai); iter++) {
long unsigned int *elem = (long unsigned int*) g_slist_nth_data(omegai, iter);
double Rij = matrix_get(residual, i, *elem);
double Wit = matrix_get(W, i, t);
double Hjt = matrix_get(H, *elem, t);
......@@ -91,11 +90,12 @@ void update_col_residual(matrix residual, list(long unsigned int, omegai),
}
}
void update_row_residual(matrix residual, list(long unsigned int, omegaj),
void update_row_residual(matrix residual, GSList * omegaj,
double s, matrix W, matrix H, long unsigned int j,
long unsigned int t) {
list_each_elem(omegaj, elem) {
for(guint iter = 0; iter < g_slist_length(omegaj); iter++){
long unsigned int* elem = (long unsigned int*) g_slist_nth_data(omegaj, iter);
double Rij = matrix_get(residual, *elem, j);
double Wit = matrix_get(W, *elem, t);
double Hjt = matrix_get(H, j, t);
......@@ -115,14 +115,15 @@ void s(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, om) ,long unsigned int t,
GSList * om ,long unsigned int t,
long unsigned int i,void (*f)(double_args)) {
double Rij, Wit, Hjt, numerator, denominator;
numerator = denominator = .0;
list_each_elem(om,elem) {
for(guint iter = 0; iter < g_slist_length(om); iter++) {
long unsigned int * elem = (long unsigned int*) g_slist_nth_data(om, iter);
Rij = matrix_get(residual,i, *elem);
Wit = matrix_get(W, i, t);
Hjt = matrix_get(H, *elem, t);
......
/* vim: set ft=c et ts=3 sw=3 sts=3:
*
* Copyright (C) 2013 James McLaughlin. All rights reserved.
* http://github.com/udp/list
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "list.h"
/* This file contains private helper functions for the macros defined in list.h.
*
* These functions provide the actual linked list logic, keeping it out of the
* macros (and therefore out of anything but list.o).
*/
struct list_head
{
list_element * first, * last;
size_t length;
};
struct list_element
{
list_head * list;
list_element * prev, * next;
};
static list_element * get_element (list_element * elem)
{
return elem ? (elem - 1) : 0;
}
static void * get_value_ptr (list_element * elem)
{
return elem ? (elem + 1) : 0;
}
size_t _list_length (list_head * list)
{
return list ? list->length : 0;
}
void _list_push (list_head ** p_list, size_t value_size, void * value)
{
if (!*p_list)
*p_list = (list_head *) calloc (sizeof (list_head), 1);
list_head * list = *p_list;
++ list->length;
list_element * elem = (list_element *)
malloc (sizeof (*elem) + value_size);
memset (elem, 0, sizeof (*elem));
memcpy (get_value_ptr (elem), value, value_size);
elem->list = list;
elem->prev = list->last;
if (list->last)
{
list->last->next = elem;
list->last = elem;
}
else
{
list->first = list->last = elem;
}
}
void _list_push_front (list_head ** p_list, size_t value_size, void * value)
{
if (!*p_list)
*p_list = (list_head *) calloc (sizeof (list_head), 1);
list_head * list = *p_list;
++ list->length;
list_element * elem = (list_element *)
malloc (sizeof (*elem) + value_size);
memset (elem, 0, sizeof (*elem));
memcpy (get_value_ptr (elem), value, value_size);
elem->list = list;
elem->next = list->first;
if (list->first)
{
list->first->prev = elem;
list->first = elem;
}
else
{
list->first = list->last = elem;
}
}
list_element * _list_front (list_head * list)
{
return list ? (list_element *) get_value_ptr (list->first) : 0;
}
list_element * _list_back (list_head * list)
{
return list ? (list_element *) get_value_ptr (list->last) : 0;
}
list_element * _list_next (list_element * elem)
{
if (!elem || ! (elem = get_element (elem)->next))
return 0;
return (list_element *) get_value_ptr (elem);
}
list_element * _list_prev (list_element * elem)
{
if (!elem || ! (elem = get_element (elem)->prev))
return 0;
return (list_element *) get_value_ptr (elem);
}
void _list_remove (list_element * elem)
{
if (!elem)
return;
elem = get_element (elem);
list_head * list = elem->list;
-- list->length;
if (elem->next)
elem->next->prev = elem->prev;
if (elem->prev)
elem->prev->next = elem->next;
if (elem == list->first)
list->first = elem->next;
if (elem == list->last)
list->last = elem->prev;
free (elem);
}
void _list_clear (list_head ** list, size_t value_size)
{
if (!*list)
return;
list_element * elem = (*list)->first;
while (elem)
{
list_element * next = elem->next;
free (elem);
elem = next;
}
free (*list);
*list = 0;
}
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