aboutsummaryrefslogtreecommitdiff
path: root/tests/aux
diff options
context:
space:
mode:
Diffstat (limited to 'tests/aux')
-rw-r--r--tests/aux/README.md2
-rw-r--r--tests/aux/dposvtest.m64
-rw-r--r--tests/aux/dsysvtest.m37
-rw-r--r--tests/aux/testje.m79
4 files changed, 182 insertions, 0 deletions
diff --git a/tests/aux/README.md b/tests/aux/README.md
new file mode 100644
index 0000000..399e82f
--- /dev/null
+++ b/tests/aux/README.md
@@ -0,0 +1,2 @@
+This folder contains auxiliary files that were used to construct some of the
+unit tests.
diff --git a/tests/aux/dposvtest.m b/tests/aux/dposvtest.m
new file mode 100644
index 0000000..7937d6a
--- /dev/null
+++ b/tests/aux/dposvtest.m
@@ -0,0 +1,64 @@
+clear;
+more off;
+
+rand('state', 219038);
+
+n = 6;
+m = 5;
+
+tmp = rand(n);
+A = tmp + tmp' + n*eye(n);
+
+% Since we're testing the lower part of A, delete the upper triangel
+
+%idx = triu(ones(n)) - eye(n);
+%idx = logical(idx);
+%A(idx) = NaN;
+
+for i=1:size(A, 1)
+ for j=1:size(A, 2)
+ if j >= i % only print the upper part
+ fprintf('matrix_set(A, n, %i, %i, %.16f);\n', i-1, j-1, A(i, j));
+ end
+ end
+end
+fprintf('\n\n');
+
+B = rand(n, m);
+%b = vec(B); % this gives B in column-major order
+%for i=1:numel(b)
+% fprintf('B[%i] = %.16f;\n', i-1, b(i));
+%end
+
+%for i=1:size(B, 1)
+% for j=1:size(B, 2)
+% fprintf('matrix_set(B, m, %i, %i, %.16f);\n', i-1, j-1, B(i, j));
+% end
+%end
+%fprintf('\n\n');
+X = A \ B;
+
+x = vec(X);
+for i=1:numel(x)
+ fprintf('mu_assert(fabs(B[%i] - %.16f) < 1e-14,\n"Incorrect value of B at %i");\n', i-1, x(i), i-1);
+end
+%
+%for i=1:size(X, 1)
+% for j=1:size(X, 2)
+% fprintf('mu_assert(fabs(matrix_get(B, m, %i, %i) -\n%.16f) < 1e-14,\n"Incorrect value of B at %i, %i");\n', i-1, j-1, X(i, j), i-1, j-1);
+% end
+%end
+fprintf('\n\n');
+
+
+
+%
+%dposv(
+% UPLO, 'L'
+% N, 'n'
+% NRHS, 'm'
+% A, 'A'
+% LDA, 'n'
+% B, 'B'
+% LDB, 'n'
+% INFO) \ No newline at end of file
diff --git a/tests/aux/dsysvtest.m b/tests/aux/dsysvtest.m
new file mode 100644
index 0000000..fb22f5c
--- /dev/null
+++ b/tests/aux/dsysvtest.m
@@ -0,0 +1,37 @@
+more off;
+clear;
+
+rand('state', 891716);
+
+n = 6;
+m = 5;
+
+
+tmp = rand(n);
+% A is symmetric, but not necessarily p.s.d.
+A = tmp + tmp';
+clear tmp;
+
+for i=1:size(A, 1)
+ for j=1:size(A, 2)
+ if j >= i % only print the upper part
+ fprintf('matrix_set(A, n, %i, %i, %.16f);\n', i-1, j-1, A(i, j));
+ end
+ end
+end
+fprintf('\n\n');
+
+B = rand(n, m);
+b = vec(B); % this gives B in column-major order
+for i=1:numel(b)
+ fprintf('B[%i] = %.16f;\n', i-1, b(i));
+end
+
+X = A \ B;
+
+x = vec(X);
+for i=1:numel(x)
+ fprintf('mu_assert(fabs(B[%i] - %.16f) < 1e-14,\n"Incorrect value of B at %i");\n', i-1, x(i), i-1);
+end
+
+fprintf('\n\n');
diff --git a/tests/aux/testje.m b/tests/aux/testje.m
new file mode 100644
index 0000000..aaad1f7
--- /dev/null
+++ b/tests/aux/testje.m
@@ -0,0 +1,79 @@
+clear;
+
+rand('state', 123456);
+
+n = 8;
+m = 3;
+K = 3;
+
+y = [ 2 1 3 2 3 3 1 2]';
+
+U = SimplexGen(K);
+
+UU = zeros(n, K-1, K);
+
+for jj=1:K
+ UU(:, :, jj) = U(y, :) - U(jj*ones(n, 1), :);
+end
+
+VV = zeros(n, K-1, K);
+for i=1:n
+ for j=1:K-1
+ for k=1:K
+ VV(i, j, k) = U(y(i), j) - U(k, j);
+ end
+ end
+end
+
+Z = [ones(n, 1), -1 + 2 * rand(n, m)];
+
+V = -1 + 2 * rand(m+1, K-1);
+
+ZV = Z*V;
+
+Q = zeros(n, K);
+for i=1:n
+ for j=1:K
+ Q(i, j) = ZV(i, :) * (U(y(i), :) - U(j, :))';
+ end
+end
+
+% calculate loss
+kappa = 0.5;
+p = 1.5;
+%rho = ones(n, 1);
+rho = zeros(n, 1);
+for i=1:K
+ nk = sum(y == i);
+ rho(y==i) = (n/(K*nk));
+end
+lambda = 0.123;
+
+H = zeros(n, K);
+for i=1:n
+ for j=1:K
+ q = Q(i, j);
+ if (q <= -kappa)
+ H(i, j) = (1 - q - (kappa + 1)/2.0);
+ elseif (q <= 1)
+ H(i, j) = (1/(2*kappa + 2)) * (1 - q)^2;
+ else
+ H(i, j) = 0;
+ end
+ end
+end
+
+R = zeros(n, K);
+I = eye(K);
+for i=1:n
+ R(i, :) = I(y(i, :), :);
+end
+R = ~logical(R);
+
+J = eye(m+1);
+J(1, 1) = 0;
+
+L = sum((H.^p).*R, 2).^(1/p);
+L = 1/n * sum(rho.*L) + lambda * trace(V'*J*V);
+
+% DON"T REMOVE YET!! \ No newline at end of file