{"id":28210742,"url":"https://github.com/xuset/neuralnetwork","last_synced_at":"2025-06-11T00:31:53.263Z","repository":{"id":71414430,"uuid":"14097997","full_name":"xuset/NeuralNetwork","owner":"xuset","description":"An extensible neural network and genetic algorithm","archived":false,"fork":false,"pushed_at":"2013-11-25T01:02:56.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T17:11:15.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xuset.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}},"created_at":"2013-11-04T01:54:21.000Z","updated_at":"2020-09-07T18:35:18.000Z","dependencies_parsed_at":"2023-02-21T18:46:22.386Z","dependency_job_id":null,"html_url":"https://github.com/xuset/NeuralNetwork","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/xuset%2FNeuralNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuset%2FNeuralNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuset%2FNeuralNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuset%2FNeuralNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuset","download_url":"https://codeload.github.com/xuset/NeuralNetwork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuset%2FNeuralNetwork/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259175404,"owners_count":22816985,"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":[],"created_at":"2025-05-17T17:10:31.350Z","updated_at":"2025-06-11T00:31:53.256Z","avatar_url":"https://github.com/xuset.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"NeuralNetwork\n=============\n\nTo get started with the demo, SDL is needed. In the demo there are 30 squares, each with it's own neural network. One genetic algorithm trains them all. The goal of each square is to collect as many yellow dots as possible. The neural networks get an 4 inputs: a normalized x and y of the closest mine and a normalized x and y of the direction it is facing. The 2 outputs determine determine how the square moves. The more yellow dots a square collects, the higher it's fitness becomes. Heres a picture.\n\n![alt tag](https://raw.github.com/xuset/NeuralNetwork/master/Screenshot.png)\n\nTo compile the demo run.\n```\ng++ -o demo -lSDL src/*.cpp src/Demo/*.cpp src/NNetwork/*.cpp src/NNetwork/GeneticAlg/*.cpp\n```\nTo compile without the demo, run this. You will need to add in your own int main(void).\n```\ng++ -o notADemo src/NNetwork/*.cpp src/NNetwork/GeneticAlg/*.cpp\n```\n\nUsing the code below will create a feedforward neural network with 2 input neurons, 2 hidden layers, and 3 output neurons.\n```C++\n#define LAYER_COUNT 4\nusing namespace NeuralNetwork;\n\nint layers[LAYER_COUNT] = { 2, 6, 6, 3 };\nNNetwork nn(layers, layerCount);\nnn.setSigmoidOutput(true);\n```\n\nTo create a genetic algorithm that trains a neural network, a sample neural network must be created first. This neural network is not trained but just used to make copies. The code below creates a genetic algorithm with 100 neural networks that have the same attributes as the sample.\n```C++\n#define LAYER_COUNT 4\nusing namespace NeuralNetwork;\n\nint layers[LAYER_COUNT] = { 2, 6, 6, 3 };\nNNetwork nn(layers, layerCount);\nnn.setSigmoidOutput(true);\nGeneticAlg alg(nn, 100);\n```\n\nTo train the networks, you can loop through each network. Then apply an input and determine the network's fitness base on it's output. Calling epoch() runs through one generation on the genetic algorithm.\n```C++\n#define LAYER_COUNT 4\nusing namespace NeuralNetwork;\n\nint layers[LAYER_COUNT] = { 2, 6, 6, 3};\nNNetwork nn(layers, LAYER_COUNT);\nnn.setSigmoidOutput(true);\nGeneticAlg alg(nn, 100);\n\nwhile (alg.getGeneration() \u003c 1000) {\n\n\tfor (int i = 0; i \u003c alg.getPopulationSize(); i++) {\n\t\tChromosome\u0026 chromo = alg.getChromo(i);\n\t\t\n\t\tdouble inputs[] = { 1, 1}\n\t\tdouble outputs[3];\n\t\tchromo.stimulate(inputs, outputs);\n\t\t\n\t\tchromo.fitness = 1.0;\n\t}\n\t\n\talg.epoch();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuset%2Fneuralnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuset%2Fneuralnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuset%2Fneuralnetwork/lists"}