{"id":18331977,"url":"https://github.com/mrousavy/brabenetz","last_synced_at":"2025-04-06T03:33:30.100Z","repository":{"id":37678045,"uuid":"102705014","full_name":"mrousavy/BrabeNetz","owner":"mrousavy","description":"🧠 A fast and clean supervised neural network in C++, capable of effectively using multiple cores","archived":false,"fork":false,"pushed_at":"2020-08-03T18:11:56.000Z","size":4418,"stargazers_count":26,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T00:21:46.550Z","etag":null,"topics":["algorithm","artificial-intelligence","biases","cpp","cpu","digit-recognizer","linux","machine-learning","neural-network","neurons","nuget","scalability","supervised-neural-network","xor"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrousavy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"mrousavy","ko_fi":"mrousavy","custom":["https://paypal.me/mrousavy"]}},"created_at":"2017-09-07T07:22:23.000Z","updated_at":"2024-04-17T11:02:01.000Z","dependencies_parsed_at":"2022-09-13T04:25:04.518Z","dependency_job_id":null,"html_url":"https://github.com/mrousavy/BrabeNetz","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FBrabeNetz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FBrabeNetz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FBrabeNetz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FBrabeNetz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrousavy","download_url":"https://codeload.github.com/mrousavy/BrabeNetz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["algorithm","artificial-intelligence","biases","cpp","cpu","digit-recognizer","linux","machine-learning","neural-network","neurons","nuget","scalability","supervised-neural-network","xor"],"created_at":"2024-11-05T19:36:40.747Z","updated_at":"2025-04-06T03:33:28.872Z","avatar_url":"https://github.com/mrousavy.png","language":"C++","readme":"# BrabeNetz\n\n\u003cimg align=\"right\" src=\"Images/brain.png\" alt=\"Brain - Image by medium.com\" width=200\u003e\n\n\u003e **BrabeNetz** is a **supervised neural network** written in C++, aiming to be as fast as possible. It can effectively multithread on the **CPU** where needed, is heavily **performance optimized** and is well inline-documented. System Technology (BRAH) TGM 2017/18\n\n[![NuGet](https://img.shields.io/nuget/v/BrabeNetz.svg)](https://www.nuget.org/packages/BrabeNetz/)\n[![Download on NuGet](https://img.shields.io/nuget/dt/BrabeNetz.svg)](https://www.nuget.org/packages/BrabeNetz)\n\n```sh\nPM\u003e Install-Package BrabeNetz\n```\n\nI've written two examples of using **BrabeNetz** in the [Trainer class](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetzConsole/Trainer.cpp) to train a **XOR** (`{0,0}=0`, `{0,1}=1`, ..) and **recognize handwritten characters**.\n\nIn my XOR example, I'm using a `{2,3,1}` topology (`2` input-, `3` hidden- and `1` output-neurons), but **BrabeNetz** is scalable until the hardware reaches its limits. The digits recognizer is using a `{784,500,100,10}` network to train handwritten digits from the [MNIST DB](http://yann.lecun.com/exdb/mnist/).\n\nBe sure to [read the network description](DESCRIPTION.md), and **check out my [digit recognizer written in Qt](https://github.com/mrousavy/DigitRecognizer)** (using a trained BrabeNetz MNIST dataset)\n\n## Benchmarks\n\n\u003e **Build:** Release x64 | Windows 10 64bit\n\u003e\n\u003e **CPU:** Intel i7 6700k @ 4.0GHz x 8cores\n\u003e\n\u003e **RAM:** HyperX Fury DDR4 32GB CL14 2400MHz\n\u003e\n\u003e **SSD:** Samsung 850 EVO 540MB/s\n\u003e\n\u003e **Commit:** [53328c3](https://github.com/mrousavy/BrabeNetz/commit/53328c3f6cc2f166ad79c7c8d01a4e6a739c3b93)\n\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"700\" align=\"center\" src=\"Images/mac_cout_digits.png\" alt=\"Console output in digit recognition\"\u003e\n   \u003cp align=\"center\"\u003e\u003cb\u003eActual prediction\u003c/b\u003e of the digit recognizer network on \u003cb\u003emacOS Mojave\u003c/b\u003e\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"700\" align=\"center\" src=\"Images/win_time_xor.png\" alt=\"Console output with elapsed time (2ms)\"\u003e\n   \u003cp align=\"center\"\u003eTraining a \u003cb\u003eXOR\u003c/b\u003e 1000 times takes just \u003cb\u003e0.49ms\u003c/b\u003e\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"700\" align=\"center\" src=\"Images/linux_cout_digits.png\" alt=\"Actual trained network prediction output for digit recognition\"\u003e\n   \u003cp align=\"center\"\u003e\u003cb\u003eActual prediction\u003c/b\u003e of the digit recognizer network on \u003cb\u003eDebian Linux\u003c/b\u003e\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"750\" align=\"center\" src=\"Images/cpuload.png\" alt=\"Using 24/24 cores in Taskmanager\"\u003e\n   \u003cp align=\"center\"\u003eEffectively using \u003cb\u003eall available cores\u003c/b\u003e (24/24, 100% workload)\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"700\" align=\"center\" src=\"Images/linux_htop.png\" alt=\"Running on Linux (Task View - htop)\"\u003e\n   \u003cp align=\"center\"\u003eTask Resource viewer (htop) on \u003ca href=\"https://github.com/mrousavy/BrabeNetz/tree/master/Linux\"\u003eLinux\u003c/a\u003e (Debian 9, Linux 4.9.62, KDE Plasma)\u003c/p\u003e\n\u003c/p\u003e\n\n## Specs\n\n* **Optimized algorithms** via **raw arrays** instead of `std::vector` and more\n* Smart **multithreading** by [OpenMP](http://www.openmp.org/) anywhere the spawn-overhead is worth the performance gain\n* **Scalability** (Neuron size, Layer count) - only limited by hardware\n* **Easy to use** (Inputs, outputs)\n* **Randomly generated values** to begin with\n* Easily binary save/load with `network::save(string)`/`network::load(string)` (`state.nn` file)\n* **Sigmoid** squashing function\n* **Biases** for each neuron\n* `network_topology` helper objects for loading/saving state and inspecting network\n* `brabenetz` wrapper class for an **easy-to-use interface**\n\n## Usage\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"Images/example-code.png\" alt=\"Example Usage Code\" align=\"center\" width=\"500\" /\u003e\n\u003c/p\u003e\n\n1. Build \u0026 link library\n    * See: [build/link instructions](https://github.com/mrousavy/BrabeNetz/blob/master/BUILD.md)\n\n2. Choose your interface\n    1. `brabenetz.h`: _[Recommended]_ A wrapper for the raw `network.h` interface, but with **error handling** and **modern C++ interface** styling such as `std::vector`s, `std::exception`s, etc.\n    2. `network.h`: The raw `network` with C-style arrays and no bound/error checking. **Only use this if _performance_ is important.**\n\n3. Constructors\n    1. `(initializer_list\u003cint\u003e, properties)`: Construct a new neural network with the given network size (e.g. `{ 2, 3, 4, 1 }`) and randomize all base weights and biases - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L76-L92)\n    2. `(network_topology\u0026, properties)`: Construct a new neural network with the given network topology and import it's existing weights and biases - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L94-L104)\n    3. `(string, properties)`: Construct a new neural network with and load the neural network state from the file specified in `properties.state_file` - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L106-L116)\n\n4. Functions\n    1. `network_result brabenetz::feed(std::vector\u003cdouble\u003e\u0026 input_values)`: Feed the network input values and forward propagate through all neurons to estimate a possible output (Use the `network_result` structure ([ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L11-L57)) to access the result of the forward propagation, such as `.values` to view the output) - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L128-L140)\n    2. `double network_result::adjust(std::vector\u003cdouble\u003e\u0026 expected_output)`: Backwards propagate through the whole network to adjust wrong neurons for result trimming and return the total network error - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L35-L51)\n    3. `void brabenetz::save(string path)`: Save the network's state to disk by serializing weights - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L142-L149)\n    4. `void brabenetz::set_learnrate(double value)`: Set the network's learning rate. It is good practice and generally recommended to use one divided by the train count, so the learn rate decreases the more often you train - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L151-L162)\n    5. `network_topology\u0026 brabenetz::build_topology()`: Build and set the network topology object of the current network's state (can be used for network visualization or similar) - [ref](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetz/BrabeNetz.h#L164-L172)\n\nUsage examples can be found [here](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetzConsole/BrabeNetzConsole.cpp), and [here](https://github.com/mrousavy/BrabeNetz/blob/master/BrabeNetzConsole/Trainer.cpp)\n\n\u003e Thanks for using **BrabeNetz**!\n\n\u003ca href='https://ko-fi.com/F1F8CLXG' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi2.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n","funding_links":["https://github.com/sponsors/mrousavy","https://ko-fi.com/mrousavy","https://paypal.me/mrousavy","https://ko-fi.com/F1F8CLXG'"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Fbrabenetz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrousavy%2Fbrabenetz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Fbrabenetz/lists"}