function [mdl,isAnomaly,score] = ocsvm(X,varargin)
%OCSVM Fit one-class Support Vector Machine (SVM).
%   MDL = OCSVM(TBL) returns a one-class SVM model for data in the table
%   TBL. TBL contains the predictor variables. MDL is an object of class
%   OneClassSVM.
%
%   MDL = OCSVM(X) is an alternative syntax that accepts X as an N-by-P
%   matrix of predictors with one row per observation and one column per
%   predictor.
%
%   [MDL,ISANOM] = OCSVM(...) also returns logical array ISANOM with N
%   elements using any of the input arguments in the previous syntaxes. The
%   Jth element of this array is true if the Jth observation (row) in TBL
%   or X is an anomaly.
%
%   [MDL,ISANOM,SCORES] = OCSVM(...) also returns numeric array SCORES of
%   anomaly scores with N elements. The values in this array are between
%   -Inf and +Inf. Large negative value indicates a normal observation, and
%   large positive value indicates an anomaly. OCSVM returns NaN scores for
%   observations with missing data. Observations with NaN scores are not
%   treated as anomalies.
%
%   MDL = OCSVM(...,Name=Value) specifies optional parameter name-value
%   arguments:
%       BetaTolerance  - Relative tolerance on linear coefficients and
%                        bias term. A nonnegative scalar. Default is 1e-4.
%       BlockSize      - A positive scalar specifying the maximum amount
%                        of memory that can be allocated in megabytes
%                        (MB). If OCSVM requires more memory than this
%                        parameter to hold the transformed data, the
%                        internal algorithms will automatically switch to
%                        a block-wise strategy. Default: 4e3, i.e. 4 GB.
%       CategoricalPredictors - List of categorical predictors. Pass
%                        CategoricalPredictors as one of:
%                          * A numeric vector with indices between 1 and P,
%                            where P is the number of predictor variables.
%                          * A logical vector of length P, where a true
%                            entry means that the corresponding predictor
%                            is a categorical variable.
%                          * 'all', meaning all predictors are categorical.
%                          * A string array or cell array of character
%                            vectors, where each element in the array is
%                            the name of a predictor variable. The names
%                            must match entries in PredictorNames values
%                            for matrix X or names in table TBL.
%                        Default: for a matrix input X, no categorical
%                        predictors; for a table TBL, predictors are
%                        treated as categorical if they are strings, cell
%                        arrays of character vectors, logical, or unordered
%                        of type 'categorical'.
%                          NOTE: OCSVM creates dummy variables for
%                                categorical predictors by expanding each
%                                categorical predictor into a set of binary
%                                predictors. The process is different for
%                                unordered and ordered categorical
%                                predictors in the table TBL. For the
%                                matrix X, OCSVM treats categorical
%                                predictors as unordered. For details, see
%                                the reference page of OCSVM.
%       ContaminationFraction - Fraction of anomalies in the data, single
%                        or double scalar between 0 and 1. Default: 0
%       GradientTolerance - Absolute gradient tolerance. A nonnegative
%                        scalar. Default: 1e-6
%       IterationLimit - Maximal number of optimization iterations. A
%                        positive integer. Default is 1000 if the transformed
%                        data fits in memory (see BlockSize) and 100
%                        otherwise.
%       KernelScale    - Either string 'auto' or positive scalar specifying
%                        the value for the scale parameter. If you pass
%                        'auto', OCSVM selects an appropriate scale using a
%                        heuristic procedure. Default: 1
%       Lambda         - Either 'auto' or a nonnegative scalar value
%                        specifying the strength of the regularization
%                        term. If 'auto', OCSVM selects an appropriate
%                        regularization parameter using a heuristic
%                        procedure. Default: 'auto'
%       NumExpansionDimensions - Number of dimensions in the expanded
%                        space. Either 'auto' or a positive integer. If you
%                        pass 'auto', OCSVM selects an appropriate number
%                        using a heuristic procedure.  Default: 'auto'
%       PredictorNames - A string/cell array of names for the predictor
%                        variables, in the order in which they appear in X.
%                        Default: {'x1','x2',...}. For a table TBL, these
%                        names must be a subset of the variable names in
%                        TBL, and only the selected variables are used.
%                        Default: all variables
%       RandomStream   - A random number stream to control reproducibility
%                        of the random basis functions used for
%                        transforming TBL or X to a high dimensional space.
%       StandardizeData - Logical scalar. If true, standardize numeric
%                        predictors in TBL or X by centering and dividing
%                        the respective columns by their standard
%                        deviations. Default: false
%       Verbose        - Verbosity level, a nonnegative integer:
%                          * 0  - OCSVM does not display any diagnostic
%                                 messages. (default)
%                          * 1  - OCSVM periodically displays the value of
%                                 the objective function, gradient
%                                 magnitude, and other diagnostic info.

%   Copyright 2022 The MathWorks, Inc.

internal.stats.checkNotTall(upper(mfilename),0,X,varargin{:});

[varargin{:}] = convertStringsToChars(varargin{:});
[mdl,isAnomaly,score] = OneClassSVM.fitandscore(X,varargin{:});

end

% LocalWords:  ISANOM
