Half mean squared error
The half mean squared error operation computes the half mean squared error loss between network predictions and target values for regression tasks.
The loss is calculated using the following formula
where Xi is the network prediction, Ti is the target value, M is the total number of responses in X (across all observations), and N is the total number of observations in X.
Find Half Mean Squared Error Between Predicted and Target Values
The half mean squared error evaluates how well the network predictions correspond to the target values.
Create the input predictions as a single observation of random values with a height and width of six and a single channel.
height = 6; width = 6; channels = 1; observations = 1; Y = rand(height,width,channels,observations); dlY = dlarray(Y,'SSCB')
Create the target values as a numeric array with the same dimension order as the
targets = ones(height,width,channels,observations);
Compute the half mean squared error between the predictions and the targets.
loss = mse(dlY,targets)
loss = 1x1 dlarray 5.2061
dlY — Predictions
dlarray | numeric array
Predictions, specified as a formatted
dlarray, an unformatted
dlarray, or a numeric array. When
dlY is not a
dlarray, you must specify the dimension format using the
dlY is a numeric array,
targets must be a
targets — Target responses
dlarray | numeric array
Target responses, specified as a formatted or unformatted
dlarray or a
The size of each dimension of
targets must match the size of the corresponding dimension of
targets is a formatted
dlarray, then its format must
be the same as the format of
dlY, or the same as
targets is an unformatted
dlarray or a numeric array,
then the function applies the format of
dlY or the value of
dlarray objects automatically permute the dimensions of the
underlying data to have order
"T" (time), then
(unspecified). To ensure that the dimensions of
targets are consistent, when
dlY is a formatted
targets as a formatted
FMT — Dimension order of unformatted data
char array | string
Dimension order of unformatted input data, specified as the comma-separated pair
'DataFormat' and a character array or string
FMT that provides a label for each dimension of the data. Each
FMT must be one of the following:
'B'— Batch (for example, samples and observations)
'T'— Time (for example, sequences)
You can specify multiple dimensions labeled
'U'. You can use the labels
'T' at most once.
You must specify
'DataFormat',FMT when the input data is not a
loss — Half mean squared error loss
Half mean squared error loss, returned as an unformatted
scalar. The output
loss has the same underlying data type as the
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
When at least one of the following input arguments is a
dlarraywith underlying data of type
gpuArray, this function runs on the GPU:
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).