{"id":24535678,"url":"https://github.com/maosong2022/tinyneuralnetwork","last_synced_at":"2026-06-24T22:31:25.291Z","repository":{"id":209625605,"uuid":"722145238","full_name":"MaoSong2022/TinyNeuralNetwork","owner":"MaoSong2022","description":"A simply C++ implemented neural networks","archived":false,"fork":false,"pushed_at":"2023-12-23T15:34:47.000Z","size":589,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T23:28:28.636Z","etag":null,"topics":["cpp","cpp17","deep-learning","deep-neural-networks"],"latest_commit_sha":null,"homepage":"https://maosong2022.github.io/TinyNeuralNetwork/index.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaoSong2022.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-22T14:29:22.000Z","updated_at":"2023-12-23T15:06:43.000Z","dependencies_parsed_at":"2023-12-23T10:21:15.292Z","dependency_job_id":"59f9189d-c892-40ec-87f8-d6a60587a5c2","html_url":"https://github.com/MaoSong2022/TinyNeuralNetwork","commit_stats":null,"previous_names":["maosong2022/tinyneuralnetwork"],"tags_count":0,"template":false,"template_full_name":"MaoSong2022/CppProjectTemplate","purl":"pkg:github/MaoSong2022/TinyNeuralNetwork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaoSong2022%2FTinyNeuralNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaoSong2022%2FTinyNeuralNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaoSong2022%2FTinyNeuralNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaoSong2022%2FTinyNeuralNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaoSong2022","download_url":"https://codeload.github.com/MaoSong2022/TinyNeuralNetwork/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaoSong2022%2FTinyNeuralNetwork/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34752465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp17","deep-learning","deep-neural-networks"],"created_at":"2025-01-22T12:20:11.122Z","updated_at":"2026-06-24T22:31:25.258Z","avatar_url":"https://github.com/MaoSong2022.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# An C++ implemented Neural Network\nThis is a C++ implemented, a simple implementation of Multi-Layer Perception (MLP), it is enclosed so that we can use it in the same way of using Pytorch.\n\nHere is a simple example:\n```\nint main()\n{\n    // training data\n    std::vector\u003cdouble\u003e inputs = {2.0, 3.0, -1.0};\n    std::vector\u003cdouble\u003e targets = {1.0};\n\n    // construct mlp\n    size_t num_inputs = inputs.size();\n    std::vector\u003csize_t\u003e num_outputs{4, 4, 1};\n    MLP mlp(num_inputs, num_outputs);\n\n    // configure training parameters\n    size_t iters = 20;\n    double lr = 0.01;\n\n    for (size_t iter = 0; iter \u003c iters; iter++)\n    {\n        // forward pass\n        const std::vector\u003cVariable\u003e \u0026predictions = mlp.forward(inputs);\n\n        // compute and record loss\n        Variable loss = MSELoss(predictions, targets);\n        spdlog::info(\n            fmt::format(\"Iteration: {}. Loss: {}\", iter, loss.value()));\n\n        // zero gradient\n        for (auto \u0026parameter : mlp.mutable_parameters())\n        {\n            parameter.zero_grad();\n        }\n\n        // set gradient in order to back propagate\n        loss.set_gradient(1.0);\n\n        // backward\n        loss.backward();\n\n        // update values\n        for (auto \u0026parameter : mlp.mutable_parameters())\n        {\n            parameter.gradient_descent(lr);\n        }\n    }\n\n    return 0;\n}\n```\nfor more details, see `app/simple_mlp.cc`.\n\n\n## Building\n\nFirst, clone this repo and do the preliminary work:\n\n```shell\ngit clone --recursive https://github.com/franneck94/CppProjectTemplate\nmake prepare\n```\n\n- App Executable\n\n```shell\ncd build\ncmake -DCMAKE_BUILD_TYPE=Release ..\ncmake --build . --config Release --target main\ncd app\n./main\n```\n\n- Unit testing\n\n```shell\ncd build\ncmake -DCMAKE_BUILD_TYPE=Debug ..\ncmake --build . --config Debug --target unit_tests\ncd tests\n./unit_tests\n```\n\n- Documentation\n\n```shell\ncd build\ncmake -DCMAKE_BUILD_TYPE=Debug ..\ncmake --build . --config Debug --target docs\n```\n\n- Code Coverage (Unix only)\n\n```shell\ncd build\ncmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON ..\ncmake --build . --config Debug --target coverage\n```\n\nFor more info about CMake see [here](./README_cmake.md).\nThe first time to compile may take a long time, be patient!\n\n# Method\nSince the forward process and backward process are asynchronous, it is necessary for us to remember what happened before, this project uses a special class `Variable`, which has a special member `_backward` of function type to determine the behavior of backward process. In other words, `Variable` class passes gradient related information during backward process.\n\nThen, `Neuron`, `Layer`, `MLP` are built step by step, of which `_weights` and `_bias` are the cores, which we use a special field of `Variable` called `ref` to ensure they are correctly updated.\n\n\n\n# Checklists\n[ ] support batch inputs.  \n[ ] support convolution neural networks.   \n[ ] support more loss functions.  \n[ ] memory use efficiency.\n\n\n\n\n## Structure\n``` text\n├── CMakeLists.txt\n├── app\n│   ├── CMakesLists.txt\n│   └── main.cc\n├── cmake\n│   └── cmake modules\n├── docs\n│   ├── Doxyfile\n│   └── html/\n├── external\n│   ├── CMakesLists.txt\n│   ├── ...\n├── src\n│   ├── CMakesLists.txt\n│   ├── my_lib.h\n│   └── my_lib.cc\n└── tests\n    ├── CMakeLists.txt\n    └── main.cc\n```\n\nLibrary code goes into [src/](src/), main program code in [app/](app) and tests go in [tests/](tests/).\n\n## Software Requirements\n\n- CMake 3.21+\n- GNU Makefile\n- Doxygen\n- Conan or VCPKG\n- MSVC 2017 (or higher), G++9 (or higher), Clang++9 (or higher)\n- Optional: Code Coverage (only on GNU|Clang): lcov, gcovr\n- Optional: Makefile, Doxygen, Conan, VCPKG\n\n\n\n\n# Acknowledgement\n1. This project is inspired by lectures given by [Andrej Karpathy](https://karpathy.ai/),  here is the [video link](https://www.youtube.com/watch?v=VMj-3S1tku0), and the corresponding [Github Repository](https://github.com/karpathy/micrograd).\n2. This project uses the template provided by [CppProjectTemplate](https://github.com/franneck94/CppProjectTemplate).\n3. The documentation is generated with the help of [Doxygen](https://www.doxygen.nl/index.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaosong2022%2Ftinyneuralnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaosong2022%2Ftinyneuralnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaosong2022%2Ftinyneuralnetwork/lists"}