Skip to content

Commit e3d2145

Browse files
committed
Created testst for added demos and fixed a bug in probit likelihood
1 parent fd4c6db commit e3d2145

21 files changed

+336
-83
lines changed

gp/demo_derivatives.m

Lines changed: 80 additions & 81 deletions
Large diffs are not rendered by default.

gp/lik_probit.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ip=inputParser;
2626
ip.FunctionName = 'LIK_PROBIT';
2727
ip.addOptional('lik', [], @isstruct);
28-
ip.addParamValue('nu', [], @(x) ~isempty(x) && x>0)
28+
ip.addParamValue('nu', 1.0, @(x) ~isempty(x) && x>0)
2929
ip.parse(varargin{:});
3030
lik=ip.Results.lik;
3131

tests/realValues/derivatives.mat

204 KB
Binary file not shown.

tests/realValues/derivatives.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
TolFun reached. Func-count 28. Final f(x)=8.83586. Elapsed time 0.29
2+
TolFun reached. Func-count 31. Final f(x)=5.26377. Elapsed time 0.20
3+
TolFun reached. Func-count 25. Final f(x)=8.76508. Elapsed time 0.15
4+
TolFun reached. Func-count 55. Final f(x)=9.8007. Elapsed time 1.07
5+
TolFun reached. Func-count 26. Final f(x)=9.30243. Elapsed time 0.51
6+
TolFun reached. Func-count 19. Final f(x)=27.0383. Elapsed time 0.50
7+
TolFun reached. Func-count 19. Final f(x)=28.9647. Elapsed time 0.60
8+
TolX reached. Func-count 43. Final f(x)=57.4604. Elapsed time 4.95
9+
TolFun reached. Func-count 51. Final f(x)=13.8857. Elapsed time 0.29
10+
TolX reached. Func-count 28. Final f(x)= 2.899. Elapsed time 0.28
11+
TolFun reached. Func-count 27. Final f(x)=7.30701. Elapsed time 0.19
12+
TolFun reached. Func-count 30. Final f(x)=-14.7792. Elapsed time 0.40
13+
TolFun reached. Func-count 19. Final f(x)=8.95452. Elapsed time 0.13
14+
TolFun reached. Func-count 29. Final f(x)=11.6177. Elapsed time 0.94
15+
16+
gp hyperparameters:
17+
18+
0.2063 0.5772 -1.1356 1.2508 -5.3190
19+
20+
Demo completed in 0.228 minutes

tests/realValues/derivatives_fig1.fig

23.7 KB
Binary file not shown.

tests/realValues/derivatives_fig2.fig

34.9 KB
Binary file not shown.

tests/realValues/derivatives_fig3.fig

33.9 KB
Binary file not shown.

tests/realValues/derivatives_fig4.fig

177 KB
Binary file not shown.

tests/realValues/derivatives_fig5.fig

177 KB
Binary file not shown.

tests/realValues/derivatives_fig6.fig

106 KB
Binary file not shown.

tests/realValues/derivatives_fig7.fig

106 KB
Binary file not shown.

tests/realValues/derivatives_fig8.fig

106 KB
Binary file not shown.

tests/realValues/derivatives_fig9.fig

106 KB
Binary file not shown.

tests/realValues/multivariategp.mat

6.05 KB
Binary file not shown.

