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