wolffd@0: function errstring = consist(model, type, inputs, outputs) wolffd@0: %CONSIST Check that arguments are consistent. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % ERRSTRING = CONSIST(NET, TYPE, INPUTS) takes a network data structure wolffd@0: % NET together with a string TYPE containing the correct network type, wolffd@0: % a matrix INPUTS of input vectors and checks that the data structure wolffd@0: % is consistent with the other arguments. An empty string is returned wolffd@0: % if there is no error, otherwise the string contains the relevant wolffd@0: % error message. If the TYPE string is empty, then any type of network wolffd@0: % is allowed. wolffd@0: % wolffd@0: % ERRSTRING = CONSIST(NET, TYPE) takes a network data structure NET wolffd@0: % together with a string TYPE containing the correct network type, and wolffd@0: % checks that the two types match. wolffd@0: % wolffd@0: % ERRSTRING = CONSIST(NET, TYPE, INPUTS, OUTPUTS) also checks that the wolffd@0: % network has the correct number of outputs, and that the number of wolffd@0: % patterns in the INPUTS and OUTPUTS is the same. The fields in NET wolffd@0: % that are used are wolffd@0: % type wolffd@0: % nin wolffd@0: % nout wolffd@0: % wolffd@0: % See also wolffd@0: % MLPFWD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Assume that all is OK as default wolffd@0: errstring = ''; wolffd@0: wolffd@0: % If type string is not empty wolffd@0: if ~isempty(type) wolffd@0: % First check that model has type field wolffd@0: if ~isfield(model, 'type') wolffd@0: errstring = 'Data structure does not contain type field'; wolffd@0: return wolffd@0: end wolffd@0: % Check that model has the correct type wolffd@0: s = model.type; wolffd@0: if ~strcmp(s, type) wolffd@0: errstring = ['Model type ''', s, ''' does not match expected type ''',... wolffd@0: type, '''']; wolffd@0: return wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % If inputs are present, check that they have correct dimension wolffd@0: if nargin > 2 wolffd@0: if ~isfield(model, 'nin') wolffd@0: errstring = 'Data structure does not contain nin field'; wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: data_nin = size(inputs, 2); wolffd@0: if model.nin ~= data_nin wolffd@0: errstring = ['Dimension of inputs ', num2str(data_nin), ... wolffd@0: ' does not match number of model inputs ', num2str(model.nin)]; wolffd@0: return wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % If outputs are present, check that they have correct dimension wolffd@0: if nargin > 3 wolffd@0: if ~isfield(model, 'nout') wolffd@0: errstring = 'Data structure does not conatin nout field'; wolffd@0: return wolffd@0: end wolffd@0: data_nout = size(outputs, 2); wolffd@0: if model.nout ~= data_nout wolffd@0: errstring = ['Dimension of outputs ', num2str(data_nout), ... wolffd@0: ' does not match number of model outputs ', num2str(model.nout)]; wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: % Also check that number of data points in inputs and outputs is the same wolffd@0: num_in = size(inputs, 1); wolffd@0: num_out = size(outputs, 1); wolffd@0: if num_in ~= num_out wolffd@0: errstring = ['Number of input patterns ', num2str(num_in), ... wolffd@0: ' does not match number of output patterns ', num2str(num_out)]; wolffd@0: return wolffd@0: end wolffd@0: end