diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2016-12-05 20:06:26 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <burg@ese.eur.nl> | 2016-12-05 20:06:26 +0100 |
| commit | 463e406d4af8ad20a1ec2c3b9e01f3f80267c0dd (patch) | |
| tree | c263185666cc4abf474c9f53830de482ed3bcb79 | |
| parent | add octave testfiles to git (diff) | |
| download | gensvm-463e406d4af8ad20a1ec2c3b9e01f3f80267c0dd.tar.gz gensvm-463e406d4af8ad20a1ec2c3b9e01f3f80267c0dd.zip | |
fix missing test in gensvm_optimize and expose doublesort
| -rw-r--r-- | include/gensvm_consistency.h | 1 | ||||
| -rw-r--r-- | src/gensvm_consistency.c | 5 | ||||
| -rw-r--r-- | src/gensvm_io.c | 4 | ||||
| -rw-r--r-- | tests/aux/test_optimize.m | 13 | ||||
| -rw-r--r-- | tests/src/test_gensvm_consistency.c | 14 | ||||
| -rw-r--r-- | tests/src/test_gensvm_optimize.c | 59 |
6 files changed, 74 insertions, 22 deletions
diff --git a/include/gensvm_consistency.h b/include/gensvm_consistency.h index cc0eeea..61e699d 100644 --- a/include/gensvm_consistency.h +++ b/include/gensvm_consistency.h @@ -36,6 +36,7 @@ // function declarations struct GenQueue *gensvm_top_queue(struct GenQueue *q, double percentile); +int gensvm_dsort(const void *elem1, const void *elem2); void gensvm_consistency_repeats(struct GenQueue *q, long repeats, double percentile); double gensvm_percentile(double *values, long N, double p); diff --git a/src/gensvm_consistency.c b/src/gensvm_consistency.c index eaa4f8c..3881bb9 100644 --- a/src/gensvm_consistency.c +++ b/src/gensvm_consistency.c @@ -272,7 +272,7 @@ void gensvm_consistency_repeats(struct GenQueue *q, long repeats, * @param[in] elem2 number 2 * @returns comparison of number 1 larger than number 2 */ -int doublesort(const void *elem1, const void *elem2) +int gensvm_dsort(const void *elem1, const void *elem2) { const double t1 = (*(double *) elem1); const double t2 = (*(double *) elem2); @@ -304,7 +304,7 @@ double gensvm_percentile(double *values, long N, double p) for (i=0; i<N; i++) local[i] = values[i]; - qsort(local, N, sizeof(double), doublesort); + qsort(local, N, sizeof(double), gensvm_dsort); p /= 100.0; p = p*N + 0.5; pi = maximum(minimum(floor(p), N-1), 1); @@ -315,4 +315,3 @@ double gensvm_percentile(double *values, long N, double p) return boundary; } - diff --git a/src/gensvm_io.c b/src/gensvm_io.c index 1da5597..e77d647 100644 --- a/src/gensvm_io.c +++ b/src/gensvm_io.c @@ -39,8 +39,8 @@ * Read the data from the data_file. The data matrix X is augmented * with a column of ones, to get the matrix Z. The data is expected * to follow a specific format, which is specified in the @ref spec_data_file. - * The class labels are corrected internally to correspond to the interval - * [1 .. K], where K is the total number of classes. + * The class labels are checked to make sure they correspond to the interval + * [1 .. K], where K is the total number of classes, without any gaps. * * @todo * Make sure that this function allows datasets without class labels for diff --git a/tests/aux/test_optimize.m b/tests/aux/test_optimize.m index ecd10a3..deae960 100644 --- a/tests/aux/test_optimize.m +++ b/tests/aux/test_optimize.m @@ -27,6 +27,8 @@ set_vector(rho); V = [t'; W]; +assert_matrix(V, "model->V", "model->K-1"); + end function set_matrix(A) @@ -41,4 +43,15 @@ function set_vector(a) for i=1:numel(a) fprintf('A[%i] = %.16f;\n', i-1, a(i)); end +end + +function assert_matrix(A, name, cols) + for ii=1:size(A, 1) + for jj=1:size(A, 2) + fprintf(["mu_assert(fabs(matrix_get(%s, %s, %i, %i) -\n%.16f) <", ... + " eps,\n\"Incorrect %s at %i, %i\");\n"], name, cols, ... + ii-1, jj-1, A(ii, jj), name, ii-1, jj-1); + end + end + fprintf("\n"); end
\ No newline at end of file diff --git a/tests/src/test_gensvm_consistency.c b/tests/src/test_gensvm_consistency.c index af0a0f3..439df05 100644 --- a/tests/src/test_gensvm_consistency.c +++ b/tests/src/test_gensvm_consistency.c @@ -32,9 +32,9 @@ char *test_doublesort() double a = 1.0; double b = 2.0; - mu_assert(doublesort(&b, &a) == true, "Incorrect doublesort (1)"); - mu_assert(doublesort(&a, &b) == false, "Incorrect doublesort (2)"); - mu_assert(doublesort(&a, &a) == false, "Incorrect doublesort (3)"); + mu_assert(gensvm_dsort(&b, &a) == true, "Incorrect doublesort (1)"); + mu_assert(gensvm_dsort(&a, &b) == false, "Incorrect doublesort (2)"); + mu_assert(gensvm_dsort(&a, &a) == false, "Incorrect doublesort (3)"); return NULL; } @@ -122,6 +122,13 @@ char *test_top_queue() return NULL; } +char *test_consistency_repeats() +{ + mu_test_missing(); + + return NULL; +} + char *all_tests() { mu_suite_start(); @@ -129,6 +136,7 @@ char *all_tests() mu_run_test(test_percentile_1); mu_run_test(test_percentile); mu_run_test(test_top_queue); + mu_run_test(test_consistency_repeats); return NULL; } diff --git a/tests/src/test_gensvm_optimize.c b/tests/src/test_gensvm_optimize.c index a983ec1..6263441 100644 --- a/tests/src/test_gensvm_optimize.c +++ b/tests/src/test_gensvm_optimize.c @@ -30,9 +30,6 @@ #include "gensvm_debug.h" -extern FILE *GENSVM_OUTPUT_FILE; -extern FILE *GENSVM_ERROR_FILE; - char *test_gensvm_optimize() { struct GenModel *model = gensvm_init_model(); @@ -123,20 +120,55 @@ char *test_gensvm_optimize() gensvm_init_V(seed_model, model, data); gensvm_initialize_weights(data, model); - model->rho[0] = 0.3294151808829250; - model->rho[1] = 0.6047157463292797; - model->rho[2] = 0.7628723943431572; - model->rho[3] = 0.4561071643209315; - model->rho[4] = 0.8400578887926284; - model->rho[5] = 0.1390735925868357; - model->rho[6] = 0.3505528063594583; - model->rho[7] = 0.0840834388268874; + model->rho[0] = 0.3607870295944514; + model->rho[1] = 0.2049421299461539; + model->rho[2] = 0.0601488725348535; + model->rho[3] = 0.4504181439770731; + model->rho[4] = 0.0925063643277065; + model->rho[5] = 0.2634120202183680; + model->rho[6] = 0.8675978657103286; + model->rho[7] = 0.1633697022472280; // start test code // - GENSVM_OUTPUT_FILE = stdout; gensvm_optimize(model, data); - gensvm_print_matrix(model->V, model->m+1, model->K-1); + double eps = 1e-13; + mu_assert(fabs(matrix_get(model->V, model->K-1, 0, 0) - + -0.3268931274065331) < eps, + "Incorrect model->V at 0, 0"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 0, 1) - + 0.1117992620472728) < eps, + "Incorrect model->V at 0, 1"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 0, 2) - + 0.1988823609241294) < eps, + "Incorrect model->V at 0, 2"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 1, 0) - + 1.2997452108481067) < eps, + "Incorrect model->V at 1, 0"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 1, 1) - + -0.7171806413563449) < eps, + "Incorrect model->V at 1, 1"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 1, 2) - + -0.4657948105281003) < eps, + "Incorrect model->V at 1, 2"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 2, 0) - + 0.4408949033586493) < eps, + "Incorrect model->V at 2, 0"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 2, 1) - + 0.0257888242538633) < eps, + "Incorrect model->V at 2, 1"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 2, 2) - + 1.1285833836998647) < eps, + "Incorrect model->V at 2, 2"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 3, 0) - + -1.1983357619969028) < eps, + "Incorrect model->V at 3, 0"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 3, 1) - + -0.4872684816635944) < eps, + "Incorrect model->V at 3, 1"); + mu_assert(fabs(matrix_get(model->V, model->K-1, 3, 2) - + -1.3711836483504121) < eps, + "Incorrect model->V at 3, 2"); // end test code // @@ -144,7 +176,6 @@ char *test_gensvm_optimize() gensvm_free_model(model); gensvm_free_model(seed_model); - mu_test_missing(); return NULL; } |
