Activation Softmax Forward done

This commit is contained in:
2026-07-30 18:56:27 +02:00
parent e6e9fe1026
commit 70e80327ef
15 changed files with 2637 additions and 43 deletions
+32
View File
@@ -130,6 +130,23 @@
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) num_threads(PANIC_OMP_NUM_THREADS)))
// Expands to:
// #pragma omp parallel for if(condition)
// num_threads(PANIC_OMP_NUM_THREADS)
// schedule(static)
// reduction(operation:variable)
//
// Runs the loop in parallel only when condition is true.
// Each thread receives a private copy of variable.
// Afterward, OpenMP combines those copies using operation.
// schedule(static) assigns fixed groups of iterations to each thread.
#define PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(condition, operation, variable) \
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) \
num_threads(PANIC_OMP_NUM_THREADS) \
schedule(static) \
reduction(operation:variable)))
#else
// Expands to:
@@ -147,6 +164,21 @@
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition)))
// Expands to:
// #pragma omp parallel for if(condition)
// num_threads(PANIC_OMP_NUM_THREADS)
// schedule(static)
// reduction(operation:variable)
//
// Runs the loop in parallel only when condition is true.
// Each thread receives a private copy of variable.
// Afterward, OpenMP combines those copies using operation.
// schedule(static) assigns fixed groups of iterations to each thread.
#define PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(condition, operation, variable) \
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) \
schedule(static) \
reduction(operation:variable)))
#endif
#else
+306
View File
@@ -0,0 +1,306 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* 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: math
* File Name: div.hpp
* Revision: 0.1.0
* Date: 30-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to divide panic::tensor
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* @file mul.hpp
* @brief Public API for multiplying operations on PANIC vectors and matrices.
*
* This header contains the declarations that users of the math module should call.
* The comments here describe how each function is used, what dimensions are required,
* and what is returned on failure.
*
* Implementation details, OpenMP thresholds, and explicit template instantiations are
* kept in mul.cpp.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief Divides a scalar to every element of a vector.
*
* Computes:
* @code
* c[i] = a[i] / k
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value multiplied to each element of @p a.
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool div(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
/**
* @brief Returns a new vector containing a scalar divided to every element.
*
* Computes:
* @code
* result[i] = a[i] / k
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value miltiplied to each element of @p a.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const T k);
/**
* @brief Divide a vector elementwise too a vector.
*
* Computes:
* @code
* c[i] = a[i] / b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
/**
* @brief Returns a new vector containing a vector diveded elementwise.
*
* Computes:
* @code
* result[i] = a[i] / b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
* @param k Scalar value multiplied to each element of @p a.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
/**
* @brief Divides a scalar to every element of a matix.
*
* Computes:
* @code
* C(i,j) = A(i,j) / k
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value multiplied to each element of @p A.
* @param C Output Matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if resizing @p C failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool div(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a scalar diveded to every element.
*
* Computes:
* @code
* result(i,j) = A(i,j) / k
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value multiplied to each element of @p A.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const T k);
/**
* @brief Divides a matrix elementwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) / B(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A First matrix.
* @param B Second matrix. Must have size of @p A.
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a matrix divided elementwise.
*
* Computes:
* @code
* result(i,j) = A(i,j) / B(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param B Second matrix. Must have size of @p A.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
/**
* @brief Divides a vector rowwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) / b[j]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief Divides a vector rowwise too a matrix.
*
* Computes:
* @code
* result(i,j) = A(i,j) / b[j]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
/**
* @brief Divides a vector colwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) / b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief Divides a vector colwise too a matrix.
*
* Computes:
* @code
* result(i,j) = A(i,j) / b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
} // namespace math
} // namespace panic
+286
View File
@@ -0,0 +1,286 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* 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: math
* File Name: sub.hpp
* Revision: 0.1.0
* Date: 25-06-2026
* Author: Michelle Bausager
*
* Description:
* Functions to subtracts panic::tensor togther;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief Subs a scalar to every element of a vector.
*
* Computes:
* @code
* c[i] = a[i] - k
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value added to each element of @p a.
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool sub(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
/**
* @brief Returns a new vector containing a scalar subtraced to every element.
*
* Computes:
* @code
* result[i] = a[i] - k
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value subtracted to each element of @p a.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const T k);
/**
* @brief subtracts a vector elementwise too a vector.
*
* Computes:
* @code
* c[i] = a[i] - b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
/**
* @brief Returns a new vector containing a vector subtracted elementwise.
*
* Computes:
* @code
* result[i] = a[i] - b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
* @param k Scalar value subtracted to each element of @p a.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
/**
* @brief subtracts a scalar to every element of a matix.
*
* Computes:
* @code
* C(i,j) = A(i,j) - k
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value added to each element of @p A.
* @param C Output Matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if resizing @p C failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool sub(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a scalar subtracted to every element.
*
* Computes:
* @code
* result(i,j) = A(i,j) - k
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value subtracted to each element of @p A.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const T k);
/**
* @brief subtracts a matrix elementwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) - B(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A First matrix.
* @param B Second matrix. Must have size of @p A.
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a matrix subtracted elementwise.
*
* Computes:
* @code
* result(i,j) = A(i,j) - B(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param B Second matrix. Must have size of @p A.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
/**
* @brief subtracts a vector rowwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) - b[j]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief subtracts a vector rowwise too a matrix.
*
* Computes:
* @code
* result(i,j) = A(i,j) - b[j]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
/**
* @brief subtracts a vector colwise too a matrix.
*
* Computes:
* @code
* C(i,j) = A(i,j) - b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief subtracts a vector colwise too a matrix.
*
* Computes:
* @code
* result(i,j) = A(i,j) - b[i]
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
} // namespace math
} // namespace panic
+158
View File
@@ -0,0 +1,158 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: math
* File Name: sum.hpp
* Revision: 0.1.0
* Date: 25-06-2026
* Author: Michelle Bausager
*
* Description:
* Functions to sum up arrays
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief Returns the sum value of a vector
*
* Computes:
* @code
* result = sum(a)
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
T sum(const panic::tensor::vector<T>& a);
/**
* @brief Returns the sum value of a matrix.
*
* Computes:
* @code
* result = sum(A)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
*/
template <typename T>
T sum(const panic::tensor::matrix<T>& A);
/**
* @brief Find the sum values row-wise of a matrix.
*
* Computes:
* @code
* c(i) = sum(A(i,j))
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param c Output vector. Resized to match @p A.cols().
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sum_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
/**
* @brief Returns a new matrix containing the sum row-wise elementwise.
*
* Computes:
* @code
* result[i] = sum(A(i,j))
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> sum_rowwise(const panic::tensor::matrix<T>& A);
/**
* @brief Find the sumation values column-wise of a matrix.
*
* Computes:
* @code
* C(j) = sum(A(i,j))
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param C Output matrix. Resized to match @p A.rows().
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool sum_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
/**
* @brief Returns a new matrix containing the sumation column-wise elementwise.
*
* Computes:
* @code
* result[j] = sum(A(i,j))
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> sum_colwise(const panic::tensor::matrix<T>& A);
} // namespace math
} // namespace panic
@@ -22,7 +22,7 @@
*
* Project Name: PANIC
* Module Name: neural_network
* File Name: activation_ReLU.hpp
* File Name: activation_relu.hpp
* Revision: 0.1.0
* Date: 29-08-2026
* Author: Michelle Bausager
@@ -56,19 +56,19 @@ namespace panic{
*
* The struct is used in PANIC nural_network library.
*/
struct activation_ReLU : public layer{
struct activation_relu : public layer{
/**
* @brief Empthy constructor
*
*/
activation_ReLU();
activation_relu();
/**
* @brief Default de-constructor
*
*/
~activation_ReLU() = default;
~activation_relu() = default;
/**
* @brief Forward function for layer
@@ -0,0 +1,94 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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.hpp
* Revision: 0.1.0
* Date: 29-08-2026
* Author: Michelle Bausager
*
* Description:
* Defines the activation layer for Softmax
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <neural_network/layer/layer.hpp> // for base layer struct
#include <tensor/matrix.hpp>
namespace panic{
namespace neural_network{
/**
* @brief struct for softmax activation layer used in neural networks
*
* Computes:
* @code
* panic::neural_network::activation_softmax myactivation();
* myactivation.forward(inputMatrix);
* @endcode
*
* The struct is used in PANIC nural_network library.
*/
struct activation_softmax : public layer{
/**
* @brief Empthy constructor
*
*/
activation_softmax();
/**
* @brief Default de-constructor
*
*/
~activation_softmax() = default;
/**
* @brief Forward function for layer
*
* @param inputs Data input for forward pass.
*
* @Note Calculates -> outputs = inputs * weights + biases
*/
bool forward(const panic::tensor::real_matrix& inputs);
/**
* @brief Backward function for layer
*
* @param inputs Data input for bacward pass.
*
* @Note Calculates derivative of forward function.
*/
bool backward(const panic::tensor::real_matrix& dinpus);
};
} // namespace tensor
} // namespace panic
+18 -2
View File
@@ -143,7 +143,7 @@ struct model{
*
* Computes:
* @code
* model.add_activation_ReLU(3,4);
* model.add_activation_relu(3,4);
* @endcode
*
*
@@ -151,7 +151,23 @@ struct model{
*
* @note This function is convenient, but it allocates a new layer.
*/
bool add_activation_ReLU();
bool add_activation_relu();
/**
* @brief Adds a activation Softmax layer to the model.
*
* Computes:
* @code
* model.add_activation_softmax(3,4);
* @endcode
*
*
* @return true if layer is added
*
* @note This function is convenient, but it allocates a new layer.
*/
bool add_activation_softmax();
/**
* @brief Loops over all layers forward function