/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * 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: layer_dense.hpp * Revision: 0.1.0 * Date: 28-08-2026 * Author: Michelle Bausager * * Description: * Defines the dense layers used in neural network * *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #pragma once //--------------------------------------------------------------------------------------------------------------------------- // INCLUDE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- #include // panic::uint_t, panic::int_t, and panic::real_t #include // for base layer struct #include #include namespace panic{ namespace neural_network{ /** * @brief struct for dense layer object used in neural networks * * Computes: * @code * panic::neural_network::layer_dense myDenseLayer(3, 5); * myDenseLayer.forward(inputMatrix); * @endcode * * The struct is used in PANIC nural_network library. */ struct layer_dense : public layer{ /** * @brief Emphty matrix to store input data * */ panic::tensor::real_matrix ipnuts; /** * @brief Emphty weight matrix to store layer weights * * Weight shape: * input_size x neuron_count */ panic::tensor::real_matrix weights; panic::tensor::real_matrix dweights; /** * @brief Emphty bias vector to store layer bias * * Bias shape: * 1 x neuron_count */ panic::tensor::real_vector biases; panic::tensor::real_vector dbiases; /** * @brief Empthy constructor * */ layer_dense(); /** * @brief Constructor with input size and amount of neurons * * @param input_size Input size of data to the network. * @param neurons Amount of neurons in the layer * */ layer_dense(panic::types::uint_t input_size, panic::types::uint_t neurons); /** * @brief Default de-constructor * */ ~layer_dense() = 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& input_data); /** * @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& dvalues); }; } // namespace tensor } // namespace panic //--------------------------------------------------------------------------------------------------------------------------- // VARIABLE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- // FUNCTION PROTOTYPE //---------------------------------------------------------------------------------------------------------------------------