diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2014-07-02 17:09:38 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <burg@ese.eur.nl> | 2014-07-02 17:09:38 +0200 |
| commit | 75a91a963c979b0d657b8839036cd82f6ae5f24b (patch) | |
| tree | 1fd14e14d6cf0e877c07ecc95258e3968460cc0a | |
| parent | set element of category matrix to zero explicitly, not calloced (diff) | |
| download | gensvm-75a91a963c979b0d657b8839036cd82f6ae5f24b.tar.gz gensvm-75a91a963c979b0d657b8839036cd82f6ae5f24b.zip | |
seed V based on scale of X
| -rw-r--r-- | include/libMSVMMaj.h | 6 | ||||
| -rw-r--r-- | src/libMSVMMaj.c | 35 | ||||
| -rw-r--r-- | src/msvmmaj_train.c | 5 | ||||
| -rw-r--r-- | src/msvmmaj_train_dataset.c | 12 | ||||
| -rw-r--r-- | src/trainMSVMMaj.c | 4 |
5 files changed, 40 insertions, 22 deletions
diff --git a/include/libMSVMMaj.h b/include/libMSVMMaj.h index b7261dc..a9bd789 100644 --- a/include/libMSVMMaj.h +++ b/include/libMSVMMaj.h @@ -29,12 +29,14 @@ 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_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); +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/src/libMSVMMaj.c b/src/libMSVMMaj.c index ca0916b..488b76d 100644 --- a/src/libMSVMMaj.c +++ b/src/libMSVMMaj.c @@ -216,19 +216,34 @@ void msvmmaj_calculate_huber(struct MajModel *model) * @param[in] from_model MajModel from which to copy V * @param[in,out] to_model MajModel to which V will be copied */ -void msvmmaj_seed_model_V(struct MajModel *from_model, struct MajModel *to_model) +void msvmmaj_seed_model_V(struct MajModel *from_model, + struct MajModel *to_model, struct MajData *data) { - long i, j; - long m = to_model->m; - long K = to_model->K; - double value; - + long i, j, k; + double cmin, cmax, value; + + long n = data->n; + long m = data->m; + long K = data->K; + if (from_model == NULL) { - for (i=0; i<m+1; i++) - for (j=0; j<K-1; j++) - matrix_set(to_model->V, K-1, i, j, -1.0+2.0*rnd()); + for (i=0; i<m+1; i++) { + cmin = 1e100; + cmax = -1e100; + for (k=0; k<n; k++) { + value = matrix_get(data->Z, m+1, k, i); + cmin = minimum(cmin, value); + cmax = maximum(cmax, value); + } + for (j=0; j<K-1; j++) { + cmin = (abs(cmin) < 1e-10) ? -1 : cmin; + cmax = (abs(cmax) < 1e-10) ? 1 : cmax; + value = 1.0/cmin + (1.0/cmax - 1.0/cmin)*rnd(); + matrix_set(to_model->V, K-1, i, j, value); + } + } } else { - for (i=0; i<m+1; i++) + for (i=0; i<m+1; i++) for (j=0; j<K-1; j++) { value = matrix_get(from_model->V, K-1, i, j); matrix_set(to_model->V, K-1, i, j, value); diff --git a/src/msvmmaj_train.c b/src/msvmmaj_train.c index 2333544..4aea85f 100644 --- a/src/msvmmaj_train.c +++ b/src/msvmmaj_train.c @@ -88,13 +88,14 @@ void msvmmaj_optimize(struct MajModel *model, struct MajData *data) Lbar = L; L = msvmmaj_get_loss(model, data, ZV); - if (it%100 == 0) + if (it%100 == 0) note("iter = %li, L = %15.16f, Lbar = %15.16f, " "reldiff = %15.16f\n", it, L, Lbar, (Lbar - L)/L); it++; } - note("optimization finished, iter = %li, error = %15.16f\n", it-1, + note("optimization finished, iter = %li, loss = %15.16f, " + "rel. diff. = %15.16f\n", it-1, L, (Lbar - L)/L); note("number of support vectors: %li\n", msvmmaj_num_sv(model, data)); diff --git a/src/msvmmaj_train_dataset.c b/src/msvmmaj_train_dataset.c index 8d23684..7fa7316 100644 --- a/src/msvmmaj_train_dataset.c +++ b/src/msvmmaj_train_dataset.c @@ -335,7 +335,7 @@ void consistency_repeats(struct Queue *q, long repeats, TrainType traintype) model->m = task->train_data->m; model->K = task->train_data->K; msvmmaj_allocate_model(model); - msvmmaj_seed_model_V(NULL, model); + msvmmaj_seed_model_V(NULL, model, task->train_data); } time[i] = 0.0; @@ -356,7 +356,7 @@ void consistency_repeats(struct Queue *q, long repeats, TrainType traintype) note("%3.3f\t", p); // this is done because if we reuse the V it's not a // consistency check - msvmmaj_seed_model_V(NULL, model); + msvmmaj_seed_model_V(NULL, model, task->train_data); } for (r=0; r<repeats; r++) { std[i] += pow(matrix_get( @@ -512,7 +512,7 @@ void start_training_cv(struct Queue *q) model->m = task->train_data->m; model->K = task->train_data->K; msvmmaj_allocate_model(model); - msvmmaj_seed_model_V(NULL, model); + msvmmaj_seed_model_V(NULL, model, task->train_data); main_s = clock(); while (task) { @@ -576,7 +576,7 @@ void start_training_tt(struct Queue *q) seed_model->m = task->train_data->m; seed_model->K = task->train_data->K; msvmmaj_allocate_model(seed_model); - msvmmaj_seed_model_V(NULL, seed_model); + msvmmaj_seed_model_V(NULL, seed_model, task->train_data); main_s = clock(); while (task) { @@ -594,7 +594,7 @@ void start_training_tt(struct Queue *q) msvmmaj_allocate_model(model); msvmmaj_initialize_weights(task->train_data, model); - msvmmaj_seed_model_V(seed_model, model); + msvmmaj_seed_model_V(seed_model, model, task->train_data); fid = MSVMMAJ_OUTPUT_FILE; MSVMMAJ_OUTPUT_FILE = NULL; @@ -607,7 +607,7 @@ void start_training_tt(struct Queue *q) if (task->test_data->y != NULL) total_perf = msvmmaj_prediction_perf(task->test_data, predy); - msvmmaj_seed_model_V(model, seed_model); + msvmmaj_seed_model_V(model, seed_model, task->train_data); msvmmaj_free_model(model); free(predy); diff --git a/src/trainMSVMMaj.c b/src/trainMSVMMaj.c index af07fe7..5377b43 100644 --- a/src/trainMSVMMaj.c +++ b/src/trainMSVMMaj.c @@ -113,10 +113,10 @@ int main(int argc, char **argv) if (msvmmaj_check_argv_eq(argc, argv, "-m")) { struct MajModel *seed_model = msvmmaj_init_model(); msvmmaj_read_model(seed_model, model_filename); - msvmmaj_seed_model_V(seed_model, model); + msvmmaj_seed_model_V(seed_model, model, data); msvmmaj_free_model(seed_model); } else { - msvmmaj_seed_model_V(NULL, model); + msvmmaj_seed_model_V(NULL, model, data); } // start training |
