function obj = fitrnet(X,Y,varargin)
% FITRNET Fit a regression neural network.
% fitrnet creates a fully connected, feedforward neural network for regression.
%
% Mdl = FITRNET(Tbl,ResponseVarName) returns a neural network regression model 
% Mdl trained using the predictors in the table Tbl and the response values in 
% the ResponseVarName table variable.
%
% Mdl = FITRNET(Tbl,formula) returns a neural network regression 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 = FITRNET(Tbl,Y) returns a neural network regression model using the predictor
% variables in the table Tbl and the response values in vector Y.
%
% Mdl = FITRNET(X,Y) returns a neural network regression model trained using the 
% predictors in the matrix X and the response values in vector Y.
%
% Mdl = FITRNET(___,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 RegressionNeuralNetwork object. If you set any of the 
% cross-validation name-value arguments, then Mdl is a RegressionPartitionedModel 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 optimization 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 regression name-value arguments include:
% 
%   "CategoricalPredictors" – Categorical predictors list
%   vector of positive integers | logical vector | character matrix | string array | cell array of character vectors | "all"
% 
%   "PredictorNames" – Predictor variable names
%   string array of unique names | cell array of unique character vectors
% 
%   "ResponseName" – Response variable name
%   "Y" (default) | character vector | string scalar
% 
%   "Weights" – Observation weights
%   positive numeric vector | names of variable in Tbl
% 
% Cross-validation name-value arguments include:
% 
%   "CrossVal" – Flag to train cross-validated regression model
%   "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: Train a regression neural network model using sample data.
%         rng("default")
%         n = 1000;
%         x = linspace(-10,10,n)';
%         y = 1 + x*5e-2 + sin(x)./x + 0.2*randn(n,1);
%         Mdl = fitrnet(x,y);
% 
% See also RegressionNeuralNetwork, classreg.learning.partition.RegressionPartitionedModel.

%   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("fitrnet",X,Y,varargin{:});
else
    obj = RegressionNeuralNetwork.fit(X,Y,RemainingArgs{:});
end
end
