SLIM  1.0
Sparse Linear Methods (SLIM) for top-n recommender systems
 All Data Structures Files Functions Variables Typedefs Macros Pages
Functions
slim_fs_learn.c File Reference

This file contains all the routines for SLIM learning with feature selection. More...

#include <slim.h>

Go to the source code of this file.

Functions

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.
 

Detailed Description

This file contains all the routines for SLIM learning with feature selection.

Definition in file slim_fs_learn.c.

Function Documentation

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.

Parameters
[in]ctrlA ctrl structure which contains all the parameters for SLIM Learning with feature selection
[in]AThe A matrix
[in]bThe RHS vector
[in,out]wThe solution vector
[in]A_colvalA temporary place for a column
[in]WrkA workspace for BCLS
[in]blThe lower bound for BCLS
[in]buThe upper bound for BCLS
[in]betaThe regularization parameter for L-2 norm
[in]cThe 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().

{
int nnz = *(A->colptr + A->ncols);
int * acol = Wrk->acol;
/* count nnz */
int kk = count_nnz(w, A->ncols);
/* find topk nnz */
int topk = 0;
/* find the indices of topk entries, meanwhile w is over-written as the topk locations */
find_topk(w, A->ncols, gk_min(ctrl->k, kk), w, &topk);
/* back up original values, this is done only once */
if (*A_colval == NULL){
*A_colval = gk_malloc(sizeof(float)*nnz, "malloc *A_colval");
memcpy((void *)*A_colval, (void *)A->colval, sizeof(float)*nnz);
}
/* remove all A nnz values, this will not affect the column under consideration */
gk_fset(nnz, 0, A->colval);
/* set all columns as inactive */
gk_iset(A->ncols, 0, acol);
/* recover all topk columns in A */
for (int i = 0; i < topk; i ++){
int j = (int)w[i];
/* activate this column */
acol[j] = 1;
int nj = A->colptr[j+1] - A->colptr[j];
for (int k = 0; k < nj; k ++){
/* get the orignal values back */
*(A->colptr[j] + k + A->colval) = *(A->colptr[j] + k + *A_colval);
}
}
/* BCLS */
gk_dset(A->ncols, 0, w);
bcsol(ctrl, A, b, w, Wrk, bl, bu, beta, c);
/* recover full A, specific to binary A, this will over-write the column of b,
but will not matter */
memcpy((void *)A->colval, (void *)*A_colval, sizeof(float)*nnz);
/* activate all columns */
gk_iset(A->ncols, 1, acol);
}