-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some unittests and cleanup (in statistics and linalg)
- Loading branch information
Showing
6 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function unittest_subspace_angles | ||
% UNITTEST_SUBSPACE_ANGLES Test the SUBSPACE_ANGLES function. | ||
% | ||
% Example (<a href="matlab:run_example unittest_subspace_angles">run</a>) | ||
% unittest_subspace_angle | ||
% | ||
% See also SUBSPACE_ANGLES, TESTSUITE | ||
|
||
% Elmar Zander | ||
% Copyright 2010, Inst. of Scientific Computing, TU Braunschweig | ||
% $Id$ | ||
% | ||
% This program is free software: you can redistribute it and/or modify it | ||
% under the terms of the GNU General Public License as published by the | ||
% Free Software Foundation, either version 3 of the License, or (at your | ||
% option) any later version. | ||
% See the GNU General Public License for more details. You should have | ||
% received a copy of the GNU General Public License along with this | ||
% program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
munit_set_function( 'subspace_angles' ); | ||
|
||
e1=unitvector(1,4); | ||
e2=unitvector(2,4); | ||
e3=unitvector(3,4); | ||
e4=unitvector(4,4); | ||
|
||
test([e1, e2], [e1, e2]); | ||
test([e1, e2], [e1, e3]); | ||
test([e1, e2], [e3, e4]); | ||
test([e1, e2], [e1, -e2+e4]); | ||
|
||
A=rand(7,5); B=rand(7,5); | ||
assert_equals( asin(subspace_distance(A,B)), subspace(A,B) ) | ||
A=[A, A]; B=[B, B]; | ||
assert_equals( asin(subspace_distance(A,B)), subspace(A,B) ) | ||
A=rand(7,5); B=rand(7,3); | ||
assert_equals( asin(subspace_distance(A,B)), subspace(A,B) ) | ||
A=rand(7,3); B=rand(7,5); | ||
assert_equals( asin(subspace_distance(A,B)), subspace(A,B) ) | ||
|
||
|
||
function test(A1,A2) | ||
theta=subspace_angles(A1,A2); | ||
dist=subspace_distance(A1,A2); | ||
assert_equals( dist, sin(theta(2)) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function unittest_subspace_distance | ||
% UNITTEST_SUBSPACE_DISTANCE Test the SUBSPACE_DISTANCE function. | ||
% | ||
% Example (<a href="matlab:run_example unittest_subspace_distance">run</a>) | ||
% unittest_subspace_distance | ||
% | ||
% See also SUBSPACE_DISTANCE, TESTSUITE | ||
|
||
% Elmar Zander | ||
% Copyright 2013, Inst. of Scientific Computing, TU Braunschweig | ||
% | ||
% This program is free software: you can redistribute it and/or modify it | ||
% under the terms of the GNU General Public License as published by the | ||
% Free Software Foundation, either version 3 of the License, or (at your | ||
% option) any later version. | ||
% See the GNU General Public License for more details. You should have | ||
% received a copy of the GNU General Public License along with this | ||
% program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
munit_set_function( 'subspace_distance' ); | ||
|
||
|
||
rand('seed', 74765); %#ok<RAND> | ||
|
||
N=10; | ||
A=rand(N,3); | ||
B=rand(N,5); | ||
|
||
assert_equals(subspace_distance(A,B), subspace_distance(B,A), 'symm'); | ||
assert_equals(subspace_distance(A,B), sin(subspace(A,B)), 'mlab'); | ||
assert_equals(subspace_distance(A,[B, A]), 0, 'zero'); | ||
|
||
|
||
opts.type = 'gv'; | ||
A=rand(N,3); | ||
B=rand(N,3); | ||
assert_equals(subspace_distance(A,B,opts), subspace_distance(B,A,opts), 'symm_gv'); | ||
assert_equals(subspace_distance(A,B,opts), subspace_distance(A,B), 'same_as_mlab_if_same_size'); | ||
assert_equals(subspace_distance(A,[B, A],opts), 1, 'one_gv'); | ||
|
||
|
||
opts.type = 'wwf'; | ||
A=rand(N,3); | ||
B=rand(N,3); | ||
assert_equals(subspace_distance(A,B,opts), subspace_distance(B,A,opts), 'symm_wwf'); | ||
assert_equals(subspace_distance(A, A, opts), 0, 'zero_wwf'); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.