%% Check Function Layer Validity
% Create a function layer object that applies the softsign operation to the input. The softsign operation is given by the function f\left(x\right)=\frac{x}{1+\left|x\right|}.

layer = functionLayer(@(X) X./(1 + abs(X)))

% Check that the layer it is valid using the checkLayer function. Set the valid input size to the typical size of a single observation input to the layer. For example, for a single input, the layer expects observations of size h-by-w-by-c, where h, w, and c are the height, width, and number of channels of the previous layer output, respectively.
% Specify validInputSize as the typical size of an input array.

validInputSize = [5 5 20];
checkLayer(layer,validInputSize)

% The results show the number of passed, failed, and skipped tests. If you do not specify the ObservationsDimension option, or do not have a GPU, then the function skips the corresponding tests.
%% Check Multiple Observations
% For multi-observation image input, the layer expects an array of observations of size h-by-w-by-c-by-N, where h, w, and c are the height, width, and number of channels, respectively, and N is the number of observations.
% To check the layer validity for multiple observations, specify the typical size of an observation and set the ObservationDimension option to 4.

layer = functionLayer(@(X) X./(1 + abs(X)));
validInputSize = [5 5 20];
checkLayer(layer,validInputSize,ObservationDimension=4)

% In this case, the function does not detect any issues with the layer.
% Copyright 2021 The MathWorks, Inc.