function obj = fitcnet(X,Y,varargin)
% FITCNET Fit a classification neural network.
% fitcnet creates a fully connected, feedforward neural network for classification.
%
% Mdl = FITCNET(Tbl,ResponseVarName) returns a neural network classification
% model Mdl trained using the predictors in the table Tbl and the class labels
% in the ResponseVarName table variable.
%
% Mdl = FITCNET(Tbl,formula) returns a neural network classification model trained
% using the sample data in the table Tbl. The input argument formula is an explanatory
% model of the response and a subset of the predictor variables in Tbl used to fit Mdl.
%
% Mdl = FITCNET(Tbl,Y) returns a neural network classification model using the predictor
% variables in the table Tbl and the class labels in vector Y.
%
% Mdl = FITCNET(X,Y) returns a neural network classification model trained using
% the predictors in the matrix X and the class labels in vector Y.
%
% Mdl = FITCNET(___,Name,Value) specifies options using one or more name-value
% arguments in addition to any of the input argument combinations in previous syntaxes.
% For example, you can adjust the size of the fully connected layers and the activation functions
% for the fully connected layers by specifying the "LayerSizes" and "Activations"
% name-value arguments. By default, Mdl is a ClassificationNeuralNetwork object.
% If you set any of the cross-validation name-value arguments, then Mdl is a
% ClassificationPartitionedModel object.
%
% Neural network name-value arguments include:
%
%   "LayerSizes" – Sizes of fully connected layers
%   10 (default) | positive integer vector
%
%   "Activations" – Activation functions for fully connected layers
%   "relu" (default) | "tanh" | "sigmoid" | "none" | string array | cell array of character vectors
%
%   "LayerWeightsInitializer" – Function to initialize fully connected layer weights
%   "glorot" (default) | "he"
%
%   "LayerBiasesInitializer" – Type of initial fully connected layer biases
%   "zeros" (default) | "ones"
%
%   "ObservationsIn" – Predictor data observation dimension
%   "rows" (default) | "columns"
%
%   "Lambda" – Regularization term strength
%   0 (default) | nonnegative scalar
%
%   "Standardize" – Flag to standardize predictor data
%   false or 0 (default) | true or 1
%
% Convergence control name-value arguments include:
%
%   "Verbose" – Verbosity level
%   0 (default) | 1
%
%   "VerboseFrequency" – Frequency of verbose printing
%   1 (default) | nonnegative scalar
%
%   "StoreHistory" – Flag to store optimization history
%   true or 1 (default) | false or 0
%
%   "IterationLimit" – Maximum number of optimization iterations
%   1e3 (default) | positive integer scalar
%
%   "GradientTolerance" – Relative gradient tolerance
%   1e-6 (default) | nonnegative scalar
%
%   "LossTolerance" – Loss tolerance
%   1e-6 (default) | nonnegative scalar
%
%   "InitialStepSize" – Initial step size
%   [] (default) | nonnegative scalar | "auto"
%
%   "StepTolerance" – Step size tolerance
%   1e-6 (default) | nonnegative scalar
%
%   "ValidationData" – Validation data for training convergence detection
%   cell array | table
%
%   "ValidationFrequency" – Number of iterations between validation evaluations
%   1 (default) | positive integer scalar
%
%   "ValidationPatience" – Stopping condition for validation evaluations
%   6 (default) | nonnegative scalar | Inf
%
% Other classification name-value arguments include:
%
%   "CategoricalPredictors" – Categorical predictors list
%   vector of positive integers | logical vector | character matrix | string array | cell array of character vectors | "all"
%
%   "ClassNames" – Names of classes to use for training
%   categorical array | character array | string array | logical vector | numeric vector | cell array of character vectors
%
%   "Cost" – Misclassification cost
%   square matrix | structure array
%
%   "PredictorNames" – Predictor variable names
%   string array of unique names | cell array of unique character vectors
%
%   "Prior" – Prior probabilities
%   "empirical" (default) | "uniform" | numeric vector | structure array
%
%   "ResponseName" – Response variable name
%   "Y" (default) | character vector | string scalar
%
%   "ScoreTransform" – Score transformation
%   "none" (default) | "doublelogit" | "invlogit" | "ismax" | "logit" | function handle …
%
%   "Weights" – Observation weights
%   positive numeric vector | names of variable in Tbl
%
% Cross-validation name-value arguments include:
%
%   "CrossVal" – Flag to train cross-validated classifier
%   "off" (default) | "on"
%
%   "CVPartition" – Cross-validation partition
%   [] (default) | cvpartition partition object
%
%   "Holdout" – Fraction of data for holdout validation
%   scalar value in the range (0,1)
%
%   "KFold" – Number of folds
%   10 (default) | positive integer value greater than 1
%
%   "Leaveout" – Leave-one-out cross-validation flag
%   "off" (default) | "on"
%
% Hyperparameter optimization name-value arguments include:
%
%   "OptimizeHyperparameters" – Parameters to optimize
%   "none" (default) | "auto" | "all" | string array or cell array of eligible parameter names | …
%
%   "HyperparameterOptimizationOptions" - Options for optimization
%   structure
%
% Example: Create a neural network classifier using the Fisher iris data set, and compare the true and predicted species in a confusion matrix.
%       Tbl = readtable("fisheriris.csv");
%       Mdl = fitcnet(Tbl,"Species");
%       confusionchart(Tbl.Species,predict(Mdl,Tbl))
%
% See also ClassificationNeuralNetwork, classreg.learning.partition.ClassificationPartitionedModel.

%   Copyright 2020-2021 The MathWorks, Inc.

if nargin > 1
    Y = convertStringsToChars(Y);
end

if nargin > 2
    [varargin{:}] = convertContainedStringsToChars(varargin{:});
end

[IsOptimizing, RemainingArgs] = classreg.learning.paramoptim.parseOptimizationArgs(varargin);
if IsOptimizing
    obj = classreg.learning.paramoptim.fitoptimizing("fitcnet",X,Y,varargin{:});
else
    obj = ClassificationNeuralNetwork.fit(X,Y,RemainingArgs{:});
end
end