ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
17#include "train/metrics/MSE.h"
18
19#include <cmath>
20#include <cassert>
21
22using namespace onert_micro;
23using namespace onert_micro::train;
24using namespace onert_micro::train::metrics;
25
26/*
27 * E(Y, Y_t) = (SUM(Y_i - Y_t_i)^2) / N
28 * SUM - sum among i = (0 ... N - 1)
29 */
30float MSE::calculateValue(const uint32_t flat_size, const float *calculated_data,
31 const float *target_data)
32{
33 float result_value = 0.f;
34
35 for (uint32_t i = 0; i < flat_size; ++i)
36 {
37 const auto cur_val = calculated_data[i] - target_data[i];
38 result_value += cur_val * cur_val;
39 }
40
41 assert(flat_size != 0);
42
43 return result_value / static_cast<float>(flat_size);
44}
static float calculateValue(const uint32_t flat_size, const float *calculated_data, const float *target_data)
Definition MSE.cpp:30