model.cpp/hpp

I made the model struct to store layers. I'm still missing the backward functions, but it's functional
This commit is contained in:
2026-07-28 19:36:26 +02:00
parent 441540a996
commit c7e87fe191
10 changed files with 552 additions and 107 deletions
+43 -31
View File
@@ -28,7 +28,7 @@
* Author: Michelle Bausager
*
* Description:
* Defines the base layers struct used in pther layers in neural network
* Defines the base layers struct used in other layers in neural network
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
@@ -38,38 +38,57 @@
#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{
/**
* @brief Base layer for the rest of the neural network library to use
*
* 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 derivative object NEEDS to have these functions to work.
*
* The struct is used for PANIC neural_network library.
*/
struct layer{
/**
* @brief Emphty output matrix to store layer output
*
* Output shape:
* samples x neuron_count
*/
panic::tensor::real_matrix outputs;
/**
* @brief Default de-constructor
*
*/
virtual ~layer() = default;
/**
* @brief Virtual forward function for derivative layers
*
* @param inputs Data matrix input for forward function.
*
* @Note It's equal to 0 because it make the derivative
* object NEEDS to have these function to work.
*/
virtual bool forward(const panic::tensor::real_matrix& inputs) = 0;
/**
* @brief Virtual backward function for derivative layers
*
* @param dinputs Data matrix input for backward function.
*
* @Note It's equal to 0 because it make the derivative
* object NEEDS to have these function to work.
*/
virtual bool backward(const panic::tensor::real_matrix& dinputs) = 0;
};
@@ -79,12 +98,5 @@ struct layer{
} // namespace tensor
} // namespace panic
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------