ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSE.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
18
19using namespace onert_micro;
20using namespace onert_micro::train;
22
23/*
24 * dE/dY = (2 * (Y - Y_t)) / N
25 * where Y - vector of calculated outputs,
26 * Y_t - vector of target outputs
27 * Note: size of Y and Y_t should be the same and equal to flat_size
28 */
29void MSE::calculateErrorBackpropagation(const uint32_t flat_size, const float *calculated_data,
30 const float *target_data, float *output_grad)
31{
32 for (uint32_t i = 0; i < flat_size; ++i)
33 {
34 output_grad[i] = (2 * (calculated_data[i] - target_data[i])) / static_cast<float>(flat_size);
35 }
36}
static void calculateErrorBackpropagation(const uint32_t flat_size, const float *calculated_data, const float *target_data, float *output_grad)
Definition MSE.cpp:29