#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include "mmio.h"
#include "def.h"
#include "util.h"
#include "l1_logreg.h"
#include "dmatrix.h"
Defines | |
| #define | BIN_EXP_BEGIN (-7) |
| Shows histogram of coefficients in 10-base logscale. | |
| #define | BIN_EXP_END (+2) |
| #define | BIN_NUM_PER_DECADE (8) |
| #define | BIN_IDX_NUM ((BIN_EXP_END-BIN_EXP_BEGIN)*BIN_NUM_PER_DECADE) |
| #define | BIN_IDX_BEGIN (0) |
| #define | BIN_IDX_END (BIN_IDX_BEGIN+BIN_IDX_NUM-1) |
Functions | |
| 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, 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, 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. | |
| 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. | |
| #define BIN_EXP_BEGIN (-7) |
Shows histogram of coefficients in 10-base logscale.
| n | number of coefficients | |
| coeff | vector of coefficients |
| 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.
| len | size of the original solution vector | |
| sol | solution vector | |
| idx | array of non-zero index in solution |
| 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.
| X | feature matrix | |
| b | class vector | |
| sflag | standardization flag
|
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.
| file | matrix file name | |
| out_mat | matrix data |
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.
| file | vector file name | |
| out_vec | vector data |
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.

where
is column average and
is column deviation.
| 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.
| n | number of coefficients | |
| coeff | vector of coefficients | |
| threshold | threshold value |
| double userinput_threshold | ( | void | ) |
Gets a threshold value from standard input.