{"id":24213520,"url":"https://github.com/sea5kg/simpleneuralnetworkcpp","last_synced_at":"2025-09-08T00:12:21.855Z","repository":{"id":94041747,"uuid":"533406045","full_name":"sea5kg/SimpleNeuralNetworkCpp","owner":"sea5kg","description":"Simple Neural Network C++","archived":false,"fork":false,"pushed_at":"2023-10-12T13:57:06.000Z","size":420,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T12:43:29.707Z","etag":null,"topics":["cpp","export-to-cpp","genetic-algorithm","neural-network","neural-network-cpp","perceptron","perceptron-learning-algorithm","simple"],"latest_commit_sha":null,"homepage":"","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/sea5kg.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":"2022-09-06T16:17:58.000Z","updated_at":"2023-09-02T18:09:55.000Z","dependencies_parsed_at":"2023-10-13T01:37:17.839Z","dependency_job_id":"9fa8e3de-1a29-4b4e-b1da-371b6b802c8e","html_url":"https://github.com/sea5kg/SimpleNeuralNetworkCpp","commit_stats":null,"previous_names":["sea5kg/simpleneuralnetworkcpp","sea-kg/simpleneuralnetworkcpp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sea5kg/SimpleNeuralNetworkCpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sea5kg%2FSimpleNeuralNetworkCpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sea5kg%2FSimpleNeuralNetworkCpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sea5kg%2FSimpleNeuralNetworkCpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sea5kg%2FSimpleNeuralNetworkCpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sea5kg","download_url":"https://codeload.github.com/sea5kg/SimpleNeuralNetworkCpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sea5kg%2FSimpleNeuralNetworkCpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274113514,"owners_count":25224423,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"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","export-to-cpp","genetic-algorithm","neural-network","neural-network-cpp","perceptron","perceptron-learning-algorithm","simple"],"created_at":"2025-01-14T03:10:45.479Z","updated_at":"2025-09-08T00:12:21.810Z","avatar_url":"https://github.com/sea5kg.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleNeuralNetworkCpp\n\nSimple Neural Network C++\n\nFeatures:\n\n* You can use build-in genetic algorithm for learning neural network\n* You can export to c++ function teached neural network\n\n\nSample (teach neural network for sum):\n\n```cpp\n#include \u003cstdint.h\u003e\n#include \u003ciostream\u003e\n#include \u003cctime\u003e\n#include \u003calgorithm\u003e\n#include \u003cchrono\u003e\n\n#include \"SimpleNeuralNetwork.h\"\n#include \"test_sum_numbers_func.h\"\n\nvoid initTrainingData(SimpleNeuralTrainingItemList \u0026trainingData, int nTrainingData) {\n    // init training data\n    for (int i = 0; i \u003c nTrainingData; ++i) {\n        float in0 = static_cast\u003cfloat\u003e(std::rand() % 100);\n        float in1 = static_cast\u003cfloat\u003e(std::rand() % 100);\n        trainingData.addItem({in0, in1}, {in0 + in1});\n    }\n}\n\nint main(int argc, char *argv[]) {\n\tstd::srand(std::time(nullptr));\n\n    constexpr int nNumberOfIn = 2;\n    constexpr int nNumberOfOut = 1;\n\n    SimpleNeuralTrainingItemList trainingData(nNumberOfIn,nNumberOfOut);\n\n    constexpr size_t nTrainingDataSize = 1000;\n    initTrainingData(trainingData, nTrainingDataSize);\n\n\tSimpleNeuralNetwork *pNet = new SimpleNeuralNetwork({\n        trainingData.getNumberOfIn(),\n        64,64, // middle layers\n        trainingData.getNumberOfOut()\n    });\n\n    // init first generation\n    constexpr int nBetterSpecimens = 30;\n    constexpr int nMutateSpecimens = 40;\n    constexpr int nMixSpecimens = 40;\n    SimpleNeuralGenomList genoms(nBetterSpecimens, nMutateSpecimens, nMixSpecimens);\n    genoms.fillRandom(pNet);\n    genoms.calculateRatingForAll(pNet, \u0026trainingData);\n\n    constexpr int nMaxGenerations = 100;\n    constexpr float nConditionRatingStop = 0.1f;\n    int n = 0;\n    while (genoms.getBetterRating() \u003e nConditionRatingStop \u0026\u0026 n \u003c nMaxGenerations) {\n        ++n;\n\n        auto start = std::chrono::steady_clock::now();\n        genoms.sort(); // better generations will be on the top\n\n        std::cout \u003c\u003c \" ------- Generation \" \u003c\u003c n \u003c\u003c \" ------- \" \u003c\u003c std::endl;\n        genoms.printFirstRatings(3);\n        genoms.mutateAndMix(pNet);\n\n        // calc rating\n        genoms.calculateRatingForMutatedAndMixed(pNet, \u0026trainingData);\n\n        auto end = std::chrono::steady_clock::now();\n        std::cout\n            \u003c\u003c \"Elapsed time: \"\n            \u003c\u003c std::chrono::duration_cast\u003cstd::chrono::milliseconds\u003e(end - start).count()\n            \u003c\u003c \"ms\" \u003c\u003c std::endl\n        ;\n        std::cout \u003c\u003c \"calc avarage time: \" \u003c\u003c pNet-\u003egetCalcAvarageTimeInNanoseconds() \u003c\u003c \"ns\" \u003c\u003c std::endl;\n    }\n\n    pNet-\u003esetGenom(genoms.getBetterGenom().getGenom());\n\n    // export to c++ code\n    pNet-\u003eexportToCppFunction(\"SumNumbers.cpp\", \"sum_numbers\");\n\n    // test\n    for (int i = 0; i \u003c 10; i++) {\n        float x = (std::rand() % 200) - 100;\n        float y = (std::rand() % 200) - 100;\n        std::cout \u003c\u003c x \u003c\u003c \" + \" \u003c\u003c y \u003c\u003c \" = \" \u003c\u003c pNet-\u003ecalc({x,y})[0] \u003c\u003c \", expected (\" \u003c\u003c int(x+y) \u003c\u003c \") \" \u003c\u003c std::endl;\n    }\n\n    // write genom to file \"best_genom.txt\"\n    const std::vector\u003cfloat\u003e \u0026vBetterGenom = genoms.list()[0].getGenom();\n    std::ofstream file;\n    file.open(\"best_genom.txt\", std::ofstream::out);\n    for (int i=0; i \u003c vBetterGenom.size(); ++i) {\n        file \u003c\u003c vBetterGenom[i] \u003c\u003c \" \";\n    }\n    file \u003c\u003c std::endl;\n    file.close();\n\n\treturn 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsea5kg%2Fsimpleneuralnetworkcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsea5kg%2Fsimpleneuralnetworkcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsea5kg%2Fsimpleneuralnetworkcpp/lists"}