I've created the optimizer class
This commit is contained in:
2026-08-04 18:55:30 +02:00
parent 11da534fd6
commit b52c128496
15 changed files with 1207 additions and 48 deletions
@@ -0,0 +1,216 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: activation_softmax_loss_categorical_crossentropy.Hpp
* Revision: 0.1.0
* Date: 28-07-2026
* Author: Michelle Bausager
*
* Description:
* Defines the combined activation function softmax and
* categorical crossentropy loss used in neural network
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <tensor/vector.hpp>
#include <tensor/matrix.hpp>
#include <neural_network/activation/activation_softmax.hpp>
#include <neural_network/loss/loss_categorical_crossentropy.hpp>
namespace panic{
namespace neural_network{
/**
* @brief struct for activation_softmax_loss_categorical_crossentropy object used in neural networks
*
*
* The struct is used in PANIC nural_network library.
*/
struct activation_softmax_loss_categorical_crossentropy: loss{
activation_softmax activation;
loss_categorical_crossentropy loss;
/**
* @brief Emphty matrix to store input data for bacward pass
*
*/
panic::tensor::real_matrix dinputs;
/**
* @brief Emphty matrix to store output data
*
*/
panic::tensor::real_matrix outputs;
/**
* @brief Empthy constructor
*
*/
activation_softmax_loss_categorical_crossentropy();
/**
* @brief Default de-constructor
*
*/
~activation_softmax_loss_categorical_crossentropy() = default;
/**
* @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);
/**
* @brief forward function to calculate losses
*
* @param y_pred Matrix of model predection.
* @param y_true Vector of true label of data.
*
*/
bool calculate(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 calculate(const panic::tensor::real_matrix& y_pred, const panic::tensor::real_matrix& y_true);
/**
* @brief backward function to calculate from losses
*
* @param y_pred Matrix of model predection.
* @param y_true Vector of true label of data.
*
*/
bool backward(const panic::tensor::real_matrix& dvalues, const panic::tensor::uint_vector& y_true);
/**
* @brief backward function to calculate from 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 backward(const panic::tensor::real_matrix& dvalues, const panic::tensor::real_matrix& y_true);
};
} // namespace tensor
} // namespace panic
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------