Where can I find examples of programs using neural networks in C ++?

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of the Kromster , Vladimir Martyanov , aleksandr barakin , Kirill Stoianov , αλΡχολυτ 8 Oct '16 at 12:02 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And I would also be interested. Find - lay out. - 0xdb

1 answer 1

Just the other day I was reading articles about the simplest neural networks, and along the way I sketched my simplest network. This network was designed to recognize the numbers in the pictures - a classic task in most articles of the runet :) However, the structure of the neurons tried to make the structure itself independent of the task, and in my opinion it turned out to be quite revealing. I hope comments in the comments will be enough. Classes represent parts of an artificial neuron, and are called respectively

Header file:

class Neuron { public: /*Аксон - выходная Ρ‡Π°ΡΡ‚ΡŒ Π½Π΅ΠΉΡ€ΠΎΠ½Π°, которая ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅Ρ‚ состояниС Π½Π΅ΠΉΡ€ΠΎΠ½Π° дальшС, ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Π½Π½ΠΎΠ΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ Π°ΠΊΡ‚ΠΈΠ²Π°Ρ†ΠΈΠΈ*/ class Akson{ public: float getSignal();//Ѐункция Π°ΠΊΡ‚ΠΈΠ²Π°Ρ†ΠΈΠΈ Neuron *ownerNeuron; }; /*Π”Π΅Π½Π΄Ρ€ΠΈΡ‚ - ΠΎΠ΄Π½Π° ΠΈΠ· Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Π»ΠΈΠ½ΠΈΠΉ Π½Π΅ΠΉΡ€ΠΎΠ½Π°. Π‘ΠΎΠ΄Π΅Ρ€ΠΆΠΈΡ‚ вСсовой коэффициСнт. Π’ Π΄Π°Π½Π½ΠΎΠΉ Π°Ρ€Ρ…ΠΈΡ‚Π΅ΠΊΡ‚ΡƒΡ€Π΅ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ Π΄Π΅Π½Π΄Ρ€ΠΈΡ‚ содСрТит ΡƒΠΊΠ°Π·Π°Ρ‚Π΅Π»ΡŒ Π½Π° ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Π΅ΠΌΡƒ аксон, с ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ ΠΎΠ½ ΠΈ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ сигнал.*/ class Dendrit{ public: float weight = 0.1; Akson *inputAkson; }; Neuron(); /*Π’Π΅ΠΊΡ‚ΠΎΡ€, содСрТащий Π²Ρ…ΠΎΠ΄Π½Ρ‹Π΅ Π΄Π΅Π½Π΄Ρ€ΠΈΡ‚Ρ‹, Ρ‚.ΠΊ. ΠΈΡ… ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π½ΠΎΠ΅ количСство*/ std::vector<Dendrit> dendrits; Akson akson; /*Π‘ΡƒΠΌΠΌΠΈΡ€ΡƒΡŽΡ‰Π°Ρ функция, которая суммируСт(Π’ самом простом случаС) Π²Ρ…ΠΎΠ΄Π½Ρ‹Π΅ сигналы*/ virtual float kernelFunction(); /*БостояниС Π½Π΅ΠΉΡ€ΠΎΠ½Π°*/ float value; }; 

The implementation file itself implements the functions of the neuron and axon. The function of the neuron is declared virtual, so that it can be redefined for each layer of neurons.

Here is the implementation code:

 #include "neuron.h" #include <cmath> /*Π’ качСствС Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π°ΠΊΡ‚ΠΈΠ²Π°Ρ†ΠΈΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ‚.Π½. сигма-функция, которая ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ сигнал, ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹ΠΉ ΡΡƒΠΌΠΌΠΈΡ€ΡƒΡŽΡ‰Π΅ΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ Π½Π΅ΠΉΡ€ΠΎΠ½Π°*/ float Neuron::Akson::getSignal() { return (1 / (1 + exp(-(ownerNeuron->kernelFunction())))) ; } /*ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€ устанавливаСт для Π² качСствС Π½Π΅ΠΉΡ€ΠΎΠ½Π°-Π²Π»Π°Π΄Π΅Π»ΡŒΡ†Π° аксона свой ΠΎΠ±ΡŠΠ΅ΠΊΡ‚*/ Neuron::Neuron() { akson.ownerNeuron = this; } /*НСйрон Π·Π°ΠΏΡ€Π°ΡˆΠΈΠ²Π°Π΅Ρ‚ сигнал Ρƒ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ своСго Π΄Π΅Π½Π΄Ρ€ΠΈΡ‚Π°, Ρ‚Π΅ΠΌ самым ΠΎΠ±Ρ€Π°Ρ‰Π°ΡΡΡŒ ΠΊ аксонам Π½Π΅ΠΉΡ€ΠΎΠ½ΠΎΠ² ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅Π³ΠΎ слоя, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² свою ΠΎΡ‡Π΅Ρ€Π΅Π΄ΡŒ ΠΎΠ±Ρ€Π°Ρ‰Π°ΡŽΡ‚ΡΡ ΠΊ своим Π½Π΅ΠΉΡ€ΠΎΠ½Π°ΠΌ ΠΈ.Ρ‚.Π΄, Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ сбор сигналов ΠΈΠ΄Π΅Ρ‚ Ρ†Π΅ΠΏΠΎΡ‡ΠΊΠΎΠΉ ΠΎΡ‚ самого ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ слоя*/ float Neuron::kernelFunction() { float result(0.); for(Dendrit d : dendrits){ result += d.inputAkson->getSignal() * d.weight; } return result; } 

Next comes the definition of the class of the neural network itself, consisting, in fact, of neurons:

 class KohonenNet { public: /*Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΏΠΎΠ΄Π²ΠΈΠ΄Π° Π½Π΅ΠΉΡ€ΠΎΠ½Π°: Π²Ρ…ΠΎΠ΄Π½ΠΎΠΉ Π½Π΅ΠΉΡ€ΠΎΠ½, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅Ρ‚ Π²Ρ…ΠΎΠ΄Π½ΠΎΠΉ сигнал дальшС*/ class InputNeuron : public Neuron{ public: float kernelFunction(){ return value; } }; KohonenNet(); vector<Neuron*> inNeurons; vector<Neuron> outNeurons; int handle(QImage); private: /*Ѐункция обучСния Π½Π΅ΠΉΡ€ΠΎΠ½Π°*/ void study(Neuron &n, QImage pic); /*ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ с Ρ†ΠΈΡ„Ρ€Π°ΠΌΠΈ для обучСния*/ QString names[9] = {"0.bmp", "1.bmp", "2.bmp", "3.bmp","4.bmp","5.bmp","6.bmp","7.bmp", "8.bmp"}; const uint numNumbers = 9; }; 

The implementation of network functions already solves a specific problem, takes many lines of code and carries little information about the device of the network itself, so I do not give it.

P.S. I hope my work will help someone understand :)