94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
*
|
|
* PANIC
|
|
* Portable Algorithms and Numerics In C++
|
|
*
|
|
* Scientific computing from scratch, with feeling.
|
|
*
|
|
* Copyright (c) 2026 Michelle Bausager
|
|
*
|
|
* This file is part of PANIC.
|
|
*
|
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
|
* You may redistribute and/or modify it under the terms of the GPL.
|
|
*
|
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the LICENSE file for the full license text.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
*
|
|
* Project Name: PANIC
|
|
* Module Name: neural_network
|
|
* File Name: loss_categorical_crossentropy.hpp
|
|
* Revision: 0.1.0
|
|
* Date: 30-07-2026
|
|
* Author: Michelle Bausager
|
|
*
|
|
* Description:
|
|
* Defines the base loss_categorical_crossentropy used in neural network
|
|
*
|
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
#pragma once
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// INCLUDE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
#include <neural_network/loss/loss.hpp>
|
|
#include <config/omp.hpp>
|
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
|
#include <tensor/vector.hpp>
|
|
|
|
|
|
namespace panic{
|
|
namespace neural_network{
|
|
|
|
|
|
|
|
/**
|
|
* @brief loss_categorical_crossentropy used in the rest of the neural network library
|
|
*
|
|
*
|
|
* The struct is used for PANIC neural_network library.
|
|
*/
|
|
struct loss_categorical_crossentropy: loss{
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @brief forward function to calculate losses
|
|
*
|
|
* @param y_pred Matrix of model predection.
|
|
* @param y_true Vector of true label of data.
|
|
*
|
|
*/
|
|
bool forward(
|
|
const panic::tensor::real_matrix& y_pred,
|
|
const panic::tensor::uint_vector& y_true);
|
|
|
|
/**
|
|
* @brief forward function to calculate losses
|
|
*
|
|
* @param y_pred Matrix of model predection.
|
|
* @param y_true Vector of true label of data.
|
|
*
|
|
* @Note Overloaded if one-shot endcoded
|
|
* is used.
|
|
*/
|
|
bool forward(
|
|
const panic::tensor::real_matrix& y_pred,
|
|
const panic::tensor::real_matrix& y_true);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace neural_network
|
|
} // namespace panic
|
|
|
|
|
|
|