first model

This commit is contained in:
2026-07-29 17:34:22 +02:00
parent 47671354ce
commit f5e0ee209b
25 changed files with 2642 additions and 108 deletions
+12
View File
@@ -63,6 +63,18 @@ namespace panic {
//---------------------------------------------------------------------------------------------------------------------------
static const panic::types::real_t pi = static_cast<panic::types::real_t>(3.14159265358979323846);
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::constants::half_pi
//
// Description:
// Default difinition of pi (3.14159265358979323846) used inside PANIC.
// static_cast makes sure the right number of decimals are used when defining the constant.
//
// Underlying Type:
// panic::types::real_t
//---------------------------------------------------------------------------------------------------------------------------
static const panic::types::real_t half_pi = pi / static_cast<panic::types::real_t>(2);
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
//
// Type Name : panic::constants::tau
//
+4 -16
View File
@@ -31,18 +31,6 @@
* Description:
* Functions to add panic::tensor togther;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* @file add.hpp
* @brief Public API for element-wise addition operations on PANIC vectors and matrices.
*
* This header contains the declarations that users of the math module should call.
* The comments here describe how each function is used, what dimensions are required,
* and what is returned on failure.
*
* Implementation details, OpenMP thresholds, and explicit template instantiations are
* kept in add.cpp.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
@@ -221,7 +209,7 @@ panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::ten
*
* Computes:
* @code
* C(i,j) = A(i,j) + b[i]
* C(i,j) = A(i,j) + b[j]
* @endcode
*
* @tparam T Numeric element type.
@@ -240,7 +228,7 @@ bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
*
* Computes:
* @code
* result(i,j) = A(i,j) + b[i]
* result(i,j) = A(i,j) + b[j]
* @endcode
*
* @tparam T Numeric element type.
@@ -260,7 +248,7 @@ panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const pa
*
* Computes:
* @code
* C(i,j) = A(i,j) + b[j]
* C(i,j) = A(i,j) + b[i]
* @endcode
*
* @tparam T Numeric element type.
@@ -279,7 +267,7 @@ bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
*
* Computes:
* @code
* result(i,j) = A(i,j) + b[j]
* result(i,j) = A(i,j) + b[i]
* @endcode
*
* @tparam T Numeric element type.
+353
View File
@@ -0,0 +1,353 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* 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: math
* File Name: maximum.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions that finds the maximum
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief Clips the maximum values in the vector or scalar.
*
* Computes:
* @code
* if (a[i] < k)
* c[i] = k
* else
* c[i] = a[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value compared to each element of @p a.
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool maximum(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
/**
* @brief Returns a cliped maximum value in the vector.
*
* Computes:
* @code
* if (a[i] < k)
* result[i] = k
* else
* result[i] = a[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param k Scalar value compared to each element of @p a.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> maximum(const panic::tensor::vector<T>& a, const T k);
/**
* @brief Clips the maximum elementwise in the vector.
*
* Computes:
* @code
* if (a[i] < b[i])
* c[i] = b[i]
* else
* c[i] = a[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool maximum(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
/**
* @brief Returns a new vector containing cliped maximum elementwise of a vector.
*
* Computes:
* @code
* if (a[i] < b[i])
* result[i] = b[i]
* else
* result[i] = a[i]
* @endcode
*
* @tparam T Numeric element type.
* @param a First vector.
* @param b Second vector. Must have size of @p a
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> maximum(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
/**
* @brief Clips the maximum elementwise in the matrix.
*
* Computes:
* @code
* if (A(i,j) < k)
* C(i,j) = k
* else
* C(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value compared to each element of @p a.
* @param C Output Matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if resizing @p C failed.
*
* @note This overload writes the result into an existing matrix to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool maximum(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing the cliped maximum elementwise in the matrix.
*
* Computes:
* @code
* if (A(i,j) < k)
* result(i,j) = k
* else
* result(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param k Scalar value compared to each element of @p a.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new matrix.
*/
template <typename T>
panic::tensor::matrix<T> maximum(const panic::tensor::matrix<T>& A, const T k);
/**
* @brief Clips the maximum of a matrix elementwise too a matrix.
*
* Computes:
* @code
* if (A(i,j) < B(i,j))
* C(i,j) = B(i,j)
* else
* C(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A First matrix.
* @param B Second matrix. Must have size of @p A.
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if matrix sizes do not match or resizing @p c failed.
*/
template <typename T>
bool maximum(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a matrix elementwise cliped to the maixmum.
*
* Computes:
* @code
* if (A(i,j) < B(i,j))
* result(i,j) = B(i,j)
* else
* result(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param B Second matrix. Must have size of @p A.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new matrix.
*/
template <typename T>
panic::tensor::matrix<T> maximum(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
/**
* @brief Clips the maximum of a vector rowwise too a matrix.
*
* Computes:
* @code
* if (A(i,j) < b[j])
* C(i,j) = b[j])
* else
* C(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if matrix sizes do not match or resizing @p c failed.
*/
template <typename T>
bool maximum_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a vector rowwise cliped to the maixmum.
*
* Computes:
* @code
* if (A(i,j) < b[j])
* result(i,j) = b[j])
* else
* result(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.cols().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> maximum_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
/**
* @brief Clips the maximum of a vector rowwise too a matrix.
*
* Computes:
* @code
* if (A(i,j) < b[i])
* C(i,j) = b[i])
* else
* C(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
* @param C Output matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if matrix sizes do not match or resizing @p c failed.
*/
template <typename T>
bool maximum_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
/**
* @brief Returns a new matrix containing a vector rowwise cliped to the maixmum.
*
* Computes:
* @code
* if (A(i,j) < b[i])
* result(i,j) = b[i])
* else
* result(i,j) = A(i,j)
* @endcode
*
* @tparam T Numeric element type.
* @param A Matrix.
* @param b Vector. Must have size of @p A.rows().
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> maximum_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
} // namespace math
} // namespace panic
+5 -5
View File
@@ -218,7 +218,7 @@ bool mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, p
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
panic::tensor::matrix<T> mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
/**
@@ -226,7 +226,7 @@ panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::ten
*
* Computes:
* @code
* C(i,j) = A(i,j) * b[i]
* C(i,j) = A(i,j) * b[j]
* @endcode
*
* @tparam T Numeric element type.
@@ -245,7 +245,7 @@ bool mul_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
*
* Computes:
* @code
* result(i,j) = A(i,j) * b[i]
* result(i,j) = A(i,j) * b[j]
* @endcode
*
* @tparam T Numeric element type.
@@ -265,7 +265,7 @@ panic::tensor::matrix<T> mul_rowwise(const panic::tensor::matrix<T>& A, const pa
*
* Computes:
* @code
* C(i,j) = A(i,j) * b[j]
* C(i,j) = A(i,j) * b[i]
* @endcode
*
* @tparam T Numeric element type.
@@ -284,7 +284,7 @@ bool mul_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
*
* Computes:
* @code
* result(i,j) = A(i,j) * b[j]
* result(i,j) = A(i,j) * b[i]
* @endcode
*
* @tparam T Numeric element type.
+61
View File
@@ -0,0 +1,61 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: math
* File Name: cos.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to calculate cossinus of x;
* This uses panic::math::sin
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
namespace panic{
namespace math{
/**
* @brief Calculates cos value of x
*
* Computes:
* @code
* c = cos(a)
* @endcode
* @tparam T Numeric element type.
* @param x Real input value
*
* @return Cosinus of x
*
* @note This function is omp-friendly
*/
template <typename T>
T cos(const T x);
} // namespace math
} // namespace panic
+60
View File
@@ -0,0 +1,60 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: math
* File Name: sin.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to calculate sinus of x;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
namespace panic{
namespace math{
/**
* @brief Calculates sin value of x
*
* Computes:
* @code
* c = sin(a)
* @endcode
* @tparam T Numeric element type.
* @param x Real input value
*
* @return Sinus of x
*
* @note This function is omp-friendly
*/
template <typename T>
T sin(const T x);
} // namespace math
} // namespace panic
@@ -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
+15 -2
View File
@@ -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
*
-7
View File
@@ -187,10 +187,3 @@ panic::tensor::real_vector uniform_vector(const panic::types::real_t min, const
} // namespace random
} // namespace panic
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
+100
View File
@@ -0,0 +1,100 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* 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: tensor
* File Name: linspace.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to generate linspace tensors
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <config/types.hpp>
namespace panic{
namespace tensor{
/**
* @brief Outputs a linear line in a vector
*
* Computes:
* @code
* c[i] = linspace(-5, 5, 10, true);
* @endcode
*
* @tparam T Numeric element type.
* @param start Start of the line.
* @param stop End of the line.
* @param num Number of points in the array.
* @param endpoint If the endpint should be the same as @p stop.
* @param c Output vector.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool linspace(const T start,
const T stop,
const panic::types::uint_t num,
panic::tensor::vector<T>& c,
const bool endpoint=true);
/**
* @brief Returns a vector with linear line.
*
* Computes:
* @code
* result[i] = linspace(-5, 5, 10, true);
* @endcode
*
* @param T Numeric element type.
* @param start Start of the line.
* @param stop End of the line.
* @param num Number of points in the array.
* @param endpoint If the endpint should be the same as @p stop.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> linspace(const T start,
const T stop,
const panic::types::uint_t num,
const bool endpoint=true);
} // namespace tensor
} // namespace panic
+50
View File
@@ -36,6 +36,7 @@
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <tensor/vector.hpp>
namespace panic{
@@ -187,6 +188,55 @@ struct matrix{
*/
const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const;
/**
* @brief Filles and set a row to a value.
*
* Computes:
* @code
* A.set_row(1, 3);
* @endcode
*
* @note Sets all values in the matrix.
*/
bool set_row(const panic::types::uint_t index_row, const T v);
/**
* @brief Filles and set a row to a vector.
*
* Computes:
* @code
* A.set_row(1, vector);
* @endcode
*
* @note Sets all values in the matrix.
*/
bool set_row(const panic::types::uint_t index_row, const panic::tensor::vector<T> v);
/**
* @brief Filles and set a column to a value.
*
* Computes:
* @code
* A.set_column(1, 3);
* @endcode
*
* @note Sets all values in the matrix.
*/
bool set_col(const panic::types::uint_t index_col, const T v);
/**
* @brief Filles and set a column to a vector.
*
* Computes:
* @code
* A.set_col(1, vector);
* @endcode
*
* @note Sets all values in the matrix.
*/
bool set_col(const panic::types::uint_t index_col, const panic::tensor::vector<T> v);
};