tests/realValues/multivariategp.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Iteration Func-count f(x) Lambda
2+
0 1 830.36
3+
1 3 647.34 10
4+
2 5 596.881 5
5+
3 7 583.62 2.5
6+
4 9 579.376 1.25
7+
5 11 577.385 0.625
8+
6 13 572.775 0.312
9+
7 15 572.187 0.156
10+
8 17 571.892 0.0781
11+
9 19 570.894 0.0391
12+
10 21 570.752 0.0195
13+
11 23 570.467 0.00977
14+
12 25 570.305 0.00488
15+
13 27 569.96 0.00244
16+
14 29 569.906 0.00122
17+
15 31 569.872 0.00061
18+
16 33 569.842 0.000305
19+
17 35 569.833 0.000153
20+
18 37 569.827 7.63e-05
21+
19 39 569.826 3.81e-05
22+
TolFun reached. Func-count 39. Final f(x)=569.826. Elapsed time 20.35
23+
24+
rho =
25+
26+
0.7887
27+
28+
Iteration Func-count f(x) Lambda
29+
0 1 1288.5
30+
1 3 526.16 10
31+
2 5 357.054 5
32+
3 7 303.202 2.5
33+
4 9 286.094 1.25
34+
5 11 283.636 0.625
35+
6 13 282.343 0.312
36+
7 15 282.255 0.156
37+
8 17 281.999 0.0781
38+
9 19 281.999 0.0391
39+
TolFun reached. Func-count 19. Final f(x)=281.999. Elapsed time 0.31
40+
Iteration Func-count f(x) Lambda
41+
0 1 1260.9
42+
1 3 478.783 10
43+
2 5 334.987 5
44+
3 7 326.08 2.5
45+
4 9 313.954 1.25
46+
5 11 294.246 0.625
47+
6 13 291.948 0.312
48+
7 15 286.84 0.156
49+
8 17 284.946 0.0781
50+
9 19 284.946 0.0391
51+
10 20 284.946 0.156
52+
11 21 284.894 0.625
53+
12 23 284.019 2.5
54+
13 25 283.102 1.25
55+
14 27 283.066 0.625
56+
15 29 283.064 0.312
57+
16 31 283.057 0.156
58+
17 33 283.057 0.0781
59+
TolFun reached. Func-count 33. Final f(x)=283.057. Elapsed time 0.54
60+
61+
gp hyperparameters:
62+
63+
1.2006 0.9512 2.1357 1.7055 1.4676 2.0421 3.9735
64+
65+
Demo completed in 0.401 minutes
20.2 KB
Binary file not shown.
5.61 KB
Binary file not shown.

tests/runtestset.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
% binomial_apc 0.224
2626
% classific 1.058
2727
% derivativeobs 0.020
28+
% derivatives 0.591
2829
% epinf 76.727
2930
% hierprior 2.734
3031
% hurdle 2.286
@@ -40,6 +41,7 @@
4041
% multiclass 42.372
4142
% multiclass_nested_ep 1.088
4243
% multinom 1.027
44+
% multivariategp 0.405
4345
% neuralnetcov 0.076
4446
% periodic 0.380
4547
% quantilegp 2.862
@@ -82,6 +84,7 @@
8284
'test_kalman1' ...
8385
'test_lgcp' ...
8486
'test_monotonic2' ...
87+
'test_multivariategp' ...
8588
'test_neuralnetcov' ...
8689
'test_periodic' ...
8790
'test_regression_additive1' ...
@@ -174,4 +177,4 @@
174177
error('Unsupported mode')
175178
end
176179

177-
end
180+
end

