]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/naninsttest.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / naninsttest.m
1 % NANINSTTEST checks whether the functions from NaN-toolbox have been
2 % correctly installed. 
3 %
4 % see also: NANTEST
5
6 %    $Id: naninsttest.m 8223 2011-04-20 09:16:06Z schloegl $
7 %    Copyright (C) 2000-2003 by Alois Schloegl <alois.schloegl@gmail.com>
8 %    This script is part of the NaN-toolbox
9 %    http://pub.ist.ac.at/~schloegl/matlab/NaN/
10
11 %    This program is free software; you can redistribute it and/or modify
12 %    it under the terms of the GNU General Public License as published by
13 %    the Free Software Foundation; either version 3 of the License, or
14 %    (at your option) any later version.
15 %
16 %    This program is distributed in the hope that it will be useful,
17 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 %    GNU General Public License for more details.
20 %
21 %    You should have received a copy of the GNU General Public License
22 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
23
24
25 r = zeros(38,2);
26
27 x = [5,NaN,0,1,nan];
28
29 % run test, k=1: with NaNs, k=2: all NaN's are removed
30 % the result of both should be the same. 
31
32 %FLAG_WARNING = warning;
33 warning('off');
34
35 funlist = {'sumskipnan','mean','std','var','skewness','kurtosis','sem','median','mad','zscore','coefficient_of_variation','geomean','harmmean','meansq','moment','rms','','corrcoef','rankcorr','spearman','ranks','center','trimean','min','max','tpdf','tcdf','tinv','normpdf','normcdf','norminv','nansum','nanstd','histo_mex','sumskipnan_mex','covm_mex','svmtrain_mex','train','','','','','','','',''};
36 for k=1:2,
37         if k==2, x(isnan(x))=[]; end; 
38         r(1,k) =sumskipnan(x(1));
39         r(2,k) =mean(x);
40         r(3,k) =std(x);
41         r(4,k) =var(x);
42                 r(5,k) = skewness(x);
43                 r(6,k) =kurtosis(x);
44                 r(7,k) =sem(x);
45         r(8,k) =median(x);
46                 r(9,k) =mad(x);
47                 tmp = zscore(x); 
48                 r(10,k)=tmp(1);
49         if exist('coefficient_of_variation','file'),
50                 r(11,k)=coefficient_of_variation(x);
51         end;
52                 r(12,k)=geomean(x);
53                 r(13,k)=harmmean(x);
54         if exist('meansq','file'),
55                 r(14,k)=meansq(x);
56         end;
57         if exist('moment','file'),
58                 r(15,k)=moment(x,6);
59         end;
60         if exist('rms','file'),
61                 r(16,k)=rms(x);
62         end;
63         % r(17,k) is currently empty. 
64                 tmp=corrcoef(x',(1:length(x))');
65         r(18,k)=any(isnan(tmp(:)));
66         if exist('rankcorr','file'),
67                 tmp=rankcorr(x',(1:length(x))');
68                 r(19,k)=any(isnan(tmp(:)));
69         end;
70         if exist('spearman','file'),
71                 tmp=spearman(x',(1:length(x))');
72                 r(20,k)=any(isnan(tmp(:)));
73         end;
74         if exist('ranks','file'),
75                 r(21,k)=any(isnan(ranks(x')))+k;
76         end;
77         if exist('center','file'),
78                 tmp=center(x);
79                 r(22,k)=tmp(1);
80         end;
81         if exist('trimean','file'),
82                 r(23,k)=trimean(x);
83         end;
84         r(24,k)=min(x);
85         r(25,k)=max(x);
86         
87         r(26,k) = k+isnan(tpdf(x(2),4));                
88         
89         try
90                 r(27,k) = k*(~isnan(tcdf(nan,4)));              
91         catch
92                 r(27,k) = k;    
93         end;
94         
95         r(28,k) = k*(~isnan(tinv(NaN,4)));              
96         
97         if exist('normpdf','file'), 
98                 fun='normpdf'; 
99         elseif exist('normal_pdf','file'),
100                 fun='normal_pdf';
101         end;
102         r(29,k) = (feval(fun,k,k,0)~=Inf)*k;            
103         if exist('normcdf','file'), 
104                 fun='normcdf'; 
105         elseif exist('normal_cdf','file'),
106                 fun='normal_cdf';
107         end;
108         r(30,k) = feval(fun,4,4,0);             
109         if exist('norminv','file'), 
110                 fun='norminv'; 
111         elseif exist('normal_inv','file'),
112                 fun='normal_inv';
113         end;
114         r(31,k) = k*any(isnan(feval(fun,[0,1],4,0)));           
115         if exist('nansum','file'),
116                 r(32,k)=k*isnan(nansum(nan));
117         end;
118         if exist('nanstd','file'),
119                 r(33,k)=k*(~isnan(nanstd(0)));
120         end;
121         
122         %%% check mex files 
123         try 
124                 histo_mex([1:5]');
125                 r(34,k)=0;
126         catch;
127                 r(34,k)=k;
128         end;
129         try 
130                 sumskipnan_mex([1:5]');
131                 r(35,k)=0;
132         catch;
133                 r(35,k)=k;
134         end;
135         try 
136                 covm_mex([1:5]');
137                 r(36,k)=0;
138         catch;
139                 r(36,k)=k;
140         end;
141         if ~exist('svmtrain_mex','file'),
142                 r(37,k)=k;
143         end;
144         if ~exist('train','file'),
145                 r(38,k)=k;
146         end;
147 end;
148
149 % check if result is correct
150 tmp = abs(r(:,1)-r(:,2))<eps;
151
152 q = zeros(1,5);
153
154 % output
155 if all(tmp(1:32)) && all(~q),
156         fprintf(1,'NANINSTTEST successful - your NaN-tools are correctly installed\n');
157         if any(~tmp(34:38)),
158                 fprintf(1,'Warning: the following mex-files are not (properly) compiled:\n');
159                 for k=find(~tmp(34:38)'),
160                         fprintf(1,'     %s.mex \n',funlist{k+33});
161                 end;
162                 fprintf(1,'run \n  mex -setup\n  cd .../NaN/src\n  make \n');
163         end; 
164 else
165         fprintf(1,'NANINSTTEST %i not successful \n', find(~tmp));
166         fprintf(1,'The following functions contain a NaN-related bug:\n');
167         fprintf(1,'  - %s\n',funlist{find(~tmp)});
168         fprintf(1,'Its recommended to install the NaN-toolbox.\n');
169 end;
170
171 %warning(FLAG_WARNING);
172
173