⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 model_test.m.svn-base

📁 Bayesian Surprise Toolkit for Matlab T. Nathan Mundhenk, Laurent Itti
💻 SVN-BASE
字号:
% ---- Bivariant Model Example ----
% Run this test.m file to check that the model works as it is supposed to
% before commiting changes it will check that the output and inputs match
% as supposed to and will call each of the example files to make sure that
% they complete. This file it intended for code stability and testing. If
% you just downloaded the code and want to try it out, see:
%   example.m
%   example2.m
%   experiment1.m
%   example_graph.m
%
%   To format data to be placed in here, use model_format_data.m

% //////////////////////////////////////////////////////////////////// %
% The Baysian Surprise Matlab Toolkit - Copyright (C) 2004-2007        %
% by the University of Southern California (USC) and the iLab at USC.  %
% See http://iLab.usc.edu for information about this project.          %
% //////////////////////////////////////////////////////////////////// %
% This file is part of the Baysian Surprise Matlab Toolkit             %
%                                                                      %
% The Baysian Surprise Matlab Toolkit 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 2 of the License, or (at your option) any later version.     %
%                                                                      %
% The Baysian Surprise Matlab Toolkit is distributed in the hope       %
% that it will be useful, but WITHOUT ANY WARRANTY; without even the   %
% implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      %
% PURPOSE.  See the GNU General Public License for more details.       %
%                                                                      %
% You should have received a copy of the GNU General Public License    %
% along with the iBaysian Surprise Matlab Toolkit; if not, write       %
% to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   %
% Boston, MA 02111-1307 USA.                                           %
% //////////////////////////////////////////////////////////////////// %
%
% Primary maintainer for this file: T. Nathan Mundhenk <mundhenk@usc.edu>
%

% (1) Check to make sure the examples still work and are not broken
fprintf('*****************************************************\n');
fprintf('TESTING example.m\n');
example
fprintf('*****************************************************\n');
fprintf('TESTING example2.m\n');
example2
fprintf('*****************************************************\n');
fprintf('TESTING experiment1.m\n');
experiment1
fprintf('*****************************************************\n');
fprintf('TESTING example_graph.m\n');
example_graph
fprintf('*****************************************************\n');
fprintf('TEST SCRIPTS RUN OK\n');

fprintf('*****************************************************\n');
fprintf('RUNNING VALUE TESTS\n');

PassVal = 0;
Tests   = 0;
Rmax    = 0.0000001;
% (2) Check the univariate Models to make sure that they return expected
% values
fprintf('*****************************************************\n');
fprintf('RUNNING UNIVARIATE MODEL TESTS\n');
data    = [1 2 4 8 16 1 2 4 8 16 8 4 2 1 1 1 1 2 4 8 16 32 16 8 4 2 1 32 16 8 4 2 1 2 4 8 16 32 32 32 32 1 1 1 1];
fprintf('*****************************************************\n');
fprintf('RUNNING TEST A-1\n');
smod    = newsm(0.7);
smod.options.debug = 0;
smod.options.factordecay = 'yes';
smod.options.robbins_monro = 'yes';
smod    = runsm(data,smod);

e_data = [ 1.179726 ; 1.931289 ; 2.210539 ; 2.655791 ; 3.201990 ; 5.666099 ; 2.595168 ; ...
           2.354112 ; 2.374396 ; 2.552527 ; 2.827307 ; 2.883379 ; 2.756011 ; 2.445142 ; ...
           1.971622 ; 1.741602 ; 1.613886 ; 1.592131 ; 1.747823 ; 2.017848 ; 2.405689 ; ...
           2.889096 ; 3.386384 ; 3.537527 ; 3.423828 ; 3.063974 ; 2.618742 ; 2.489094 ; ...
           2.646990 ; 2.718521 ; 2.858130 ; 2.664615 ; 2.366626 ; 1.919139 ; 1.900184 ; ...
           2.028608 ; 2.302987 ; 2.705540 ; 3.140480 ; 3.499670 ; 3.759070 ; 4.717428 ; ...
           3.050410 ; 2.267999 ; 1.880413 ];

