SLIM
1.0
Sparse Linear Methods (SLIM) for top-n recommender systems
|
This file contains all prototypes. More...
Go to the source code of this file.
Functions | |
void | parse_cmdline (ctrl_t *ctrl, int argc, char *argv[]) |
Entry point of the command-line argument parsing. | |
ctrl_t * | create_ctrl () |
Create a ctrl structure wich contains all the default parameters for SLIM. | |
void | free_ctrl (ctrl_t *ctrl) |
Free a ctrl structure. | |
void | start_timer (ctimer_t *ctimer) |
Start a timer to record current time. | |
void | end_timer (ctimer_t *ctimer) |
End a timer to record a length of a duration. | |
void | display_timer (ctimer_t *ctimer, char *msg) |
Display a user-defined message and a duration length recorded by a timer. | |
int | count_nnz (double *array, int narray) |
Count the number of non-zero values in an array. | |
void | find_topk (double *w, int n, int topk, double *map, int *topk2) |
Find the top-k values from an array. | |
void | get_column (gk_csr_t *constraint, int i, double *w) |
Get a column from a csr matrix. | |
gk_csr_t * | read_constraint (ctrl_t *ctrl, char *file) |
Read in a constraint matrix for feature selection. | |
void | csr_Write (gk_csr_t *mat, char *filename, char *mode, int format, int writevals, int numbering) |
Dump the csr into a file. | |
void | check_train_test (ctrl_t *ctrl, gk_csr_t *train, gk_csr_t *test) |
Check if test data are already in train data. | |
int | call_back (BCLS *ls, void *UsrWrk) |
call_back function, periodically called by BCLS to test if the user wants to exit. This is from BCLS. | |
int | call_back_it (BCLS *ls, void *UsrWrk) |
call_back function, immediately terminate BCLS iterations based on how many iterations it runs | |
int | pretty_printer (void *io_file, char *msg) |
Pretty_printer, this is the print-routine that will be used by BCLS for its output. This is from BCLS. | |
void * | cs_free (void *p) |
Wrapper for free. | |
void * | cs_malloc (int n, size_t size) |
Wrapper for malloc. | |
void * | cs_calloc (int n, size_t size) |
Wrapper for calloc. | |
cs * | cs_spfree (cs *A) |
Free a sparse matrix. | |
cs * | cs_spalloc (int m, int n, int nzmax, int values, int triplet) |
Allocate a sparse matrix (triplet form or compressed-column form) | |
void | dload (const int n, const double alpha, double x[]) |
Load a constant into a vector. | |
int | Aprod (int mode, int m, int n, int nix, int ix[], double x[], double y[], void *UsrWrk) |
Aprod, matrix-vector products. This is from BCLS. | |
void | bcsol (ctrl_t *ctrl, gk_csr_t *AA, double *bb, double *x, worksp *Wrk, double *bl, double *bu, double beta, double *c) |
BCLS learning. This is from BCLS. | |
void | slim_learn (ctrl_t *ctrl, gk_csr_t *train) |
SLIM learning. | |
void | slim_fs_learn (ctrl_t *ctrl, gk_csr_t *A, double *b, double *w, float **A_colval, worksp *Wrk, double *bl, double *bu, double beta, double *c) |
SLIM learning with feature selction. | |
void | preprocess (ctrl_t *ctrl, gk_csr_t *train, gk_csr_t *test) |
Pre-process the data. | |
double * | slim_test (ctrl_t *ctrl, gk_csr_t *model, gk_csr_t *train, gk_csr_t *test) |
Top-N recommendations and evaluations. | |
int | suggest_predict (ctrl_t *ctrl, gk_csr_t *model, int **iidx, gk_csr_t *train, int u, gk_dkv_t **rcmd) |
Top-N recommendation for a user. | |
void | slim_predict (ctrl_t *ctrl, gk_csr_t *train, gk_csr_t *test, gk_csr_t *model) |
SLIM testing. | |
This file contains all prototypes.
Definition in file proto.h.
int Aprod | ( | int | mode, |
int | m, | ||
int | n, | ||
int | nix, | ||
int | ix[], | ||
double | x[], | ||
double | y[], | ||
void * | UsrWrk | ||
) |
Aprod, matrix-vector products. This is from BCLS.
If mode == BCLS_PROD_A (0), compute y <- A *x, with x untouched; and if mode == BCLS_PROD_At (1), compute x <- A'*y, with y untouched.
Definition at line 163 of file bcsol.c.
References worksp::A, worksp::acol, cs_sparse::i, cs_sparse::p, and cs_sparse::x.
Referenced by bcsol().
void bcsol | ( | ctrl_t * | ctrl, |
gk_csr_t * | AA, | ||
double * | bb, | ||
double * | x, | ||
worksp * | Wrk, | ||
double * | bl, | ||
double * | bu, | ||
double | beta, | ||
double * | c | ||
) |
BCLS learning. This is from BCLS.
This is to solve the problem
Definition at line 247 of file bcsol.c.
References Aprod(), bcls_niters, call_back(), call_back_it(), ctrl_t::dbglvl, ctrl_t::max_bcls_niters, ctrl_t::optTol, and pretty_printer().
Referenced by slim_fs_learn(), and slim_learn().
void check_train_test | ( | ctrl_t * | ctrl, |
gk_csr_t * | train, | ||
gk_csr_t * | test | ||
) |
Check if test data are already in train data.
[in] | ctrl | A ctrl structure |
[in] | train | The training data |
[in] | test | The testing data |
Definition at line 19 of file check.c.
Referenced by preprocess().
int count_nnz | ( | double * | array, |
int | narray | ||
) |
Count the number of non-zero values in an array.
[in] | array | An array whose non-zero values will be counted |
[in] | narray | The length of the array |
Definition at line 134 of file util.c.
References EPSILON2.
Referenced by slim_fs_learn().
ctrl_t* create_ctrl | ( | ) |
Create a ctrl structure wich contains all the default parameters for SLIM.
Definition at line 21 of file util.c.
References ctrl_t::beta, ctrl_t::bl, ctrl_t::bsize, ctrl_t::bu, ctrl_t::dbglvl, ctrl_t::endi, ctrl_t::fs, ctrl_t::fs_file, ctrl_t::k, ctrl_t::lambda, ctrl_t::max_bcls_niters, ctrl_t::model_file, ctrl_t::nratings, ctrl_t::optTol, ctrl_t::pred_file, ctrl_t::starti, ctrl_t::test_file, ctrl_t::topn, ctrl_t::train_file, and ctrl_t::transpose.
Referenced by main(), and parse_cmdline().
void display_timer | ( | ctimer_t * | ctimer, |
char * | msg | ||
) |
Display a user-defined message and a duration length recorded by a timer.
[in] | ctimer | A timer with a length of a duration recorded |
[in] | msg | A user-defined message to display |
Definition at line 116 of file util.c.
References ctimer_t::end, and ctimer_t::start.
Referenced by slim_learn(), and slim_test().
void end_timer | ( | ctimer_t * | ctimer | ) |
End a timer to record a length of a duration.
[in] | ctimer | A timer to end |
Definition at line 101 of file util.c.
References ctimer_t::end.
Referenced by slim_learn(), and slim_test().
void find_topk | ( | double * | w, |
int | n, | ||
int | topk, | ||
double * | map, | ||
int * | topk2 | ||
) |
Find the top-k values from an array.
[in] | w | The array whose top-k values will be found |
[in] | n | The length of the array w |
[in] | topk | The number of top values to be found |
[out] | map | The array of indices that correspond to the top-k values in the input array |
[out] | topk2 | The actual number of top values that are found |
Definition at line 159 of file util.c.
Referenced by slim_fs_learn().
void free_ctrl | ( | ctrl_t * | ctrl | ) |
Free a ctrl structure.
[in] | ctrl | A pointer to a ctrl structure to be freed |
Definition at line 68 of file util.c.
References ctrl_t::fs_file, ctrl_t::model_file, ctrl_t::pred_file, ctrl_t::test_file, and ctrl_t::train_file.
Referenced by main().
void get_column | ( | gk_csr_t * | constraint, |
int | i, | ||
double * | w | ||
) |
Get a column from a csr matrix.
[in] | constraint | A matrix from which one column is to be retrievd |
[in] | i | The index of the column to be retrieved |
[out] | w | The output vector which saves the retrieved column |
Definition at line 194 of file util.c.
Referenced by slim_learn().
void parse_cmdline | ( | ctrl_t * | ctrl, |
int | argc, | ||
char * | argv[] | ||
) |
Entry point of the command-line argument parsing.
[out] | ctrl | A ctrl structure to be filled out |
[in] | argc | Number of arguments |
[in] | argv | A list of arguments |
Definition at line 146 of file cmd.c.
References ctrl_t::beta, ctrl_t::bsize, CMD_BETA, CMD_BSIZE, CMD_DBGLVL, CMD_ENDI, CMD_FS, CMD_FS_FILE, CMD_HELP, CMD_K, CMD_LAMBDA, CMD_MAX_BCLS_NITERS, CMD_MODEL_FILE, CMD_NRATINGS, CMD_OPTTOL, CMD_PRED_FILE, CMD_STARTI, CMD_TEST_FILE, CMD_TOPN, CMD_TRAIN_FILE, CMD_TRANSPOSE, create_ctrl(), ctrl_t::dbglvl, ctrl_t::endi, ctrl_t::fs, ctrl_t::fs_file, ctrl_t::k, ctrl_t::lambda, ctrl_t::max_bcls_niters, ctrl_t::model_file, ctrl_t::nratings, ctrl_t::optTol, ctrl_t::pred_file, ctrl_t::starti, ctrl_t::test_file, ctrl_t::topn, ctrl_t::train_file, and ctrl_t::transpose.
Referenced by main().
void slim_fs_learn | ( | ctrl_t * | ctrl, |
gk_csr_t * | A, | ||
double * | b, | ||
double * | w, | ||
float ** | A_colval, | ||
worksp * | Wrk, | ||
double * | bl, | ||
double * | bu, | ||
double | beta, | ||
double * | c | ||
) |
SLIM learning with feature selction.
[in] | ctrl | A ctrl structure which contains all the parameters for SLIM Learning with feature selection |
[in] | A | The A matrix |
[in] | b | The RHS vector |
[in,out] | w | The solution vector |
[in] | A_colval | A temporary place for a column |
[in] | Wrk | A workspace for BCLS |
[in] | bl | The lower bound for BCLS |
[in] | bu | The upper bound for BCLS |
[in] | beta | The regularization parameter for L-2 norm |
[in] | c | The vector for L-1 norm |
Definition at line 31 of file slim_fs_learn.c.
References worksp::acol, bcsol(), count_nnz(), find_topk(), and ctrl_t::k.
Referenced by slim_learn().
void slim_learn | ( | ctrl_t * | ctrl, |
gk_csr_t * | train | ||
) |
SLIM learning.
This routine contains the learning algorithm for SLIM
[in] | ctrl | A ctrl structure which contains all the parameters for SLIM learning |
[in] | train | The training data |
Definition at line 22 of file slim_learn.c.
References worksp::A, worksp::acol, bcsol(), ctrl_t::beta, ctrl_t::bl, ctrl_t::bsize, ctrl_t::bu, csr_Write(), display_timer(), end_timer(), ctrl_t::endi, EPSILON, ctrl_t::fs, ctrl_t::fs_file, get_column(), cs_sparse::i, ctrl_t::lambda, cs_sparse::m, ctrl_t::max_bcls_niters, worksp::max_bcls_niters, ctrl_t::model_file, cs_sparse::n, cs_sparse::nz, cs_sparse::nzmax, cs_sparse::p, read_constraint(), slim_fs_learn(), start_timer(), ctrl_t::starti, and cs_sparse::x.
Referenced by main().
void slim_predict | ( | ctrl_t * | ctrl, |
gk_csr_t * | train, | ||
gk_csr_t * | test, | ||
gk_csr_t * | model | ||
) |
SLIM testing.
This routine contains the testing method for SLIM
[in] | ctrl | A ctrl structure which contains all the Parameters for SLIM testing |
[in] | train | The training data, which has been used to learn the model |
[in] | test | The testing data |
[in] | model | The model |
Definition at line 26 of file slim_predict.c.
References ctrl_t::nratings, and slim_test().
Referenced by main().
double* slim_test | ( | ctrl_t * | ctrl, |
gk_csr_t * | model, | ||
gk_csr_t * | train, | ||
gk_csr_t * | test | ||
) |
Top-N recommendations and evaluations.
[in] | ctrl | A ctrl structure |
[in] | model | A model |
[in] | train | The training data from which the model is learned |
[in] | test | The testing data |
Definition at line 60 of file slim_predict.c.
References ctrl_t::dbglvl, display_timer(), end_timer(), ctrl_t::nratings, ctrl_t::pred_file, start_timer(), and suggest_predict().
Referenced by slim_predict().
void start_timer | ( | ctimer_t * | ctimer | ) |
Start a timer to record current time.
[in] | ctimer | A timer to start |
Definition at line 88 of file util.c.
References ctimer_t::start.
Referenced by slim_learn(), and slim_test().
int suggest_predict | ( | ctrl_t * | ctrl, |
gk_csr_t * | model, | ||
int ** | iidx, | ||
gk_csr_t * | train, | ||
int | u, | ||
gk_dkv_t ** | rcmd | ||
) |
Top-N recommendation for a user.
[in] | ctrl | A ctrl structure |
[in] | model | A model |
[in] | iidx | An auxiliary array for efficient recommendations |
[in] | train | Training data from which the model is learned |
[in] | u | The index of the user for which the top-n recommendations are generated |
[out] | rcmd | The list of recommendations, in which the keys are the recommendation scores and the values are the item indices |
Definition at line 228 of file slim_predict.c.
References ctrl_t::topn.
Referenced by slim_test().