diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2013-10-18 15:48:59 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <burg@ese.eur.nl> | 2013-10-18 15:48:59 +0200 |
| commit | 6d064658f8ae7ca0f42fef6dcc7f896144e9637b (patch) | |
| tree | a41e8793f71f637b68f862220ae5566f4537073d /include | |
| parent | allow seeding of V and added documentation (diff) | |
| download | gensvm-6d064658f8ae7ca0f42fef6dcc7f896144e9637b.tar.gz gensvm-6d064658f8ae7ca0f42fef6dcc7f896144e9637b.zip | |
restart using git
Diffstat (limited to 'include')
| -rw-r--r-- | include/MSVMMaj.h | 12 | ||||
| -rw-r--r-- | include/crossval.h | 13 | ||||
| -rw-r--r-- | include/globals.h | 20 | ||||
| -rw-r--r-- | include/libMSVMMaj.h | 40 | ||||
| -rw-r--r-- | include/matrix.h | 6 | ||||
| -rw-r--r-- | include/msvmmaj_pred.h | 15 | ||||
| -rw-r--r-- | include/msvmmaj_train.h | 19 | ||||
| -rw-r--r-- | include/msvmmaj_train_dataset.h | 61 | ||||
| -rw-r--r-- | include/mylapack.h | 11 | ||||
| -rw-r--r-- | include/parallel.h | 13 | ||||
| -rw-r--r-- | include/strutil.h | 19 | ||||
| -rw-r--r-- | include/timer.h | 8 | ||||
| -rw-r--r-- | include/types.h | 21 | ||||
| -rw-r--r-- | include/util.h | 43 |
14 files changed, 249 insertions, 52 deletions
diff --git a/include/MSVMMaj.h b/include/MSVMMaj.h index 021a341..5c3efb8 100644 --- a/include/MSVMMaj.h +++ b/include/MSVMMaj.h @@ -1,11 +1,12 @@ +#ifndef MSVMMAJ_H +#define MSVMMAJ_H -#define MAX_ITER 10000000 -#define MAX_LINE_LENGTH 1024 +#include "globals.h" /* Model structure */ -struct Model { +struct MajModel { int weight_idx; long K; long n; @@ -24,16 +25,19 @@ struct Model { double *H; double *R; double *rho; + double training_error; char *data_file; }; /* Data structure */ -struct Data { +struct MajData { long K; long n; long m; long *y; double *Z; }; + +#endif diff --git a/include/crossval.h b/include/crossval.h new file mode 100644 index 0000000..0794622 --- /dev/null +++ b/include/crossval.h @@ -0,0 +1,13 @@ +#ifndef CROSSVAL_H +#define CROSSVAL_H + +#include "globals.h" + +// forward delaration +struct MajData; + +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); + +#endif diff --git a/include/globals.h b/include/globals.h new file mode 100644 index 0000000..8420f76 --- /dev/null +++ b/include/globals.h @@ -0,0 +1,20 @@ +#ifndef GLOBALS_H +#define GLOBALS_H + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAX_LINE_LENGTH 1024 + +#define Calloc(type, n) (type *)calloc((n), sizeof(type)) +#define Malloc(type, n) (type *)malloc((n)*sizeof(type)) +#define Memset(var, type, n) memset(var, 0, (n)*sizeof(type)) + +#ifndef MIN_MAX_DEFINE +#define MIN_MAX_DEFINE +#define maximum(a, b) (a) > (b) ? (a) : (b) +#define minimum(a, b) (a) < (b) ? (a) : (b) +#endif + +#endif diff --git a/include/libMSVMMaj.h b/include/libMSVMMaj.h index 3e0f25c..21efc2f 100644 --- a/include/libMSVMMaj.h +++ b/include/libMSVMMaj.h @@ -1,31 +1,23 @@ -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <cblas.h> -#include <string.h> +#ifndef LIBMSVMMAJ_H +#define LIBMSVMMAJ_H -#include "util.h" -#include "matrix.h" +#include "globals.h" -void simplex_gen(long K, double *U); -void category_matrix(struct Model *model, struct Data *data); -void simplex_diff(struct Model *model, struct Data *dataset); +// forward declarations +struct MajData; +struct MajModel; -void calculate_errors(struct Model *model, struct Data *data, double *ZV); -void calculate_huber(struct Model *model); +// 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); -double get_msvmmaj_loss(struct Model *model, struct Data *data, double *ZV); -void msvmmaj_update(struct Model *model, struct Data *data, - double *B, double *ZAZ, double *ZAZV, double *ZAZVT); -void step_doubling(struct Model *model); +void msvmmaj_calculate_errors(struct MajModel *model, struct MajData *data, double *ZV); +void msvmmaj_calculate_huber(struct MajModel *model); -void main_loop(struct Model *model, struct Data *data); +void msvmmaj_step_doubling(struct MajModel *model); -int dposv(char UPLO, int N, int NRHS, double *A, int LDA, double *B, int LDB); - -void seed_model_V(struct Model *from_model, struct Model *to_model); -void initialize_weights(struct Data *data, struct Model *model); - -void predict_labels(struct Data *data, struct Model *model, long *predy); -double prediction_perf(struct Data *data, long *predy); +void msvmmaj_seed_model_V(struct MajModel *from_model, struct MajModel *to_model); +void msvmmaj_initialize_weights(struct MajData *data, struct MajModel *model); +#endif diff --git a/include/matrix.h b/include/matrix.h index 4157475..5f0a441 100644 --- a/include/matrix.h +++ b/include/matrix.h @@ -1,3 +1,7 @@ +#ifndef MATRIX_H +#define MATRIX_H + +#include "globals.h" void matrix_set(double *M, long cols, long i, long j, double val); void matrix_add(double *M, long cols, long i, long j, double val); @@ -10,3 +14,5 @@ void matrix3_set(double *M, long N2, long N3, long i, long j, long k, double matrix3_get(double *M, long N2, long N3, long i, long j, long k); void print_matrix(double *M, long rows, long cols); + +#endif diff --git a/include/msvmmaj_pred.h b/include/msvmmaj_pred.h new file mode 100644 index 0000000..952389c --- /dev/null +++ b/include/msvmmaj_pred.h @@ -0,0 +1,15 @@ +#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, struct MajModel *model, + long *predy); +double msvmmaj_prediction_perf(struct MajData *data, long *perdy); + +#endif diff --git a/include/msvmmaj_train.h b/include/msvmmaj_train.h new file mode 100644 index 0000000..4fb198e --- /dev/null +++ b/include/msvmmaj_train.h @@ -0,0 +1,19 @@ +#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 new file mode 100644 index 0000000..fdcdb4c --- /dev/null +++ b/include/msvmmaj_train_dataset.h @@ -0,0 +1,61 @@ +#ifndef MSVMMAJ_TRAIN_DATASET_H +#define MSVMMAJ_TRAIN_DATASET_H + +#include "globals.h" +#include "types.h" + +struct Task { + KernelType kerneltype; + int weight_idx; + long folds; + long ID; + double p; + double kappa; + double lambda; + double epsilon; + double *kernel_param; + struct MajData *train_data; + struct MajData *test_data; + double performance; +}; + +struct Queue { + struct Task **tasks; + long N; + long i; +}; + +struct Training { + TrainType traintype; + long repeats; + long folds; + long Np; + long Nl; + long Nk; + long Ne; + long Nw; + int *weight_idxs; + double *ps; + double *lambdas; + double *kappas; + double *epsilons; + 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 MajModel *seed_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); +#endif diff --git a/include/mylapack.h b/include/mylapack.h new file mode 100644 index 0000000..4c79e0e --- /dev/null +++ b/include/mylapack.h @@ -0,0 +1,11 @@ +#ifndef MYLAPACK_H +#define MYLAPACK_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); + +#endif diff --git a/include/parallel.h b/include/parallel.h new file mode 100644 index 0000000..8747347 --- /dev/null +++ b/include/parallel.h @@ -0,0 +1,13 @@ + +struct Task { + enum KernelType kernel_type; + int weight_idx; + double epsilon; + double p; + double kappa; + double lambda; + double *kernel_param; + struct MajData **data; +} + + diff --git a/include/strutil.h b/include/strutil.h new file mode 100644 index 0000000..66722ae --- /dev/null +++ b/include/strutil.h @@ -0,0 +1,19 @@ +#ifndef STRUTIL_H +#define STRUTIL_H + +#include "globals.h" +#include "types.h" + +bool str_startswith(const char *str, const char *pre); +bool str_endswith(const char *str, const char *suf); + +void next_line(FILE *fid, char *filename); +void get_line(FILE *fid, char *filename, char *buffer); + +double get_fmt_double(FILE *fid, char *filename, const char *fmt); +long get_fmt_long(FILE *fid, char *filename, const char *fmt); + +long all_doubles_str(char *buffer, long offset, double *all_doubles); +long all_longs_str(char *buffer, long offset, long *all_longs); + +#endif diff --git a/include/timer.h b/include/timer.h new file mode 100644 index 0000000..8a737e0 --- /dev/null +++ b/include/timer.h @@ -0,0 +1,8 @@ +#ifndef TIMER_H +#define TIMER_H + +#include "globals.h" + +double elapsed_time(clock_t s_time, clock_t e_time); + +#endif diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..b4db8d8 --- /dev/null +++ b/include/types.h @@ -0,0 +1,21 @@ +#ifndef TYPES_H +#define TYPES_H + +typedef enum { + false, + true +} bool; + +typedef enum { + CV=0, + TT=1 +} TrainType; + +typedef enum { + K_LINEAR=0, + K_POLY=1, + K_RBF=2, + K_SIGMOID=3, +} KernelType; + +#endif diff --git a/include/util.h b/include/util.h index 2cf36e8..facae79 100644 --- a/include/util.h +++ b/include/util.h @@ -1,33 +1,28 @@ -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> -#include <time.h> -#include "MSVMMaj.h" +#ifndef UTIL_H +#define UTIL_H -#define Calloc(type, n) (type *)calloc((n), sizeof(type)) -#define Malloc(type, n) (type *)malloc((n)*sizeof(type)) -#define Memset(var, type, n) memset(var, 0, (n)*sizeof(type)) -#define maximum(a, b) a > b ? a : b -#define minimum(a, b) a < b ? a : b +#include "globals.h" -void read_data(struct Data *dataset, char *data_file); +// forward declarations +struct MajData; +struct MajModel; -void read_model(struct Model *model, char *model_filename); -void write_model(struct Model *model, char *output_filename); +// function declarations +void msvmmaj_read_data(struct MajData *dataset, char *data_file); -void write_predictions(struct Data *data, long *predy, char *output_filename); +void msvmmaj_read_model(struct MajModel *model, char *model_filename); +void msvmmaj_write_model(struct MajModel *model, char *output_filename); -int check_argv(int argc, char **argv, char *str); -int check_argv_eq(int argc, char **argv, char *str); +void msvmmaj_write_predictions(struct MajData *data, long *predy, + char *output_filename); -void set_print_string_function(void (*print_func)(const char *)); -void info(const char *fmt,...); +int msvmmaj_check_argv(int argc, char **argv, char *str); +int msvmmaj_check_argv_eq(int argc, char **argv, char *str); -double rnd(); +void note(const char *fmt,...); -void allocate_model(struct Model *model); -void free_model(struct Model *model); -void free_data(struct Data *data); +void msvmmaj_allocate_model(struct MajModel *model); +void msvmmaj_free_model(struct MajModel *model); +void msvmmaj_free_data(struct MajData *data); +#endif |