[Rval,Pass] = model_eval(smod.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
fprintf('*****************************************************\n');
fprintf('RUNNING TEST A-2\n');
smod    = newsm(0.7);
smod.options.debug = 0;
smod.options.factordecay = 'no';
smod.options.robbins_monro = 'yes';
smod    = runsm(data,smod);

e_data = [ 1.179726 ; 1.944426 ; 2.171435 ; 2.620000 ; 3.005933 ; 3.548907 ; 2.518557 ; ...
           2.268853 ; 2.382525 ; 2.652149 ; 2.972683 ; 2.951669 ; 2.732461 ; 2.403969 ; ...
           1.975821 ; 1.765138 ; 1.669987 ; 1.643605 ; 1.849380 ; 2.146079 ; 2.495092 ; ...
           2.883417 ; 3.269628 ; 3.309933 ; 3.135400 ; 2.832419 ; 2.458115 ; 2.179284 ; ...
           2.824848 ; 3.042984 ; 2.976547 ; 2.739304 ; 2.404963 ; 1.962601 ; 1.983635 ; ...
           2.207700 ; 2.525772 ; 2.899515 ; 3.289025 ; 3.520557 ; 3.659135 ; 3.907249 ; ...
           2.831810 ; 2.205254 ; 1.875199 ];
[Rval,Pass] = model_eval(smod.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
fprintf('*****************************************************\n');
fprintf('RUNNING TEST A-3\n');
smod    = newsm(0.7);
smod.options.debug = 0;
smod.options.factordecay = 'no';
smod.options.robbins_monro = 'no';
smod    = runsm(data,smod);

e_data = [ 1.105826 ; 2.042862 ; 4.073972 ; 8.225801 ; 16.675653 ; 25.711285 ; 18.664126 ; ...
           14.791841 ; 14.802615 ; 20.819879 ; 28.624260 ; 28.318072 ; 24.138247 ; 19.104889 ; ...
           14.355120 ; 11.028694 ; 8.702130 ; 6.984683 ; 7.165158 ; 10.297865 ; 18.336139 ; ...
           35.506620 ; 50.200522 ; 51.306783 ; 44.433669 ; 35.495073 ; 27.092558 ; 32.862475 ; ...
           45.721269 ; 48.052988 ; 42.132311 ; 33.873933 ; 25.952250 ; 18.922504 ; 15.024333 ; ...
           15.000061 ; 20.998063 ; 37.104862 ; 55.264944 ; 70.127114 ; 80.925555 ; 89.950895 ; ...
           64.341285 ; 46.206312 ; 33.408430 ];
[Rval,Pass] = model_eval(smod.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
% (2) Check the bivariate Models to make sure that they return expected
% values
fprintf('*****************************************************\n');
fprintf('RUNNING BIVARIATE MODEL TESTS\n');
data    = [ 1 1 ; 2 2 ; 3 4 ; 4 8 ; 5 16 ; 6 1 ; 1 1 ; 2 2 ; 3 3 ; 4 4 ; 5 5 ; 6 6 ; 6 3 ; 6 1 ; 1 1 ; 1 2 ; 1 3 ; ...
            1 4 ; 1 5 ; 1 6 ; 1 1 ; 6 1  ; 1 6 ; 6 1 ; 1 1 ; 6 6 ; 5 5 ; 4 4 ; 3 3 ; 2 2 ; 1 1 ; 1 2 ; 2 1 ; 1 3 ];
fprintf('*****************************************************\n');
fprintf('RUNNING TEST B-1\n');    
smod    = newsm(0.7,1,1,0,1,2);
smod.options.debug = 0;
smod.options.factordecay = 'yes';
smod.options.robbins_monro_3 = 'yes';
smod.options.jointmodel = 'mux';
smod    = runsm(data,smod);

e_data = [ 3.087038 ; 1.679007 ; 1.847540 ; 2.052965 ; 2.261978 ; 2.140827 ; 1.771600 ; ...
           1.552083 ; 1.553496 ; 1.630812 ; 1.731915 ; 1.833982 ; 1.830657 ; 1.762171 ; ...
           1.527974 ; 1.407301 ; 1.402594 ; 1.453382 ; 1.526596 ; 1.605022 ; 1.450712 ; ...
           1.537419 ; 1.613739 ; 1.643864 ; 1.471056 ; 1.679934 ; 1.752838 ; 1.762381 ; ...
           1.708658 ; 1.600569 ; 1.428694 ; 1.367408 ; 1.354249 ; 1.408508 ];
[Rval,Pass] = model_eval(smod.joint.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
fprintf('*****************************************************\n');
fprintf('RUNNING TEST B-2\n');    
smod    = newsm(0.7,1,1,0,1,2);
smod.options.debug = 0;
smod.options.factordecay = 'yes';
smod.options.robbins_monro_3 = 'no';
smod.options.jointmodel = 'mux';
smod    = runsm(data,smod);

e_data = [ 3.087038 ; 1.798205 ; 2.162353 ; 2.520984 ; 2.898347 ; 3.036737 ; 2.102092 ; ...
           1.798186 ; 1.748191 ; 1.814330 ; 1.919363 ; 2.031099 ; 2.001448 ; 1.882726 ; ...
           1.621602 ; 1.446511 ; 1.458161 ; 1.543807 ; 1.635472 ; 1.718680 ; 1.585753 ; ...
           1.611974 ; 1.879176 ; 1.923320 ; 1.723295 ; 2.163500 ; 2.148715 ; 2.089920 ; ...
           1.928663 ; 1.731272 ; 1.498908 ; 1.406603 ; 1.375927 ; 1.443034 ];
[Rval,Pass] = model_eval(smod.joint.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
fprintf('*****************************************************\n');
fprintf('RUNNING TEST B-3\n');    
smod    = newsm(0.7,1,1,0,1,2);
smod.options.debug = 0;
smod.options.factordecay = 'no';
smod.options.robbins_monro_3 = 'no';
smod.options.jointmodel = 'blind';
smod    = runsm(data,smod);

e_data = [ 2.022224 ; 2.141421 ; 2.620969 ; 3.149553 ; 3.754148 ; 3.848803 ; 2.532020 ; ...
           2.201044 ; 2.218729 ; 2.375233 ; 2.563145 ; 2.746287 ; 2.697058 ; 2.523837 ; ...
           2.091843 ; 1.862818 ; 1.899356 ; 2.031025 ; 2.165474 ; 2.289091 ; 2.031518 ; ...
           2.139153 ; 2.482185 ; 2.504428 ; 2.093177 ; 2.836981 ; 2.826662 ; 2.742681 ; ...
           2.519143 ; 2.238777 ; 1.890671 ; 1.790982 ; 1.762929 ; 1.875131 ];
[Rval,Pass] = model_eval(smod.joint.surprise,e_data,Rmax);
PassVal = PassVal + Pass;
Tests   = Tests + 1;
fprintf('*****************************************************\n');
fprintf('RESULTS\n');   
fprintf('*****************************************************\n');
if PassVal ~= Tests
    fprintf('>>>WARNING!!! Not All Tests Passed<<<\n');
end
fprintf('TESTS:  %d\n',Tests);
fprintf('PASSED: %d\n',PassVal);
fprintf('*****************************************************\n');


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -