ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CrossEntropy.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 = Y_t / Y
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 CrossEntropy::calculateErrorBackpropagation(const uint32_t flat_size,
30 const float *calculated_data,
31 const float *target_data, float *output_grad)
32{
33 for (uint32_t i = 0; i < flat_size; ++i)
34 {
35 output_grad[i] = -1.f * target_data[i] / (calculated_data[i] + float(10.0e-32));
36 }
37}
static void calculateErrorBackpropagation(const uint32_t flat_size, const float *calculated_data, const float *target_data, float *output_grad)