function temp = templateKernel(varargin)
%TEMPLATEKERNEL Create a kernel model template.
%   T = TEMPLATEKERNEL() returns a kernel model template.
%
%   T = TEMPLATEKERNEL('PARAM1',val1,'PARAM2',val2,...) specifies optional
%   parameter name/value pairs:
%
%         'BetaTolerance'      - Relative tolerance on linear coefficients and
%                                bias term. A nonnegative scalar. Default
%                                is 1e-4. When using tall data default is
%                                relaxed to 1e-3.
%         'BlockSize'          - A positive scalar specifying the maximum amount of
%                                memory that can be allocated in megabytes(MB). If
%                                the solver requires more memory than this parameter
%                                to hold the transformed data, the internal
%                                algorithms will automatically switch to a
%                                block-wise strategy. Default is 4e3, i.e. 4GB.
%         'BoxConstraint'      - Positive scalar specifying the box constraint.
%                                Valid only for SVM learner and when Lambda is not
%                                given. Default is 1.
%         'GradientTolerance'  - Absolute gradient tolerance. A nonnegative scalar.
%                                Default is 1e-6. When using tall data default is
%                                relaxed to 1e-5.
%         'HessianHistorySize' - Size of history buffer for Hessian approximation.
%                                A positive integer. Default is 15.
%         'IterationLimit'     - Maximal number of optimization iterations. A
%                                positive integer. Default is 1000 if the transformed
%                                data fits in memory (see BlockSize), 100
%                                if the solver switches to a block-wise
%                                strategy, or 20 when using tall data.
%         'KernelScale'        - Either 'auto' or a positive scalar specifying the
%                                value for the scale parameter. If you pass 'auto',
%                                an appropriate scale factor is selected using a
%                                heuristic procedure. Default is 1.
%         'Lambda'             - Either 'auto' or a nonnegative scalar value
%                                specifying the strength of the regularization term.
%                                If 'auto', the regularization parameter is set to
%                                1/N, where N is the number of observations in X.
%                                Default: 'auto'
%         'Learner'            - Either 'svm' for a support vector machine or
%                                'logistic' for logistic regression. Default: 'svm'
%         'NumExpansionDimensions' - Number of dimensions in the expanded space.
%                                Either 'auto' or a positive integer. If you pass
%                                'auto', an appropriate number of dimensions is
%                                selected using a heuristic procedure.
%                                Default: 'auto'
%         'Standardize'        - Logical scalar. If true, then the software centers
%                                and scales each numeric predictor variable by the
%                                corresponding column mean and standard deviation.
%                                Default: false
%         'RandomStream'       - A random number stream to control reproducibility
%                                of the random basis functions used for
%                                transforming X to a high dimensional space.
%         'Verbose'            - Verbosity level, a nonnegative integer:
%                                 * 0  - the solver does not display any
%                                        diagnostic messages. (default)
%                                 * 1  - the solver periodically displays the
%                                        value of the objective function,
%                                        gradient magnitude, and other
%                                        diagnostic info. (default when
%                                        using tall data)
%         'Epsilon'            - Either 'auto' or a non-negative scalar specifying
%                                half the width of the epsilon-insensitive band.
%                                If 'auto', epsilon is set to iqr(Y)/13.49 or 0.1 if
%                                iqr(Y) equals 0. This argument is only valid for
%                                Type as 'regression'.Default is 'auto'.
%         'Type'              - String specifying the type of kernel model template.
%                               Specify as one of 'classification' or 'regression'.
%                               Default = []
%
%   See also ClassificationECOC, ClassificationKernel, fitcecoc,
%   fitckernel, fitrkernel, RegressionKernel.

%   Copyright 2018-2023 The MathWorks, Inc.

if nargin > 0
    [varargin{:}] = convertStringsToChars(varargin{:});
end

[type,learner,~,extra] = internal.stats.parseArgs({'type' 'learner'},{'' ''},varargin{:});

if ~isempty(type)
    type = validatestring(type,{'classification' 'regression'},...
        'templateKernel','Type');
end

if ~isempty(learner)
    learner = validatestring(learner,{'leastsquares' 'logistic' 'svm'},...
        'templateKernel','Learner');
else
    learner = 'svm';
end

if strncmpi(learner,'leastsquares',length(learner))
    if ~isempty(type) && strncmpi(type,'classification',length(type))
        error(message('stats:templateLinear:BadClassificationLearner'));
    end
    temp = RegressionKernel.template('Learner','leastsquares',extra{:});
elseif strncmpi(learner,'logistic',length(learner))
    if ~isempty(type) && strncmpi(type,'regression',length(type))
        error(message('stats:templateLinear:BadRegressionLearner'));
    end
    temp = ClassificationKernel.template('Learner','logistic',extra{:});
elseif strncmpi(learner,'svm',length(learner))
    temp = classreg.learning.FitTemplate.make('Kernel','Learner','svm','type',type,extra{:});
else
    error(message('stats:templateLinear:BadLearner'));
end

end
