diff --git a/src/matrix/utils.hpp b/src/matrix/utils.hpp index 0c26dbc..4c715e2 100644 --- a/src/matrix/utils.hpp +++ b/src/matrix/utils.hpp @@ -1,8 +1,13 @@ #pragma once #include -#include +#include #include +#include +#include +#include +#include +#include #include #include #include @@ -14,33 +19,36 @@ namespace utils // функции активации. можно добавить еще для поиграться namespace activations { - inline auto sigmoid = [](auto x) -> float { - return 1.f / (1.f + std::exp(-x)); + inline auto sigmoid = [](auto x) { + using value_type = decltype(x); + return value_type{1} / (value_type{1} + std::exp(-x)); }; } namespace derivative { - inline auto sigmoid = [](auto x) -> float { - return x * (1 - x); + inline auto sigmoid = [](auto x) { + using value_type = decltype(x); + return x * (value_type{1} - x); }; } // коеффициент обучения - const float LEARNING_RATE = 0.1; + inline constexpr float LEARNING_RATE = 0.1f; // i, j - в матрице тут - это как m, n в матрицах в учебниках // т.е. строка и столбец соответственно template class matrix { - static_assert(std::is_arithmetic_v, "matrix element type must be arithmetic"); + static_assert(std::is_arithmetic_v && !std::is_same_v, + "matrix element type must be arithmetic and not bool"); static_assert(Rows > 0 && Cols > 0, "matrix dimensions must be positive"); public: matrix() : m_data(Rows * Cols, Type{}) {} matrix(Type fill_value) : m_data(Rows * Cols, fill_value) {} - matrix(std::initializer_list> init) + matrix(std::initializer_list> init) { if (init.size() != Rows) throw std::invalid_argument("matrix: row count mismatch"); m_data.reserve(Rows * Cols); @@ -138,7 +146,7 @@ namespace utils std::cout << '\n'; } private: - std::vector m_data; + std::vector m_data; }; // применяем эта если нужно оставить промежуточные результаты