classdef (CaseInsensitiveProperties, TruncatedProperties) neuralnet <...
      idFeedforwardNetwork & idobsolete.idnlfun
   %NEURALNET Create a Neural Network nonlinearity estimator object.
   % neuralnet is deprecated. Use idFeedforwardNetwork instead.

   %   (Requires Deep Learning Toolbox(TM))
   %
   %  Usage:
   %   N = NEURALNET(NET)
   %   creates a NEURALNET object using the NETWORK object NET. NETWORK
   %   object is created by functions in Deep Learning Toolbox, such as
   %   FEEDFORWARDNET, CASCADEFORWARDNET and LINEARLAYER.
   %
   %   A NEURALNET object functions as a type of nonlinearity estimator for
   %   Nonlinear ARX models. This object facilitates use of networks
   %   created using Deep Learning Toolbox(TM) in Nonlinear ARX models of
   %   System Identification Toolbox(TM).
   %
   %  Example:
   %   Create a feed-forward (shallow) network using 3 hidden layers
   %   employing 4, 6 and 1 neurons respectively. The transfer functions
   %   for the neurons in the three hidden layers are of type 'logsig'
   %   'radbas' and 'purelin' respectively (the output layer will use the
   %   default transfer function - 'purelin'):
   %
   %     NET = FEEDFORWARDNET([4 6 1]);
   %     NET.layers{1}.transferFcn = 'logsig';
   %     NET.layers{2}.transferFcn = 'radbas';
   %     NET.layers{3}.transferFcn = 'purelin';
   %     VIEW(NET) % view network structure
   %
   %   Use the NETWORK object NET to create a NEURALNET object:
   %   N = NEURALNET(NET);
   %
   %   In this example, NET is a 3-hidden layer feed forward neural network
   %   with uninitialized input and output sizes (= 0). The correct
   %   sizes/ranges are automatically assigned to the network when a
   %   Nonlinear ARX model using neuralnet object N as its nonlinearity
   %   estimator is estimated. Leaving the sizes at their default values is
   %   the recommended approach. Alternatively, you can initialize the
   %   sizes manually by setting input range
   %   (NET.outputs{NET.outputConnect}.range) and output range
   %   (NET.inputs{1}.range) to m-by-2 and 1-by-2 matrices respectively,
   %   where m is number of model regressors and the range values are
   %   minimum and maximum values of regressors and output data
   %   respectively (use GETREG to generate the matrix of regressors from
   %   input-output data for a given Nonlinear ARX model).
   %
   %   The neuralnet object N implements a mapping from row vectors of
   %   dimension m to scalar reals. The value of the function is computed
   %   by evaluate(N,x), where x is the regressor matrix (Nr rows).
   %   NEURALNET can be used as a type of nonlinearity estimator for
   %   Nonlinear ARX (IDNLARX) models. Example:
   %
   %     load twotankdata
   %     Data = iddata(y,u,0.2);
   %     NET =  cascadeforwardnet(20); % single hidden layer cascade-forward network
   %     N = neuralnet(NET);
   %     Model = nlarx(Data,[2 2 1],N); % create Nonlinear ARX model to fit Data
   %     compare(Data, Model) % compare model response to measured output signal
   %
   % See also NETWORK, NLARX, NLHW, TRAIN, EVALUATE, GETREG,
   % FEEDFORWARDNET, CASCADEFORWARDNET, LINEARLAYER, TREEPARTITION,
   % WAVENET, SIGMOIDNET, CUSTOMNET.

   % Copyright 2006-2022 The MathWorks, Inc.

   % Author(s): Qinghua Zhang
   %   Technology created in collaboration with INRIA and University Joseph
   %   Fourier of Grenoble - FRANCE

   methods
      function this = neuralnet(varargin)
         % Constructor.
         warning(message('Ident:general:obsoleteClass','neuralnet','idFeedforwardNetwork'))
         this = this@idFeedforwardNetwork(varargin{:});
      end

      function [Props,AsgnVals] = pnames(~, flag)
         %PNAMES  All NEURALNET public properties and their assignable
         %values.
         no = nargout;
         ni = nargin;
         readonlyflag = false;
         if ni>1 && ischar(flag)
            if strcmpi(flag, 'readonly')
               readonlyflag = true;
            else
               error(message('Ident:general:wrongPnamesFlag'))
            end
         end

         if readonlyflag
            Props = {};
         else
            Props = {'Network'};
         end

         if no>1
            if readonlyflag
               AsgnVals = {};
            else
               AsgnVals = {getString(message('Ident:idnlmodel:neuralnetDescr'))};
            end
         end
      end
   end

   methods (Static, Hidden)
      function sys = loadobj(s)
         %LOADOBJ Load filter for NEURALNET objects. STATIC METHOD.

         % R2021a (ver 23): loadobj first introduced
         % R2021b (ver 24): replaced with idFeedforwardNetwork

         if isstruct(s)
            updatewarn
            Warn = ctrlMsgUtils.SuspendWarnings; %#ok<NASGU>
         end

         v = nlident.internal.FcnIO.utGetVersion(s);
         if isstruct(s)
            if v<23
               nu = size(s.RegressorRange,2);
               sys = initializeIOs(neuralnet(s.prvNetwork),"u"+(1:nu),"y");
               sys.Initialized = s.Initialized;
               sys.Input.Range = s.RegressorRange;
               sys.Input.Mean = zeros(1,size(s.RegressorRange,2));
               sys.Output.Range = [-Inf;Inf];
               sys.Output.Mean = 0;
               %sys.NonlinearRegressors = s.NonlinearRegressors; % no need; "all" are used
               sys.Utility = s.Utility;
            else
               sys = reload(neuralnet(s.prvNonlinearFcn),s,v);
            end
         else
            sys = s;
         end
      end
   end

end %class

