function metric = fScoreMetric(opts)
% fScoreMetric   Deep learning F-score metric
%
%   metric = fScoreMetric creates a F-score metric to use when training
%   a deep neural network.
%
%   metric = fScoreMetric(PARAM1=VAL1,PARAM2=VAL2,...) specifies optional
%   name-value arguments for creating the metric:
%
%       Name                 - Metric name, specified as a string scalar or
%                              char array.
%                              The default is "FScore".
%
%       NetworkOutput        - Name of output layer to apply the metric to,
%                              specified as [], a string scalar or a character 
%                              vector. When the value is [], the software 
%                              passes all of the network outputs to the metric.
%                              If the network has multiple outputs, then
%                              NetworkOutput must be set to the name of the
%                              network output to apply this metric to.
%                              The default is [].
%
%       AverageType          - Type of averaging to use to compute the 
%                              F-score, specified as:
%                             "micro"    - Calculate the F-score across all
%                                          classes. 
%                             "macro"    - Calculate the F-score for each 
%                                          class and return the average. 
%                             "weighted" - Calculate the F-score for each 
%                                          class and return the weighted 
%                                          average. The weight for each class
%                                          is the proportion of observations
%                                          from that class.
%                              The default value is "macro".
%
%       ClassificationMode   - Type of classification task, specified as
%                              one of the following:
%                             "single-label" - Each observation is 
%                                              exclusively assigned one 
%                                              class label.
%                             "multilabel"   - Each observation can be 
%                                              assigned more than one 
%                                              independent class label.
%                             The default value is "single-label".

%   Copyright 2022-2023 The MathWorks, Inc.
 
arguments
    opts.Name {deep.internal.util.validateName} = iDefaultName()
    opts.NetworkOutput {deep.internal.util.validateOneNetworkOutput} = iDefaultNetworkOutput()
    opts.AverageType {deep.internal.util.validateAverageType} = iDefaultAverageType()
    opts.ClassificationMode {deep.internal.util.validateClassificationMode} = iDefaultClassificationMode()
end

% Standardize values.
name = deep.internal.util.validateName(opts.Name);
networkOutput = deep.internal.util.validateOneNetworkOutput(opts.NetworkOutput);
averageType = deep.internal.util.validateAverageType(opts.AverageType);
classificationMode = deep.internal.util.validateClassificationMode(opts.ClassificationMode);

% Create a user-visible F-score metric.
metric = deep.metric.FScoreMetric(name, networkOutput, averageType, classificationMode);

end

function name = iDefaultName()
name = "FScore";
end

function name = iDefaultNetworkOutput()
name = [];
end

function val = iDefaultAverageType()
val = "macro";
end

function val = iDefaultClassificationMode()
val = "single-label";
end