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:
@@ -24,7 +24,7 @@
|
||||
* Module Name: neural_network
|
||||
* File Name: layer_dense.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 23-06-2026
|
||||
* Date: 28-08-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
@@ -41,59 +41,76 @@
|
||||
#include <tensor/vector.hpp>
|
||||
#include <tensor/matrix.hpp>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// DEFINE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// TYPE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Function Name : panic::neural_network::layer_dense
|
||||
//
|
||||
// Description:
|
||||
// Dense/fully-connected neural network layer.
|
||||
//
|
||||
// Inputs:
|
||||
// Samples x input size const panic::tensor::real_matrix&
|
||||
//
|
||||
// Weight shape:
|
||||
// input_size x neuron_count
|
||||
//
|
||||
// Bias shape:
|
||||
// 1 x neuron_count
|
||||
//
|
||||
// Output shape:
|
||||
// samples x neuron_count panic::tensor::real_matrix
|
||||
//
|
||||
// Notes:
|
||||
// forward(input) calculates:
|
||||
//
|
||||
// outputs = inputs * weights + biases
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
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 weight matrix to store layer weights
|
||||
*
|
||||
* Weight shape:
|
||||
* input_size x neuron_count
|
||||
*/
|
||||
panic::tensor::real_matrix weights;
|
||||
panic::tensor::real_vector biases;
|
||||
panic::tensor::real_matrix outputs;
|
||||
|
||||
// Empthy contructor
|
||||
/**
|
||||
* @brief Emphty bias vector to store layer bias
|
||||
*
|
||||
* Bias shape:
|
||||
* 1 x neuron_count
|
||||
*/
|
||||
panic::tensor::real_vector biases;
|
||||
|
||||
/**
|
||||
* @brief Empthy constructor
|
||||
*
|
||||
*/
|
||||
layer_dense();
|
||||
|
||||
// Contructor with layer size
|
||||
/**
|
||||
* @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);
|
||||
|
||||
// Decontructor (All internal variables has decontructors, so we can just use default)
|
||||
/**
|
||||
* @brief Default de-constructor
|
||||
*
|
||||
*/
|
||||
~layer_dense() = default;
|
||||
|
||||
// Forward function for forward pass
|
||||
/**
|
||||
* @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);
|
||||
|
||||
// Backward pass
|
||||
/**
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user