comparison toolboxes/FullBNT-1.0.7/netlab3.3/consist.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function errstring = consist(model, type, inputs, outputs)
2 %CONSIST Check that arguments are consistent.
3 %
4 % Description
5 %
6 % ERRSTRING = CONSIST(NET, TYPE, INPUTS) takes a network data structure
7 % NET together with a string TYPE containing the correct network type,
8 % a matrix INPUTS of input vectors and checks that the data structure
9 % is consistent with the other arguments. An empty string is returned
10 % if there is no error, otherwise the string contains the relevant
11 % error message. If the TYPE string is empty, then any type of network
12 % is allowed.
13 %
14 % ERRSTRING = CONSIST(NET, TYPE) takes a network data structure NET
15 % together with a string TYPE containing the correct network type, and
16 % checks that the two types match.
17 %
18 % ERRSTRING = CONSIST(NET, TYPE, INPUTS, OUTPUTS) also checks that the
19 % network has the correct number of outputs, and that the number of
20 % patterns in the INPUTS and OUTPUTS is the same. The fields in NET
21 % that are used are
22 % type
23 % nin
24 % nout
25 %
26 % See also
27 % MLPFWD
28 %
29
30 % Copyright (c) Ian T Nabney (1996-2001)
31
32 % Assume that all is OK as default
33 errstring = '';
34
35 % If type string is not empty
36 if ~isempty(type)
37 % First check that model has type field
38 if ~isfield(model, 'type')
39 errstring = 'Data structure does not contain type field';
40 return
41 end
42 % Check that model has the correct type
43 s = model.type;
44 if ~strcmp(s, type)
45 errstring = ['Model type ''', s, ''' does not match expected type ''',...
46 type, ''''];
47 return
48 end
49 end
50
51 % If inputs are present, check that they have correct dimension
52 if nargin > 2
53 if ~isfield(model, 'nin')
54 errstring = 'Data structure does not contain nin field';
55 return
56 end
57
58 data_nin = size(inputs, 2);
59 if model.nin ~= data_nin
60 errstring = ['Dimension of inputs ', num2str(data_nin), ...
61 ' does not match number of model inputs ', num2str(model.nin)];
62 return
63 end
64 end
65
66 % If outputs are present, check that they have correct dimension
67 if nargin > 3
68 if ~isfield(model, 'nout')
69 errstring = 'Data structure does not conatin nout field';
70 return
71 end
72 data_nout = size(outputs, 2);
73 if model.nout ~= data_nout
74 errstring = ['Dimension of outputs ', num2str(data_nout), ...
75 ' does not match number of model outputs ', num2str(model.nout)];
76 return
77 end
78
79 % Also check that number of data points in inputs and outputs is the same
80 num_in = size(inputs, 1);
81 num_out = size(outputs, 1);
82 if num_in ~= num_out
83 errstring = ['Number of input patterns ', num2str(num_in), ...
84 ' does not match number of output patterns ', num2str(num_out)];
85 return
86 end
87 end