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