{"id":23447613,"url":"https://github.com/rugleb/neural-network","last_synced_at":"2025-06-30T12:33:01.114Z","repository":{"id":96355485,"uuid":"158281020","full_name":"rugleb/neural-network","owner":"rugleb","description":"High-level neural networks API for C++","archived":false,"fork":false,"pushed_at":"2019-12-04T07:34:27.000Z","size":153,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T16:49:22.868Z","etag":null,"topics":["cpp","neural","neural-network"],"latest_commit_sha":null,"homepage":"https://github.com/rugleb/neural-network","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/rugleb.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":"2018-11-19T19:47:43.000Z","updated_at":"2021-11-23T18:39:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"edd8863e-1cc4-4395-806f-200ddb359067","html_url":"https://github.com/rugleb/neural-network","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fneural-network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fneural-network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fneural-network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fneural-network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rugleb","download_url":"https://codeload.github.com/rugleb/neural-network/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248138811,"owners_count":21053960,"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":["cpp","neural","neural-network"],"created_at":"2024-12-23T21:18:26.294Z","updated_at":"2025-04-10T01:24:05.232Z","avatar_url":"https://github.com/rugleb.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/rugleb/neural-network.svg?branch=master)](https://travis-ci.com/rugleb/neural-network)\n[![Language](https://img.shields.io/badge/Lang-C++11-green.svg)]()\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# Preview\n\nThis repository is created for educational purposes only and is not ready for use in production.\n\nThe developed interface for working with neural networks is largely inspired by the [Keras](https://keras.io) framework.\n\n# Getting started\n\nThe central data structure of this library is the [model](https://github.com/rugleb/neural-network/blob/8812e1cc41e8854e301d86987b03c69e2ef1cb5d/src/network.h#L108).\nIt defines the structure of the [layers](https://github.com/rugleb/neural-network/blob/8812e1cc41e8854e301d86987b03c69e2ef1cb5d/src/network.h#L45) and the relationship between them.\n\n\u003e At the moment, only a Sequential network model is implemented.\n\nNow create an instance of the new network model:\n\n```C++\n#include \"src/network.h\"\n\nModel model;\n```\n\nThen add two hidden layers with different activation functions and neurons number:\n\n```C++\nmodel.add(Layer(20, relu));         // 20 neurons and ReLU activation\nmodel.add(Layer(10, sigmoid));      // 10 neurons and Sigmoid activation\n```\n\n\u003e Note that the model automatically selects the number of neurons on the input layer of the network.\n\nNow the structure of the neural network is ready.\n\nThe next step is to train the neural network.\nBut before you train a model, you must set the training parameters.  \nThis is done quite simply:\n\n```C++\nTrainParams params;\nparams.dataset = dataset;           // train dataset\nparams.epochs = 5;                  // number of training epochs\nparams.error = 1e-10;               // acceptable learning error\nparams.teach = 0.05;                // learning rate\n```\n\nUnder dataset should be understood as a set (vector) of data in the format:\nvector of input values of the network and a vector of output values of the network. \nMore detailed: [Dataset structure](https://github.com/rugleb/neural-network/blob/b5dbe3ab3a37ac44db6a1044407c7903d623bdb0/src/network.h#L92).\n\nNow that we are ready to train the network, we can start the learning process:\n\n```C++\nmodel.fit(params);\n```\n\nDuring the training program will inform you:\n\n```C++\nTraining started\n---- Epoch: 1, average error: 5.74e-04\n---- Epoch: 2, average error: 1.62e-05\n---- Epoch: 3, average error: 8.75e-07\n---- Epoch: 4, average error: 6.41e-08\n---- Epoch: 5, average error: 2.32e-09\nTraining finished\n```\n\nAfter training the model, we can test the quality on the test data:\n\n```C++\nDataset testing = makeTesting(3);    // creates 3 test datasets\nmodel.testing(testingSet);           // starts testing\n```\n\nThe output of the program:\n\n```C++\nTesting started\n---- Testing set: 1, error: 1.12e-02\n---- Testing set: 2, error: 1.65e-03\n---- Testing set: 3, error: 4.36e-04\nTesting finished. Average error: 4.43e-03\n```\n\nNow the model is trained and tested.\nThen it can be saved and used for other tasks.\n\n# Full example\n\nYou can see a complete example of a program that uses a neural network (autoencoder) to compress a PNG image\ninto a vector and then restores the image from the compressed vector to the original image: [main.cpp file](https://github.com/rugleb/neural-network/blob/master/main.cpp).\n\nBuild from sources:\n\n```bash\n./compile.sh\n```\n\nRun application:\n```bash\n./build/nn example.png output.png\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frugleb%2Fneural-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frugleb%2Fneural-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frugleb%2Fneural-network/lists"}