src_c/util.h File Reference

Header file for utility functions. More...

#include "dmatrix.h"

Go to the source code of this file.

Data Structures

struct  buffer_t

Defines

#define TYPE_E   0
#define TYPE_G   1
#define BUFFER_INC_SIZE   1024
#define BUFFER_SIZE_DOUBLE   sizeof(double)
#define BUFFER_SIZE_INT   sizeof(int)

Functions

void buffer_new (buffer_t **buf, int elemsize, int length)
void buffer_free (buffer_t *buf)
int buffer_write (buffer_t *buf, void *src, int n)
int condense_solution (const int len, double *sol, int *idx)
 Condense solution by removing zeros.
double find_lambdamax (const dmatrix *X, const double *b, const int sflag)
 Returns the maximum value of the regularization parameter lambda that gives a non-zero solution.
void standardize_data (dmatrix *X, const double *b, double **average, double **stddev, double **acol, double **arow)
 Standardizes the data.
int read_mm_new_matrix (const char *file_x, dmatrix **out_mat)
 Read a matrix file.
int read_mm_new_matrix_transpose (const char *file, dmatrix **out_mat)
int read_mm_new_vector (const char *file_x, double **out_vec)
 Read a vector file.
int write_mm_vector (const char *file, const int m, const double *vec, const char *comments, const int type)
int write_mm_matrix (const char *file, dmatrix *mat, const char *comments, const int type)
int write_mm_matrix_crd_header (FILE *fp, const int m, const int n, const int nnz, const char *comments)
int write_mm_matrix_crd_column (FILE *fp, const int len, const int col, const double *vec)
int write_mm_matrix_crd_column_threshold (FILE *fp, const int len, const int col, const double *vec, const double threshold)
int get_mm_info (const char *file, int *m, int *n, int *nz)
int show_histogram (const int n, const double *coeff)
double userinput_threshold (void)
 Gets a threshold value from standard input.
int thresholding (const int n, double *coeff, double threshold)
 Thresholds coefficients.


Detailed Description

Header file for utility functions.


Function Documentation

int condense_solution ( const int  len,
double *  sol,
int *  idx 
)

Condense solution by removing zeros.

Truncates coefficients if their absolute values are below the threshold.

Parameters:
len size of the original solution vector
sol solution vector
idx array of non-zero index in solution
ex: initial sol: [1 0 0 6 0 0 0 7 1] final sol: [1 6 7 1] idx: [1 4 8 9]

double find_lambdamax ( const dmatrix X,
const double *  b,
const int  sflag 
)

Returns the maximum value of the regularization parameter lambda that gives a non-zero solution.

Parameters:
X feature matrix
b class vector
sflag standardization flag
  • If sflag is 0, compute the maximum value of lambda without standardization.
  • If sflag is 1, given matrix is standardized first and then the maximum value of lambda is computed.
Returns:
maximum value of lambda

References dmat_copy(), dmat_diagscale(), dmat_duplicate(), dmat_free(), dmat_norminf(), dmat_yAmpqTx(), dmatrix::m, dmatrix::n, and standardize_data().

int read_mm_new_matrix ( const char *  file,
dmatrix **  out_mat 
)

Read a matrix file.

Reads a Matrix Market formatted matrix from a file.

Parameters:
file matrix file name
out_mat matrix data
Returns:
result

References dmatrix::idx, dmatrix::jdx, dmatrix::m, dmatrix::n, dmatrix::nz, dmatrix::rdx, and dmatrix::val.

Referenced by main().

int read_mm_new_vector ( const char *  file,
double **  out_vec 
)

Read a vector file.

Reads a Matrix Market formatted vector from a file. Returns pointer to dense vector.

Parameters:
file vector file name
out_vec vector data
Returns:
result

Referenced by main().

void standardize_data ( dmatrix X,
const double *  b,
double **  average,
double **  stddev,
double **  acol,
double **  arow 
)

Standardizes the data.

Standardizes the feature matrix.

  • If b is not given, compute $ X := (X-1^T\mu)\mbox{diag}(\sigma)^{-1} $
  • If b is given, compute $ X := \mbox{diag}(b)(X-1^T\mu)\mbox{diag}(\sigma)^{-1} $ where $ \mu $ is column average and $ \sigma $ is column deviation.

Parameters:
X feature matrix
b class vector
average column average
stddev column standard deviation
acol column vector used for implicit standardization
arow row vector used for implicit standardization

References dmat_colavg(), dmat_colstd(), dmat_diagscale(), dmat_elemdivi(), dmat_vcopy(), dmat_vset(), dmatrix::m, dmatrix::n, dmatrix::nz, and dmatrix::val.

Referenced by find_lambdamax(), and l1_logreg_train().

int thresholding ( const int  n,
double *  coeff,
double  threshold 
)

Thresholds coefficients.

Truncates coefficients if their absolute values are below the threshold.

Parameters:
n number of coefficients
coeff vector of coefficients
threshold threshold value

double userinput_threshold ( void   ) 

Gets a threshold value from standard input.

  • If input value is positive, return it.
  • If input value is negative, assume it as a 10-based log value. For example, -3 is converted to 10^(-3).

Returns:
threshold value


Generated on Mon May 25 19:15:19 2009 for l1_logreg by Doxygen 1.5.5