From 1e340d509f229120eb3aaa98c91028dc3c0d3305 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 25 Aug 2014 14:38:03 +0200 Subject: rename msvmmaj to gensvm --- include/crossval.h | 14 ++-- include/gensvm.h | 99 ++++++++++++++++++++++++++++ include/gensvm_init.h | 28 ++++++++ include/gensvm_io.h | 30 +++++++++ include/gensvm_kernel.h | 38 +++++++++++ include/gensvm_lapack.h | 26 ++++++++ include/gensvm_matrix.h | 37 +++++++++++ include/gensvm_pred.h | 32 +++++++++ include/gensvm_sv.h | 19 ++++++ include/gensvm_train.h | 31 +++++++++ include/gensvm_train_dataset.h | 139 ++++++++++++++++++++++++++++++++++++++++ include/globals.h | 4 +- include/libGenSVM.h | 42 ++++++++++++ include/libMSVMMaj.h | 42 ------------ include/msvmmaj.h | 99 ---------------------------- include/msvmmaj_init.h | 28 -------- include/msvmmaj_io.h | 30 --------- include/msvmmaj_kernel.h | 38 ----------- include/msvmmaj_lapack.h | 26 -------- include/msvmmaj_matrix.h | 37 ----------- include/msvmmaj_pred.h | 32 --------- include/msvmmaj_sv.h | 19 ------ include/msvmmaj_train.h | 31 --------- include/msvmmaj_train_dataset.h | 139 ---------------------------------------- include/timer.h | 4 +- include/types.h | 4 +- include/util.h | 12 ++-- 27 files changed, 540 insertions(+), 540 deletions(-) create mode 100644 include/gensvm.h create mode 100644 include/gensvm_init.h create mode 100644 include/gensvm_io.h create mode 100644 include/gensvm_kernel.h create mode 100644 include/gensvm_lapack.h create mode 100644 include/gensvm_matrix.h create mode 100644 include/gensvm_pred.h create mode 100644 include/gensvm_sv.h create mode 100644 include/gensvm_train.h create mode 100644 include/gensvm_train_dataset.h create mode 100644 include/libGenSVM.h delete mode 100644 include/libMSVMMaj.h delete mode 100644 include/msvmmaj.h delete mode 100644 include/msvmmaj_init.h delete mode 100644 include/msvmmaj_io.h delete mode 100644 include/msvmmaj_kernel.h delete mode 100644 include/msvmmaj_lapack.h delete mode 100644 include/msvmmaj_matrix.h delete mode 100644 include/msvmmaj_pred.h delete mode 100644 include/msvmmaj_sv.h delete mode 100644 include/msvmmaj_train.h delete mode 100644 include/msvmmaj_train_dataset.h (limited to 'include') diff --git a/include/crossval.h b/include/crossval.h index 0dff0b9..fa3cca7 100644 --- a/include/crossval.h +++ b/include/crossval.h @@ -6,20 +6,20 @@ * * @details * Contains function declarations for functions needed for performing cross - * validation on MajData structures. + * validation on GenData structures. * */ -#ifndef CROSSVAL_H -#define CROSSVAL_H +#ifndef GENSVM_CROSSVAL_H +#define GENSVM_CROSSVAL_H #include "globals.h" // forward delaration -struct MajData; +struct GenData; -void msvmmaj_make_cv_split(long N, long folds, long *cv_idx); -void msvmmaj_get_tt_split(struct MajData *full_data, struct MajData *train_data, - struct MajData *test_data, long *cv_idx, long fold_idx); +void gensvm_make_cv_split(long N, long folds, long *cv_idx); +void gensvm_get_tt_split(struct GenData *full_data, struct GenData *train_data, + struct GenData *test_data, long *cv_idx, long fold_idx); #endif diff --git a/include/gensvm.h b/include/gensvm.h new file mode 100644 index 0000000..1231c29 --- /dev/null +++ b/include/gensvm.h @@ -0,0 +1,99 @@ +/** + * @file gensvm.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Definitions for common structures + * + * @details + * Contains documentation and declarations of GenModel and GenData. + * + */ + +#ifndef GENSVM_H +#define GENSVM_H + +#include "globals.h" +#include "types.h" + +/** + * @brief A structure to represent a single GenSVM model. + * + * @param weight_idx which weights to use (1 = unit, 2 = group) + * @param K number of classes in the dataset + * @param n number of instances in the dataset + * @param m number of predictors in the dataset + * @param epsilon stopping criterion + * @param p parameter for the L_p norm + * @param kappa parameter for the Huber hinge + * @param lambda regularization parameter + * @param *W pointer to the weight matrix + * @param *t pointer to the translation vector + * @param *V pointer to the augmented weight matrix + * @param *Vbar pointer to the augmented weight matrix from a + * previous iteration + * @param *U pointer to the simplex matrix + * @param *UU pointer to the 3D simplex difference matrix + * @param *Q pointer to the error matrix + * @param *H pointer to the Huber weighted error matrix + * @param *R pointer to the 0-1 auxiliary matrix + * @param *rho pointer to the instance weight vector + * @param training_error error after training has completed + * @param *data_file pointer to the filename of the data + * @param kerneltype kernel to be used in the model + * @param kernelparam pointer to the vector of kernel parameters + * + * @TODO + * change R to int, it's a binary matrix + */ +struct GenModel { + int weight_idx; + long K; + long n; + long m; + double epsilon; + double p; + double kappa; + double lambda; + double *W; + double *t; + double *V; + double *Vbar; + double *U; + double *UU; + double *Q; + double *H; + double *R; + double *rho; + double training_error; + char *data_file; + KernelType kerneltype; + double *kernelparam; +}; + +/** + * @brief A structure to represent the data. + * + * @param K number of classes + * @param n number of instances + * @param m number of predictors + * @param *y pointer to vector of class labels + * @param *Z pointer to augmented data matrix + * @param *RAW pointer to augmented raw data matrix + * @param *J pointer to regularization vector + * @param kerneltype kerneltype used in GenData::Z + * @param *kernelparam kernel parameters used in GenData::Z + * + */ +struct GenData { + long K; + long n; + long m; + long *y; + double *Z; + double *RAW; + double *J; + KernelType kerneltype; + double *kernelparam; +}; + +#endif diff --git a/include/gensvm_init.h b/include/gensvm_init.h new file mode 100644 index 0000000..544c960 --- /dev/null +++ b/include/gensvm_init.h @@ -0,0 +1,28 @@ +/** + * @file gensvm_init.h + * @author Gertjan van den Burg + * @date January, 2014 + * @brief Header file for gensvm_init.c + * + * @details + * Contains function declarations for the initialization functions for + * GenModel and GenData structures. + */ + +#ifndef GENSVM_INIT_H +#define GENSVM_INIT_H + +// forward declaration +struct GenData; +struct GenModel; + +struct GenModel *gensvm_init_model(); + +struct GenData *gensvm_init_data(); + +void gensvm_allocate_model(struct GenModel *model); +void gensvm_reallocate_model(struct GenModel *model, long n, long m); +void gensvm_free_model(struct GenModel *model); +void gensvm_free_data(struct GenData *data); + +#endif diff --git a/include/gensvm_io.h b/include/gensvm_io.h new file mode 100644 index 0000000..35b6a5a --- /dev/null +++ b/include/gensvm_io.h @@ -0,0 +1,30 @@ +/** + * @file gensvm_io.h + * @author Gertjan van den Burg + * @date January, 2014 + * @brief Header files for gensvm_io.c + * + * @details + * Function declarations for input/output functions. + * + */ + +#ifndef GENSVM_IO_H +#define GENSVM_IO_H + +#include "globals.h" + +// forward declarations +struct GenData; +struct GenModel; + +// function declarations +void gensvm_read_data(struct GenData *dataset, char *data_file); + +void gensvm_read_model(struct GenModel *model, char *model_filename); +void gensvm_write_model(struct GenModel *model, char *output_filename); + +void gensvm_write_predictions(struct GenData *data, long *predy, + char *output_filename); + +#endif diff --git a/include/gensvm_kernel.h b/include/gensvm_kernel.h new file mode 100644 index 0000000..bf46bbc --- /dev/null +++ b/include/gensvm_kernel.h @@ -0,0 +1,38 @@ +/** + * @file gensvm_kernel.h + * @author Gertjan van den Burg + * @date January, 2014 + * @brief Header file for kernel functionality + * + * @details + * Contains function declarations for computing the kernel matrix + * in nonlinear MSVMGen. Additional kernel functions should be + * included here and in gensvm_kernel.c + * + */ + +#ifndef GENSVM_KERNEL_H +#define GENSVM_KERNEL_H + +#include "globals.h" + +// forward declarations +struct GenData; +struct GenModel; + +// function declarations +void gensvm_make_kernel(struct GenModel *model, struct GenData *data); + +long gensvm_make_eigen(double *K, long n, double **P, double **Lambda); + +void gensvm_make_crosskernel(struct GenModel *model, + struct GenData *data_train, struct GenData *data_test, + double **K2); + +double gensvm_compute_rbf(double *x1, double *x2, double *kernelparam, + long n); +double gensvm_compute_poly(double *x1, double *x2, double *kernelparam, + long n); +double gensvm_compute_sigmoid(double *x1, double *x2, double *kernelparam, + long n); +#endif diff --git a/include/gensvm_lapack.h b/include/gensvm_lapack.h new file mode 100644 index 0000000..7ac4fc9 --- /dev/null +++ b/include/gensvm_lapack.h @@ -0,0 +1,26 @@ +/** + * @file gensvm_lapack.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Header file for gensvm_lapack.c + * + * @details + * Function declarations for external LAPACK functions + * + */ + +#ifndef GENSVM_LAPACK_H +#define GENSVM_LAPACK_H + +#include "globals.h" + +int dposv(char UPLO, int N, int NRHS, double *A, int LDA, double *B, + int LDB); +int dsysv(char UPLO, int N, int NRHS, double *A, int LDA, int *IPIV, + double *B, int LDB, double *WORK, int LWORK); +int dsyevx(char JOBZ, char RANGE, char UPLO, int N, double *A, int LDA, + double VL, double VU, int IL, int IU, double ABSTOL, + int *M, double *W, double *Z, int LDZ, double *WORK, int LWORK, + int *IWORK, int *IFAIL); +double dlamch(char CMACH); +#endif diff --git a/include/gensvm_matrix.h b/include/gensvm_matrix.h new file mode 100644 index 0000000..01be3da --- /dev/null +++ b/include/gensvm_matrix.h @@ -0,0 +1,37 @@ +/** + * @file gensvm_matrix.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Header file for gensvm_matrix.c + * + * @details + * Contains function declarations for functions useful for dealing with matrices. + * + */ + +#ifndef GENSVM_MATRIX_H +#define GENSVM_MATRIX_H + +#include "globals.h" + +// Set a matrix element (RowMajor) +#define matrix_set(M, cols, i, j, val) M[(i)*(cols)+j] = val + +// Get a matrix element (RowMajor) +#define matrix_get(M, cols, i, j) M[(i)*(cols)+j] + +// Add to a matrix element (RowMajor) +#define matrix_add(M, cols, i, j, val) M[(i)*(cols)+j] += val + +// Multiply a matrix element (RowMajor) +#define matrix_mul(M, cols, i, j, val) M[(i)*(cols)+j] *= val + +// Set a 3D matrix element (N2 = second dim, N3 = third dim, RowMajor) +#define matrix3_set(M, N2, N3, i, j, k, val) M[k+(N3)*(j+(N2)*(i))] = val + +// Get a 3D matrix element (N2 = second dim, N3 = third dim, RowMajor) +#define matrix3_get(M, N2, N3, i, j, k) M[k+(N3)*(j+(N2)*(i))] + +void print_matrix(double *M, long rows, long cols); + +#endif diff --git a/include/gensvm_pred.h b/include/gensvm_pred.h new file mode 100644 index 0000000..0cce20b --- /dev/null +++ b/include/gensvm_pred.h @@ -0,0 +1,32 @@ +/** + * @file gensvm_pred.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Header file for gensvm_pred.c + * + * @details + * Contains function declarations for prediction functions. + * + */ + +#ifndef GENSVM_PRED_H +#define GENSVM_PRED_H + +#include "globals.h" + +// forward declarations +struct GenData; +struct GenModel; + +// function declarations +void gensvm_predict_labels(struct GenData *data_test, + struct GenData *data_train, struct GenModel *model, + long *predy); +void gensvm_predict_labels_linear(struct GenData *data, + struct GenModel *model, long *predy); +void gensvm_predict_labels_kernel(struct GenData *data_test, + struct GenData *data_train, struct GenModel *model, + long *predy); +double gensvm_prediction_perf(struct GenData *data, long *perdy); + +#endif diff --git a/include/gensvm_sv.h b/include/gensvm_sv.h new file mode 100644 index 0000000..5664f83 --- /dev/null +++ b/include/gensvm_sv.h @@ -0,0 +1,19 @@ +/** + * @file gensvm_sv.h + * @author Gertjan van den Burg + * @date May, 2014 + * @brief Header file for gensvm_sv.c + * + * @details + * Contains function declarations for functions used to count support vectors. + * + */ + +#ifndef GENSVM_SV_H +#define GENSVM_SV_H + +#include "globals.h" + +long gensvm_num_sv(struct GenModel *model, struct GenData *data); + +#endif diff --git a/include/gensvm_train.h b/include/gensvm_train.h new file mode 100644 index 0000000..f59359d --- /dev/null +++ b/include/gensvm_train.h @@ -0,0 +1,31 @@ +/** + * @file gensvm_train.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Header file for gensvm_train.c + * + * @details + * Contains function declarations for functions used to train a single + * GenModel. + * + */ + +#ifndef GENSVM_TRAIN_H +#define GENSVM_TRAIN_H + +#include "globals.h" + +//forward declarations +struct GenData; +struct GenModel; + +// function declarations +void gensvm_optimize(struct GenModel *model, struct GenData *data); + +double gensvm_get_loss(struct GenModel *model, struct GenData *data, + double *ZV); + +void gensvm_get_update(struct GenModel *model, struct GenData *data, + double *B, double *ZAZ, double *ZAZV, double *ZAZVT); + +#endif diff --git a/include/gensvm_train_dataset.h b/include/gensvm_train_dataset.h new file mode 100644 index 0000000..299bc52 --- /dev/null +++ b/include/gensvm_train_dataset.h @@ -0,0 +1,139 @@ +/** + * @file gensvm_train_dataset.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Structs and functions necessary for the grid search + * + * @details + * The grid search for the optimal parameters is done through a queue. + * This file contains struct definitions for this queue and a single + * task in a queue, as well as a structure for the complete training + * scheme. Function declarations are also included. + * + */ + +#ifndef GENSVM_TRAIN_DATASET_H +#define GENSVM_TRAIN_DATASET_H + +#include "globals.h" +#include "types.h" + +/** + * @brief A structure for a single task in the queue. + * + * @param folds number of folds in cross validation + * @param ID numeric id of the task in the queue + * @param weight_idx parameter for the GenModel + * @param p parameter for the GenModel + * @param kappa parameter for the GenModel + * @param lambda parameter for the GenModel + * @param epsilon parameter for the GenModel + * @param kerneltype parameter for the GenModel + * @param *kernelparam parameters for the GenModel + * @param *train_data pointer to the training data + * @param *test_data pointer to the test data (if any) + * @param performance performance after cross validation + */ +struct Task { + KernelType kerneltype; + int weight_idx; + long folds; + long ID; + double p; + double kappa; + double lambda; + double epsilon; + double *kernelparam; + struct GenData *train_data; + struct GenData *test_data; + double performance; +}; + +/** + * @brief Simple task queue. + * + * This struct is basically just an array of pointers to Task instances, + * with a length and an index of the current task. + * + * @param **tasks array of pointers to Task structs + * @param N size of task array + * @param i index used for keeping track of the queue + */ +struct Queue { + struct Task **tasks; + long N; + long i; +}; + +/** + * @brief Structure for describing the entire grid search + * + * @param traintype type of training to use + * @param kerneltype type of kernel to use throughout training + * @param repeats number of repeats to be done after the grid + * search to find the parameter set with the + * most consistent high performance + * @param folds number of folds in cross validation + * @param Np size of the array of p values + * @param Nl size of the array of lambda values + * @param Nk size of the array of kappa values + * @param Ne size of the array of epsilon values + * @param Nw size of the array of weight_idx values + * @param Ng size of the array of gamma values + * @param Nc size of the array of coef values + * @param Nd size of the array of degree values + * @param *weight_idxs array of weight_idxs + * @param *ps array of p values + * @param *lambdas array of lambda values + * @param *kappas array of kappa values + * @param *epsilons array of epsilon values + * @param *gammas array of gamma values + * @param *coefs array of coef values + * @param *degrees array of degree values + * @param *train_data_file filename of train data file + * @param *test_data_file filename of test data file + * + */ +struct Training { + TrainType traintype; + KernelType kerneltype; + long repeats; + long folds; + long Np; + long Nl; + long Nk; + long Ne; + long Nw; + long Ng; + long Nc; + long Nd; + int *weight_idxs; + double *ps; + double *lambdas; + double *kappas; + double *epsilons; + double *gammas; + double *coefs; + double *degrees; + char *train_data_file; + char *test_data_file; +}; + +void make_queue(struct Training *training, struct Queue *queue, + struct GenData *train_data, struct GenData *test_data); + +struct Task *get_next_task(struct Queue *q); +void start_training_tt(struct Queue *q); +void start_training_cv(struct Queue *q); +void free_queue(struct Queue *q); + +void consistency_repeats(struct Queue *q, long repeats, TrainType traintype); + +double cross_validation(struct GenModel *model, struct GenData *data, + long folds); + +void make_model_from_task(struct Task *task, struct GenModel *model); +void copy_model(struct GenModel *from, struct GenModel *to); + +void print_progress_string(struct Task *task, long N); +#endif diff --git a/include/globals.h b/include/globals.h index 55fb6c4..46cc3d2 100644 --- a/include/globals.h +++ b/include/globals.h @@ -16,8 +16,8 @@ * */ -#ifndef MSVMMAJ_GLOBALS_H -#define MSVMMAJ_GLOBALS_H +#ifndef GENSVM_GLOBALS_H +#define GENSVM_GLOBALS_H #include #include diff --git a/include/libGenSVM.h b/include/libGenSVM.h new file mode 100644 index 0000000..cfa2815 --- /dev/null +++ b/include/libGenSVM.h @@ -0,0 +1,42 @@ +/** + * @file libGenSVM.h + * @author Gertjan van den Burg + * @date August, 2013 + * @brief Header file for the core GenSVM library libGenSVM.c + * + * @details + * The core computational routines for GenSVM are defined in libGenSVM.c. + * This file contains function declarations for these functions. + * + */ + +/** + * @todo + * rename this file and libGenSVM.c to correspond with the lowercase convention. + * Also change the name of the include guard. + */ +#ifndef LIBGENSVM_H +#define LIBGENSVM_H + +#include "globals.h" + +// forward declarations +struct GenData; +struct GenModel; + +// function declarations +void gensvm_simplex_gen(long K, double *U); +void gensvm_category_matrix(struct GenModel *model, struct GenData *data); +void gensvm_simplex_diff(struct GenModel *model, struct GenData *dataset); + +void gensvm_calculate_errors(struct GenModel *model, struct GenData *data, + double *ZV); +void gensvm_calculate_huber(struct GenModel *model); + +void gensvm_step_doubling(struct GenModel *model); + +void gensvm_seed_model_V(struct GenModel *from_model, + struct GenModel *to_model, struct GenData *data); +void gensvm_initialize_weights(struct GenData *data, struct GenModel *model); + +#endif diff --git a/include/libMSVMMaj.h b/include/libMSVMMaj.h deleted file mode 100644 index a9bd789..0000000 --- a/include/libMSVMMaj.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @file libMSVMMaj.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Header file for the core MSVMMaj library libMSVMMaj.c - * - * @details - * The core computational routines for MSVMMaj are defined in libMSVMMaj.c. - * This file contains function declarations for these functions. - * - */ - -/** - * @todo - * rename this file and libMSVMMaj.c to correspond with the lowercase convention. - * Also change the name of the include guard. - */ -#ifndef LIBMSVMMAJ_H -#define LIBMSVMMAJ_H - -#include "globals.h" - -// forward declarations -struct MajData; -struct MajModel; - -// function declarations -void msvmmaj_simplex_gen(long K, double *U); -void msvmmaj_category_matrix(struct MajModel *model, struct MajData *data); -void msvmmaj_simplex_diff(struct MajModel *model, struct MajData *dataset); - -void msvmmaj_calculate_errors(struct MajModel *model, struct MajData *data, - double *ZV); -void msvmmaj_calculate_huber(struct MajModel *model); - -void msvmmaj_step_doubling(struct MajModel *model); - -void msvmmaj_seed_model_V(struct MajModel *from_model, - struct MajModel *to_model, struct MajData *data); -void msvmmaj_initialize_weights(struct MajData *data, struct MajModel *model); - -#endif diff --git a/include/msvmmaj.h b/include/msvmmaj.h deleted file mode 100644 index 3d04f30..0000000 --- a/include/msvmmaj.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file msvmmaj.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Definitions for common structures - * - * @details - * Contains documentation and declarations of MajModel and MajData. - * - */ - -#ifndef MSVMMAJ_H -#define MSVMMAJ_H - -#include "globals.h" -#include "types.h" - -/** - * @brief A structure to represent a single MSVMMaj model. - * - * @param weight_idx which weights to use (1 = unit, 2 = group) - * @param K number of classes in the dataset - * @param n number of instances in the dataset - * @param m number of predictors in the dataset - * @param epsilon stopping criterion - * @param p parameter for the L_p norm - * @param kappa parameter for the Huber hinge - * @param lambda regularization parameter - * @param *W pointer to the weight matrix - * @param *t pointer to the translation vector - * @param *V pointer to the augmented weight matrix - * @param *Vbar pointer to the augmented weight matrix from a - * previous iteration - * @param *U pointer to the simplex matrix - * @param *UU pointer to the 3D simplex difference matrix - * @param *Q pointer to the error matrix - * @param *H pointer to the Huber weighted error matrix - * @param *R pointer to the 0-1 auxiliary matrix - * @param *rho pointer to the instance weight vector - * @param training_error error after training has completed - * @param *data_file pointer to the filename of the data - * @param kerneltype kernel to be used in the model - * @param kernelparam pointer to the vector of kernel parameters - * - * @TODO - * change R to int, it's a binary matrix - */ -struct MajModel { - int weight_idx; - long K; - long n; - long m; - double epsilon; - double p; - double kappa; - double lambda; - double *W; - double *t; - double *V; - double *Vbar; - double *U; - double *UU; - double *Q; - double *H; - double *R; - double *rho; - double training_error; - char *data_file; - KernelType kerneltype; - double *kernelparam; -}; - -/** - * @brief A structure to represent the data. - * - * @param K number of classes - * @param n number of instances - * @param m number of predictors - * @param *y pointer to vector of class labels - * @param *Z pointer to augmented data matrix - * @param *RAW pointer to augmented raw data matrix - * @param *J pointer to regularization vector - * @param kerneltype kerneltype used in MajData::Z - * @param *kernelparam kernel parameters used in MajData::Z - * - */ -struct MajData { - long K; - long n; - long m; - long *y; - double *Z; - double *RAW; - double *J; - KernelType kerneltype; - double *kernelparam; -}; - -#endif diff --git a/include/msvmmaj_init.h b/include/msvmmaj_init.h deleted file mode 100644 index 281214c..0000000 --- a/include/msvmmaj_init.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @file msvmmaj_init.h - * @author Gertjan van den Burg - * @date January, 2014 - * @brief Header file for msvmmaj_init.c - * - * @details - * Contains function declarations for the initialization functions for - * MajModel and MajData structures. - */ - -#ifndef MSVMMAJ_INIT_H -#define MSVMMAJ_INIT_H - -// forward declaration -struct MajData; -struct MajModel; - -struct MajModel *msvmmaj_init_model(); - -struct MajData *msvmmaj_init_data(); - -void msvmmaj_allocate_model(struct MajModel *model); -void msvmmaj_reallocate_model(struct MajModel *model, long n, long m); -void msvmmaj_free_model(struct MajModel *model); -void msvmmaj_free_data(struct MajData *data); - -#endif diff --git a/include/msvmmaj_io.h b/include/msvmmaj_io.h deleted file mode 100644 index 99fb4dc..0000000 --- a/include/msvmmaj_io.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @file msvmmaj_io.h - * @author Gertjan van den Burg - * @date January, 2014 - * @brief Header files for msvmmaj_io.c - * - * @details - * Function declarations for input/output functions. - * - */ - -#ifndef MSVMMAJ_IO_H -#define MSVMMAJ_IO_H - -#include "globals.h" - -// forward declarations -struct MajData; -struct MajModel; - -// function declarations -void msvmmaj_read_data(struct MajData *dataset, char *data_file); - -void msvmmaj_read_model(struct MajModel *model, char *model_filename); -void msvmmaj_write_model(struct MajModel *model, char *output_filename); - -void msvmmaj_write_predictions(struct MajData *data, long *predy, - char *output_filename); - -#endif diff --git a/include/msvmmaj_kernel.h b/include/msvmmaj_kernel.h deleted file mode 100644 index d4f169a..0000000 --- a/include/msvmmaj_kernel.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file msvmmaj_kernel.h - * @author Gertjan van den Burg - * @date January, 2014 - * @brief Header file for kernel functionality - * - * @details - * Contains function declarations for computing the kernel matrix - * in nonlinear MSVMMaj. Additional kernel functions should be - * included here and in msvmmaj_kernel.c - * - */ - -#ifndef MSVMMAJ_KERNEL_H -#define MSVMMAJ_KERNEL_H - -#include "globals.h" - -// forward declarations -struct MajData; -struct MajModel; - -// function declarations -void msvmmaj_make_kernel(struct MajModel *model, struct MajData *data); - -long msvmmaj_make_eigen(double *K, long n, double **P, double **Lambda); - -void msvmmaj_make_crosskernel(struct MajModel *model, - struct MajData *data_train, struct MajData *data_test, - double **K2); - -double msvmmaj_compute_rbf(double *x1, double *x2, double *kernelparam, - long n); -double msvmmaj_compute_poly(double *x1, double *x2, double *kernelparam, - long n); -double msvmmaj_compute_sigmoid(double *x1, double *x2, double *kernelparam, - long n); -#endif diff --git a/include/msvmmaj_lapack.h b/include/msvmmaj_lapack.h deleted file mode 100644 index 6ea1122..0000000 --- a/include/msvmmaj_lapack.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @file msvmmaj_lapack.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Header file for msvmmaj_lapack.c - * - * @details - * Function declarations for external LAPACK functions - * - */ - -#ifndef MSVMMAJ_LAPACK_H -#define MSVMMAJ_LAPACK_H - -#include "globals.h" - -int dposv(char UPLO, int N, int NRHS, double *A, int LDA, double *B, - int LDB); -int dsysv(char UPLO, int N, int NRHS, double *A, int LDA, int *IPIV, - double *B, int LDB, double *WORK, int LWORK); -int dsyevx(char JOBZ, char RANGE, char UPLO, int N, double *A, int LDA, - double VL, double VU, int IL, int IU, double ABSTOL, - int *M, double *W, double *Z, int LDZ, double *WORK, int LWORK, - int *IWORK, int *IFAIL); -double dlamch(char CMACH); -#endif diff --git a/include/msvmmaj_matrix.h b/include/msvmmaj_matrix.h deleted file mode 100644 index db64303..0000000 --- a/include/msvmmaj_matrix.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file msvmmaj_matrix.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Header file for msvmmaj_matrix.c - * - * @details - * Contains function declarations for functions useful for dealing with matrices. - * - */ - -#ifndef MSVMMAJ_MATRIX_H -#define MSVMMAJ_MATRIX_H - -#include "globals.h" - -// Set a matrix element (RowMajor) -#define matrix_set(M, cols, i, j, val) M[(i)*(cols)+j] = val - -// Get a matrix element (RowMajor) -#define matrix_get(M, cols, i, j) M[(i)*(cols)+j] - -// Add to a matrix element (RowMajor) -#define matrix_add(M, cols, i, j, val) M[(i)*(cols)+j] += val - -// Multiply a matrix element (RowMajor) -#define matrix_mul(M, cols, i, j, val) M[(i)*(cols)+j] *= val - -// Set a 3D matrix element (N2 = second dim, N3 = third dim, RowMajor) -#define matrix3_set(M, N2, N3, i, j, k, val) M[k+(N3)*(j+(N2)*(i))] = val - -// Get a 3D matrix element (N2 = second dim, N3 = third dim, RowMajor) -#define matrix3_get(M, N2, N3, i, j, k) M[k+(N3)*(j+(N2)*(i))] - -void print_matrix(double *M, long rows, long cols); - -#endif diff --git a/include/msvmmaj_pred.h b/include/msvmmaj_pred.h deleted file mode 100644 index c274cfa..0000000 --- a/include/msvmmaj_pred.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file msvmmaj_pred.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Header file for msvmmaj_pred.c - * - * @details - * Contains function declarations for prediction functions. - * - */ - -#ifndef MSVMMAJ_PRED_H -#define MSVMMAJ_PRED_H - -#include "globals.h" - -// forward declarations -struct MajData; -struct MajModel; - -// function declarations -void msvmmaj_predict_labels(struct MajData *data_test, - struct MajData *data_train, struct MajModel *model, - long *predy); -void msvmmaj_predict_labels_linear(struct MajData *data, - struct MajModel *model, long *predy); -void msvmmaj_predict_labels_kernel(struct MajData *data_test, - struct MajData *data_train, struct MajModel *model, - long *predy); -double msvmmaj_prediction_perf(struct MajData *data, long *perdy); - -#endif diff --git a/include/msvmmaj_sv.h b/include/msvmmaj_sv.h deleted file mode 100644 index e37ffc4..0000000 --- a/include/msvmmaj_sv.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @file msvmmaj_sv.h - * @author Gertjan van den Burg - * @date May, 2014 - * @brief Header file for msvmmaj_sv.c - * - * @details - * Contains function declarations for functions used to count support vectors. - * - */ - -#ifndef MSVMMAJ_SV_H -#define MSVMMAJ_SV_H - -#include "globals.h" - -long msvmmaj_num_sv(struct MajModel *model, struct MajData *data); - -#endif diff --git a/include/msvmmaj_train.h b/include/msvmmaj_train.h deleted file mode 100644 index 835100f..0000000 --- a/include/msvmmaj_train.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file msvmmaj_train.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Header file for msvmmaj_train.c - * - * @details - * Contains function declarations for functions used to train a single - * MajModel. - * - */ - -#ifndef MSVMMAJ_TRAIN_H -#define MSVMMAJ_TRAIN_H - -#include "globals.h" - -//forward declarations -struct MajData; -struct MajModel; - -// function declarations -void msvmmaj_optimize(struct MajModel *model, struct MajData *data); - -double msvmmaj_get_loss(struct MajModel *model, struct MajData *data, - double *ZV); - -void msvmmaj_get_update(struct MajModel *model, struct MajData *data, - double *B, double *ZAZ, double *ZAZV, double *ZAZVT); - -#endif diff --git a/include/msvmmaj_train_dataset.h b/include/msvmmaj_train_dataset.h deleted file mode 100644 index 95e2c74..0000000 --- a/include/msvmmaj_train_dataset.h +++ /dev/null @@ -1,139 +0,0 @@ -/** - * @file msvmmaj_train_dataset.h - * @author Gertjan van den Burg - * @date August, 2013 - * @brief Structs and functions necessary for the grid search - * - * @details - * The grid search for the optimal parameters is done through a queue. - * This file contains struct definitions for this queue and a single - * task in a queue, as well as a structure for the complete training - * scheme. Function declarations are also included. - * - */ - -#ifndef MSVMMAJ_TRAIN_DATASET_H -#define MSVMMAJ_TRAIN_DATASET_H - -#include "globals.h" -#include "types.h" - -/** - * @brief A structure for a single task in the queue. - * - * @param folds number of folds in cross validation - * @param ID numeric id of the task in the queue - * @param weight_idx parameter for the MajModel - * @param p parameter for the MajModel - * @param kappa parameter for the MajModel - * @param lambda parameter for the MajModel - * @param epsilon parameter for the MajModel - * @param kerneltype parameter for the MajModel - * @param *kernelparam parameters for the MajModel - * @param *train_data pointer to the training data - * @param *test_data pointer to the test data (if any) - * @param performance performance after cross validation - */ -struct Task { - KernelType kerneltype; - int weight_idx; - long folds; - long ID; - double p; - double kappa; - double lambda; - double epsilon; - double *kernelparam; - struct MajData *train_data; - struct MajData *test_data; - double performance; -}; - -/** - * @brief Simple task queue. - * - * This struct is basically just an array of pointers to Task instances, - * with a length and an index of the current task. - * - * @param **tasks array of pointers to Task structs - * @param N size of task array - * @param i index used for keeping track of the queue - */ -struct Queue { - struct Task **tasks; - long N; - long i; -}; - -/** - * @brief Structure for describing the entire grid search - * - * @param traintype type of training to use - * @param kerneltype type of kernel to use throughout training - * @param repeats number of repeats to be done after the grid - * search to find the parameter set with the - * most consistent high performance - * @param folds number of folds in cross validation - * @param Np size of the array of p values - * @param Nl size of the array of lambda values - * @param Nk size of the array of kappa values - * @param Ne size of the array of epsilon values - * @param Nw size of the array of weight_idx values - * @param Ng size of the array of gamma values - * @param Nc size of the array of coef values - * @param Nd size of the array of degree values - * @param *weight_idxs array of weight_idxs - * @param *ps array of p values - * @param *lambdas array of lambda values - * @param *kappas array of kappa values - * @param *epsilons array of epsilon values - * @param *gammas array of gamma values - * @param *coefs array of coef values - * @param *degrees array of degree values - * @param *train_data_file filename of train data file - * @param *test_data_file filename of test data file - * - */ -struct Training { - TrainType traintype; - KernelType kerneltype; - long repeats; - long folds; - long Np; - long Nl; - long Nk; - long Ne; - long Nw; - long Ng; - long Nc; - long Nd; - int *weight_idxs; - double *ps; - double *lambdas; - double *kappas; - double *epsilons; - double *gammas; - double *coefs; - double *degrees; - char *train_data_file; - char *test_data_file; -}; - -void make_queue(struct Training *training, struct Queue *queue, - struct MajData *train_data, struct MajData *test_data); - -struct Task *get_next_task(struct Queue *q); -void start_training_tt(struct Queue *q); -void start_training_cv(struct Queue *q); -void free_queue(struct Queue *q); - -void consistency_repeats(struct Queue *q, long repeats, TrainType traintype); - -double cross_validation(struct MajModel *model, struct MajData *data, - long folds); - -void make_model_from_task(struct Task *task, struct MajModel *model); -void copy_model(struct MajModel *from, struct MajModel *to); - -void print_progress_string(struct Task *task, long N); -#endif diff --git a/include/timer.h b/include/timer.h index d4af649..a1b60a7 100644 --- a/include/timer.h +++ b/include/timer.h @@ -9,8 +9,8 @@ * */ -#ifndef MSVMMAJ_TIMER_H -#define MSVMMAJ_TIMER_H +#ifndef GENSVM_TIMER_H +#define GENSVM_TIMER_H #include "globals.h" diff --git a/include/types.h b/include/types.h index f6d008b..1cbcba0 100644 --- a/include/types.h +++ b/include/types.h @@ -9,8 +9,8 @@ * */ -#ifndef MSVMMAJ_TYPES_H -#define MSVMMAJ_TYPES_H +#ifndef GENSVM_TYPES_H +#define GENSVM_TYPES_H /** * @brief Implementation of true and false diff --git a/include/util.h b/include/util.h index 375a9c2..fe8d2a3 100644 --- a/include/util.h +++ b/include/util.h @@ -9,18 +9,18 @@ * */ -#ifndef MSVMMAJ_UTIL_H -#define MSVMMAJ_UTIL_H +#ifndef GENSVM_UTIL_H +#define GENSVM_UTIL_H #include "globals.h" // forward declarations -struct MajData; -struct MajModel; +struct GenData; +struct GenModel; // function declarations -int msvmmaj_check_argv(int argc, char **argv, char *str); -int msvmmaj_check_argv_eq(int argc, char **argv, char *str); +int gensvm_check_argv(int argc, char **argv, char *str); +int gensvm_check_argv_eq(int argc, char **argv, char *str); void note(const char *fmt,...); -- cgit v1.2.3