first model
This commit is contained in:
@@ -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_ReLU.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 29-08-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Defines the activation layer for ReLU
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#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 ReLU activation layer used in neural networks
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* panic::neural_network::activation_ReLU myactivation();
|
||||
* myactivation.forward(inputMatrix);
|
||||
* @endcode
|
||||
*
|
||||
* The struct is used in PANIC nural_network library.
|
||||
*/
|
||||
struct activation_ReLU : public layer{
|
||||
|
||||
/**
|
||||
* @brief Empthy constructor
|
||||
*
|
||||
*/
|
||||
activation_ReLU();
|
||||
|
||||
/**
|
||||
* @brief Default de-constructor
|
||||
*
|
||||
*/
|
||||
~activation_ReLU() = 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
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: sine_data.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 29-07-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Functions to generate dataset for neural networks;
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
|
||||
#include <config/types.hpp>
|
||||
#include <tensor/vector.hpp>
|
||||
#include <tensor/matrix.hpp>
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INPLEMENTATION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace panic {
|
||||
namespace neural_network {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generates a dataset of sines values
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* csine(10, 1, X, y)
|
||||
* @endcode
|
||||
*
|
||||
* @tparam T Numeric element type.
|
||||
* @param samples Number of samples dataset.
|
||||
* @param lenght Interval of the sinus cuve form zero.
|
||||
* @param X Output X matrix
|
||||
* @param y Output y matrix
|
||||
*
|
||||
* @return true if @p X and @p y was resized and filled successfully.
|
||||
* @return false if resizing @p X or @p y failed.
|
||||
*
|
||||
* @note This funtion writes the result into an existing vector to avoid
|
||||
* unnecessary temporary allocations.
|
||||
*/
|
||||
template <typename T>
|
||||
bool sine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::vector<T>& y);
|
||||
|
||||
/**
|
||||
* @brief Generates a dataset of sines and cosine values
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* csine(10, 1, X, y)
|
||||
* @endcode
|
||||
*
|
||||
* @tparam T Numeric element type.
|
||||
* @param samples Number of samples dataset.
|
||||
* @param lenght Interval of the sinus cuve form zero.
|
||||
* @param X Output X matrix
|
||||
* @param y Output y matrix
|
||||
*
|
||||
* @return true if @p X and @p y was resized and filled successfully.
|
||||
* @return false if resizing @p X or @p y failed.
|
||||
*
|
||||
* @note This funtion writes the result into an existing vector to avoid
|
||||
* unnecessary temporary allocations.
|
||||
*/
|
||||
template <typename T>
|
||||
bool sine_cosine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::matrix<T>& y);
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace neural_network
|
||||
} // namespace panic
|
||||
@@ -0,0 +1,74 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: spiral_data.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 29-07-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Functions to generate dataset for neural networks;
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
|
||||
#include <config/types.hpp>
|
||||
#include <tensor/vector.hpp>
|
||||
#include <tensor/matrix.hpp>
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INPLEMENTATION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace panic {
|
||||
namespace neural_network {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generates a dataset of spiral values
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* spiral_data(10, 1, X, y)
|
||||
* @endcode
|
||||
*
|
||||
* @tparam T Numeric element type.
|
||||
* @param samples Number of samples dataset.
|
||||
* @param classes Number of classes in the spiral data.
|
||||
* @param X Output X matrix
|
||||
* @param y Output y matrix
|
||||
*
|
||||
* @return true if @p X and @p y was resized and filled successfully.
|
||||
* @return false if resizing @p X or @p y failed.
|
||||
*
|
||||
* @note This funtion writes the result into an existing vector to avoid
|
||||
* unnecessary temporary allocations.
|
||||
*/
|
||||
template <typename T>
|
||||
bool spiral_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace neural_network
|
||||
} // namespace panic
|
||||
@@ -0,0 +1,74 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: vertical_data.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 29-07-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Functions to generate dataset for neural networks;
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
|
||||
#include <config/types.hpp>
|
||||
#include <tensor/vector.hpp>
|
||||
#include <tensor/matrix.hpp>
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INPLEMENTATION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace panic {
|
||||
namespace neural_network {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generates a dataset of vertical values
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* vertical_data(10, 1, X, y)
|
||||
* @endcode
|
||||
*
|
||||
* @tparam T Numeric element type.
|
||||
* @param samples Number of samples dataset.
|
||||
* @param classes Number of classes in the vertical data.
|
||||
* @param X Output X matrix
|
||||
* @param y Output y matrix
|
||||
*
|
||||
* @return true if @p X and @p y was resized and filled successfully.
|
||||
* @return false if resizing @p X or @p y failed.
|
||||
*
|
||||
* @note This funtion writes the result into an existing vector to avoid
|
||||
* unnecessary temporary allocations.
|
||||
*/
|
||||
template <typename T>
|
||||
bool vertical_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace neural_network
|
||||
} // namespace panic
|
||||
@@ -118,8 +118,6 @@ struct model{
|
||||
*/
|
||||
bool add(layer* new_layer);
|
||||
|
||||
// Create and add a dense layer.
|
||||
|
||||
/**
|
||||
* @brief Adds a dense layer to the model.
|
||||
*
|
||||
@@ -140,6 +138,21 @@ struct model{
|
||||
panic::types::uint_t neuron_count
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Adds a activation ReLU layer to the model.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* model.add_activation_ReLU(3,4);
|
||||
* @endcode
|
||||
*
|
||||
*
|
||||
* @return true if layer is added
|
||||
*
|
||||
* @note This function is convenient, but it allocates a new layer.
|
||||
*/
|
||||
bool add_activation_ReLU();
|
||||
|
||||
/**
|
||||
* @brief Loops over all layers forward function
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user