annotate toolboxes/FullBNT-1.0.7/netlab3.3/consist.m @ 0:cc4b1211e677 tip

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