added the dense layer with a forward functions. I also made the add functions for most cases.
91 lines
3.8 KiB
C++
91 lines
3.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: layer.hpp
|
|
* Revision: 0.1.0
|
|
* Date: 23-06-2026
|
|
* Author: Michelle Bausager
|
|
*
|
|
* Description:
|
|
* Defines the base layers struct used in pther layers in neural network
|
|
*
|
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
#pragma once
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// INCLUDE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
#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)
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// DEFINE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// TYPE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// Type Name : panic::neural_network::layer
|
|
//
|
|
// Description:
|
|
// A base layer to use in neural networks
|
|
//
|
|
// Member Variables:
|
|
// None.
|
|
//
|
|
// Notes:
|
|
// This base layer should be used in all layers/activations that have a forward and backward function
|
|
// This is done so it's easy to make a list of layers in the model to loop over.
|
|
// The virtual means it should use derived object's version when called with a pointer.
|
|
// The =0 means the derviced object NEEDS to have these functions to work.
|
|
//
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
namespace panic{
|
|
namespace neural_network{
|
|
|
|
struct layer{
|
|
|
|
virtual ~layer() = default;
|
|
|
|
virtual bool forward(const panic::tensor::real_matrix& inputs) = 0;
|
|
virtual bool backward(const panic::tensor::real_matrix& dinputs) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tensor
|
|
} // namespace panic
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// VARIABLE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// FUNCTION PROTOTYPE
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|