diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2016-12-06 15:06:10 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <burg@ese.eur.nl> | 2016-12-06 15:06:10 +0100 |
| commit | 62d235ba7e3a19d7cb65b2bdcb87d53fd65f11c4 (patch) | |
| tree | bf7b3fa950ac6635f67d7cbd832bc2a123c0bf08 /tests/aux/test_train.m | |
| parent | fix missing test in gensvm_optimize and expose doublesort (diff) | |
| download | gensvm-62d235ba7e3a19d7cb65b2bdcb87d53fd65f11c4.tar.gz gensvm-62d235ba7e3a19d7cb65b2bdcb87d53fd65f11c4.zip | |
add unit tests for gensvm_train
Diffstat (limited to 'tests/aux/test_train.m')
| -rw-r--r-- | tests/aux/test_train.m | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/aux/test_train.m b/tests/aux/test_train.m new file mode 100644 index 0000000..86d3074 --- /dev/null +++ b/tests/aux/test_train.m @@ -0,0 +1,52 @@ +function [V] = test_train() + +clear; +more off; +rand('state', 123456); + +n = 10; +m = 3; +K = 4; + +X = rand(n, m); +Z = [ones(n, 1), X]; +set_matrix(Z, "data->Z", "data->m+1"); + +y = [2 1 3 2 3 2 4 1 3 4]; +set_matrix(y, "data->y", "1"); + +p = 1.2143; +kappa = 0.90298; +lambda = 0.00219038; +epsilon = 1e-15; +rho = ones(n, 1); +seedV = rand(m+1, K-1); +set_matrix(seedV, "seed->V", "data->K-1"); + +[W, t] = msvmmaj(X, y, rho, p, kappa, lambda, epsilon, 'show', 0, seedV); +V = [t'; W]; + +fprintf('\n'); +assert_matrix(V, "model->V", "model->K-1"); + +end + +function set_matrix(A, name, cols) + for ii=1:size(A, 1) + for jj=1:size(A, 2) + fprintf("matrix_set(%s, %s, %i, %i, %.16f);\n", name, cols, ii-1, jj-1, A(ii, jj)); + end + end + fprintf("\n"); +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 |
