function layer = instantiateFromString(activation)
% instantiateFromString - creates an activation layer from string
%
% Syntax:
%    layer = nnActivationLayer.instantiateFromString(activation)
%
% Inputs:
%    activation - string, one of {'relu','sigmoid','tanh', 'softmax', 
%       'identity', 'none', 'sqrt'}
%
% Outputs:
%    layer - nnActivationLayer
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: nnLayer

% Authors:       Tobias Ladner
% Written:       24-June-2022
% Last update:   02-November-2022 (lower)
%                29-November-2022 (switch, softmax)
%                30-November-2022 (none, identity)
% Last revision: ---

% ------------------------------ BEGIN CODE -------------------------------

% check input arguments
activation = lower(activation);
possibleActivations = {'relu','sigmoid','tanh','softmax', 'identity', 'none','invsqrtroot','sqrt','sin','cos'};
inputArgsCheck({{activation,'str', possibleActivations}});

switch activation
    % main activation function
    case "relu"
        layer = nnReLULayer();
    case "sigmoid"
        layer = nnSigmoidLayer();
    case "tanh"
        layer = nnTanhLayer();
        % special activation functions
    case "softmax"
        layer = nnSoftmaxLayer();
    case {"identity", "none"}
        layer = nnIdentityLayer();
    case "invsqrtroot"
        layer = nnInvSqrtRootLayer();
    case "sqrt"
        layer = nnRootLayer();
        % layers from handle
    case "sin"
        layer = nnActLayerFromHandle(@sin);
    case "cos"
        layer = nnActLayerFromHandle(@cos);
    otherwise
        % should not be executed anyway due to inputArgsCheck. 
        throw(CORAerror('CORA:wrongValue', 'first', ...
            strjoin(possibleActivations, ', ')));
end

end

% ------------------------------ END OF CODE ------------------------------