tests/test_derivatives.m

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
function test_suite = test_derivatives
2+
3+
% Run specific demo, save values and compare the results to the expected.
4+
% Works for both xUnit Test Framework package by Steve Eddins and for
5+
% the built-in Unit Testing Framework (as of Matlab version 2013b).
6+
%
7+
% See also
8+
% TEST_ALL, DEMO_DERIVATIVEOBS
9+
%
10+
% Copyright (c) 2017 Eero Siivola
11+
12+
% This software is distributed under the GNU General Public
13+
% License (version 3 or later); please refer to the file
14+
% License.txt, included with the software, for details.
15+
16+
% Check which package to use
17+
if exist('initTestSuite', 'file')
18+
initTestSuite_path = which('initTestSuite');
19+
else
20+
initTestSuite_path = '';
21+
end
22+
if ~isempty(initTestSuite_path) && ...
23+
exist([initTestSuite_path(1:end-15) 'runtests'], 'file')
24+
% xUnit package
25+
initTestSuite;
26+
else
27+
% Built-in package
28+
% Use all functions except the @setup
29+
tests = localfunctions;
30+
tests = tests(~cellfun(@(x)strcmp(func2str(x),'setup'),tests));
31+
test_suite = functiontests(tests);
32+
end
33+
end
34+
35+
36+
% -------------
37+
% Tests
38+
% -------------
39+
40+
function testRunDemo(testCase)
41+
% Run the correspondin demo and save the values. Note this test has to
42+
% be run at lest once before the other test may succeed.
43+
rundemo(getName())
44+
end
45+
46+
function test1DDirectDerivatives(testCase)
47+
% Test predictive mean and variance
48+
verifyVarsEqual(testCase, getName(), {'Ef_p1','Varf_p1'}, ...
49+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
50+
end
51+
52+
function test1DDirectDerivativesAndGaussianLikelihood(testCase)
53+
% Test predictive mean and variance
54+
verifyVarsEqual(testCase, getName(), {'Ef_p2','Varf_p2'}, ...
55+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
56+
end
57+
58+
function test1DDirectDerivativesAndNonGaussianLikelihood(testCase)
59+
% Test predictive mean and variance
60+
verifyVarsEqual(testCase, getName(), {'Ef_p3','Varf_p3', 'Ef_l_p3','Varf_l_p3'}, ...
61+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
62+
end
63+
64+
function test2DDirectDerivatives(testCase)
65+
% Test predictive mean and variance
66+
verifyVarsEqual(testCase, getName(), {'Ef_p4','Varf_p4'}, ...
67+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
68+
end
69+
70+
function test2DDirectDerivativesWithAdditive(testCase)
71+
% Test predictive mean and variance
72+
verifyVarsEqual(testCase, getName(), {'Ef_p5','Varf_p5'}, ...
73+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
74+
end
75+
76+
function test2DDirectDerivativesWithAdditive2(testCase)
77+
% Test predictive mean and variance
78+
verifyVarsEqual(testCase, getName(), {'Ef_p6','Varf_p6'}, ...
79+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
80+
end
81+
82+
% ------------------------
83+
% Helper functions
84+
% ------------------------
85+
86+
function testCase = setup
87+
% Helper function to suply empty array into variable testCase as an
88+
% argument for each test function, if using xUnit package. Not to be
89+
% used with built-in test framework.
90+
testCase = [];
91+
end
92+
93+
function name = getName
94+
% Helperfunction that returns the name of the demo, e.g. 'binomial1'.
95+
name = mfilename;
96+
name = name(6:end);
97+
end
98+

tests/test_improvemarginals.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function test_Laplace_CM2(testCase)
5858
'RelTolElement', 0.05, 'RelTolRange', 0.01)
5959
end
6060

61+
6162
function test_Laplace_fact(testCase)
6263
verifyVarsEqual(testCase, getName(), ...
6364
{'pc_la2','fvec_la2','pc_la_pred2','fvec_la_pred2'}, ...

tests/test_multivariategp.m

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function test_suite = test_multivariategp
2+
3+
% Run specific demo, save values and compare the results to the expected.
4+
% Works for both xUnit Test Framework package by Steve Eddins and for
5+
% the built-in Unit Testing Framework (as of Matlab version 2013b).
6+
%
7+
% See also
8+
% TEST_ALL, DEMO_DERIVATIVEOBS
9+
%
10+
% Copyright (c) 2017 Eero Siivola
11+
12+
% This software is distributed under the GNU General Public
13+
% License (version 3 or later); please refer to the file
14+
% License.txt, included with the software, for details.
15+
16+
% Check which package to use
17+
if exist('initTestSuite', 'file')
18+
initTestSuite_path = which('initTestSuite');
19+
else
20+
initTestSuite_path = '';
21+
end
22+
if ~isempty(initTestSuite_path) && ...
23+
exist([initTestSuite_path(1:end-15) 'runtests'], 'file')
24+
% xUnit package
25+
initTestSuite;
26+
else
27+
% Built-in package
28+
% Use all functions except the @setup
29+
tests = localfunctions;
30+
tests = tests(~cellfun(@(x)strcmp(func2str(x),'setup'),tests));
31+
test_suite = functiontests(tests);
32+
end
33+
end
34+
35+
36+
% -------------
37+
% Tests
38+
% -------------
39+
40+
function testRunDemo(testCase)
41+
% Run the correspondin demo and save the values. Note this test has to
42+
% be run at lest once before the other test may succeed.
43+
rundemo(getName())
44+
end
45+
46+
function testPredictions(testCase)
47+
% Test predictive mean and variance
48+
verifyVarsEqual(testCase, getName(), {'Ef', 'Varf'}, ...
49+
'RelTolElement', 0.05, 'RelTolRange', 0.01)
50+
end
51+
% ------------------------
52+
% Helper functions
53+
% ------------------------
54+
55+
function testCase = setup
56+
% Helper function to suply empty array into variable testCase as an
57+
% argument for each test function, if using xUnit package. Not to be
58+
% used with built-in test framework.
59+
testCase = [];
60+
end
61+
62+
function name = getName
63+
% Helperfunction that returns the name of the demo, e.g. 'binomial1'.
64+
name = mfilename;
65+
name = name(6:end);
66+
end
67+

0 commit comments

Comments
 (0)