refactor: name the project "CeNet"
This commit is contained in:
+11
-5
@@ -1,11 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(NeuralNetworks CXX)
|
||||
project(cenet CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(xor src/xor.cpp)
|
||||
target_include_directories(xor PRIVATE include/)
|
||||
add_library(cenet INTERFACE
|
||||
include/cenet/mat.hpp
|
||||
include/cenet/tensor.hpp
|
||||
include/cenet/nn.hpp)
|
||||
target_include_directories(cenet INTERFACE include/)
|
||||
|
||||
add_executable(mnist src/mnist.cpp)
|
||||
target_include_directories(mnist PRIVATE include/)
|
||||
add_executable(xor example/xor.cpp)
|
||||
target_link_libraries(xor PRIVATE cenet)
|
||||
|
||||
add_executable(mnist example/mnist.cpp)
|
||||
target_link_libraries(mnist PRIVATE cenet)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "mat.hpp"
|
||||
#include "nn.hpp"
|
||||
#include "tensor.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cenet/nn.hpp>
|
||||
#include <cenet/tensor.hpp>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
@@ -14,28 +12,28 @@
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
using network_type = nn<tensor_input<1, 28, 28>,
|
||||
conv2d_layer<8, 3, 1, 1>,
|
||||
relu_layer,
|
||||
maxpool_layer<>,
|
||||
conv2d_layer<16, 3, 1, 1>,
|
||||
relu_layer,
|
||||
maxpool_layer<>,
|
||||
flatten_layer,
|
||||
dense_layer<10>,
|
||||
sigmoid_layer>;
|
||||
using network_type = cenet::nn<cenet::tensor_input<1, 28, 28>,
|
||||
cenet::conv2d_layer<8, 3, 1, 1>,
|
||||
cenet::relu_layer,
|
||||
cenet::maxpool_layer<>,
|
||||
cenet::conv2d_layer<16, 3, 1, 1>,
|
||||
cenet::relu_layer,
|
||||
cenet::maxpool_layer<>,
|
||||
cenet::flatten_layer,
|
||||
cenet::dense_layer<10>,
|
||||
cenet::sigmoid_layer>;
|
||||
|
||||
static std::uniform_real_distribution<> dist(-1, 1);
|
||||
|
||||
struct data {
|
||||
tensor<double, 1, 28, 28> xs;
|
||||
mat<1, 10> ys;
|
||||
cenet::tensor<double, 1, 28, 28> xs;
|
||||
cenet::mat<1, 10> ys;
|
||||
};
|
||||
|
||||
using dataset = std::vector<data>;
|
||||
|
||||
template <std::size_t N, typename T>
|
||||
static std::size_t col_largest_idx(const mat_col<N, T>& col) {
|
||||
static std::size_t col_largest_idx(const cenet::mat_col<N, T>& col) {
|
||||
std::size_t maxIdx = 0;
|
||||
std::remove_cv_t<T> max = col[0];
|
||||
for (std::size_t i = 1; i < N; ++i) {
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "nn.hpp"
|
||||
|
||||
#include <cenet/nn.hpp>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
@@ -21,7 +20,11 @@ int main(void) {
|
||||
};
|
||||
|
||||
// network net;
|
||||
using network_type = nn<dense_input<2>, dense_layer<2>, sigmoid_layer, dense_layer<1>, sigmoid_layer>;
|
||||
using network_type = cenet::nn<cenet::dense_input<2>,
|
||||
cenet::dense_layer<2>,
|
||||
cenet::sigmoid_layer,
|
||||
cenet::dense_layer<1>,
|
||||
cenet::sigmoid_layer>;
|
||||
network_type xorNet;
|
||||
|
||||
static constexpr const char* NETWORK_PATH = "./xor.nn";
|
||||
@@ -38,7 +41,7 @@ int main(void) {
|
||||
|
||||
while (gen <= 10'000'000) {
|
||||
for (std::size_t i = 0; i < 4; ++i) {
|
||||
mat<1, 2> xs;
|
||||
cenet::mat<1, 2> xs;
|
||||
xs[0][0] = static_cast<double>(i & 1);
|
||||
xs[0][1] = static_cast<double>(i > 1);
|
||||
|
||||
@@ -48,7 +51,7 @@ int main(void) {
|
||||
double acc = 0.0;
|
||||
|
||||
for (std::size_t i = 0; i < 4; ++i) {
|
||||
mat<1, 2> xs;
|
||||
cenet::mat<1, 2> xs;
|
||||
xs[0][0] = static_cast<double>(i & 1);
|
||||
xs[0][1] = static_cast<double>(i > 1);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#ifndef MAT_HPP
|
||||
#define MAT_HPP
|
||||
#ifndef CENET_MAT_HPP
|
||||
#define CENET_MAT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
namespace cenet {
|
||||
|
||||
template <std::size_t N, typename T = double, typename = std::enable_if_t<(N >= 1)>>
|
||||
class mat_col {
|
||||
template <std::size_t M, std::size_t N2, typename T2, typename>
|
||||
@@ -289,4 +291,6 @@ mat<M, N, T> operator/(T lhs, const mat<M, N, T>& rhs) {
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif // MAT_HPP
|
||||
} // namespace cenet
|
||||
|
||||
#endif // CENET_MAT_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef NN_HPP
|
||||
#define NN_HPP
|
||||
#ifndef CENET_NN_HPP
|
||||
#define CENET_NN_HPP
|
||||
|
||||
#include "mat.hpp"
|
||||
#include "tensor.hpp"
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace cenet {
|
||||
|
||||
struct layer_input {
|
||||
static constexpr std::uint32_t DENSE_TAG = 0x444E5345;
|
||||
static constexpr std::uint32_t TENSOR_TAG = 0x544E5352;
|
||||
@@ -719,4 +721,6 @@ private:
|
||||
layer_types m_layers;
|
||||
};
|
||||
|
||||
#endif // NN_HPP
|
||||
} // namespace cenet
|
||||
|
||||
#endif // CENET_NN_HPP
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifndef TENSOR_HPP
|
||||
#define TENSOR_HPP
|
||||
#ifndef CENET_TENSOR_HPP
|
||||
#define CENET_TENSOR_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <random>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace cenet {
|
||||
|
||||
template <typename T, std::size_t First, std::size_t... Rest>
|
||||
class tensor {
|
||||
public:
|
||||
@@ -180,4 +181,6 @@ private:
|
||||
T m_items[SIZE];
|
||||
};
|
||||
|
||||
#endif // TENSOR_HPP
|
||||
} // namespace cenet
|
||||
|
||||
#endif // CENET_TENSOR_HPP
|
||||
Reference in New Issue
Block a user