{"id":318114,"date":"2021-02-16T21:00:26","date_gmt":"2021-02-16T21:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318114"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318114","title":{"rendered":"\u0418\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438. \u0427\u0430\u0441\u0442\u044c 3"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438.<\/p>\n<p>\u041c\u044b \u043e\u0431\u0443\u0447\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 \u0440\u044f\u0434\u0435 \u0447\u0438\u0441\u0435\u043b. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0441\u043b\u0430 0 \u0438 1.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043d\u0430\u0434\u043e \u0438\u043c\u0435\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0448\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"60,58\" width=\"60\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"59,56\" width=\"59\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"69\" width=\"69\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"59\" width=\"59\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"56\" width=\"56\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"69\" width=\"69\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u044d\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u044c.<\/p>\n<p>\u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0442\u0435\u0440\u044c \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0412\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u044f \u0434\u0430\u043c \u0432\u0430\u043c \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439&nbsp;\u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435&nbsp;\u043f\u043e\u043d\u044f\u0442\u0435\u043d \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f&nbsp;\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u044b.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438, \u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f&nbsp;\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u044b&nbsp;\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"f`(x)=\\frac{e^{-x}}{(1 + e^{-x})^2}=f(x) * (1-f(x))\" alt=\"f`(x)=\\frac{e^{-x}}{(1 + e^{-x})^2}=f(x) * (1-f(x))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c5\/427\/5cf\/8c54275cfa98be8280716f118927c8f8.svg\" width=\"275\" height=\"43\"><\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Python \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def deriv_sig(x):     return sig(x) * (1 - sig(x))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b Math.py<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e 2 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b:<\/p>\n<p>rate &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<br \/>count_learn &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/p>\n<p>\u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 count_learn \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c, \u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u0410 \u0441 rate \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0432\u043e\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<p>rate = 0.1<br \/>count_learn = 10000<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435  \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043e\u0442 0 \u0434\u043e count_learn, \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0446\u0438\u043a\u043b \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043c \u0432\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def learn(self, inputs, answers):                  rate = 0.1         count_learn = 10000          for o in range(count_learn):             for inputt, answer in zip(inputs, answers):                  sum_n1 = self.n[0].w[0] * inputt[0] + self.n[0].w[1] * inputt[1] + self.n[0].b                 n1 = sig(sum_n1)                  sum_n2 = self.n[1].w[0] * inputt[0] + self.n[1].w[1] * inputt[1] + self.n[1].b                 n2 = sig(sum_n2)                  sum_n3 = self.n[2].w[0] * n1 + self.n[2].w[1] * n2 + self.n[2].b                 n3 = sig(sum_n3)                 out_res = n3                  err = -2 * (answer - out_res)                  err_rate = rate * err                  deriv_sig_n1 = deriv_sig(sum_n1)                 deriv_sig_n2 = deriv_sig(sum_n2)                 deriv_sig_n3 = deriv_sig(sum_n3)                  self.n[0].w[0] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[0] * deriv_sig_n1                 self.n[0].w[1] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[1] * deriv_sig_n1                 self.n[0].b -= err_rate * self.n[2].w[0] * deriv_sig_n3 * deriv_sig_n1                  self.n[1].w[0] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[0] * deriv_sig_n2                 self.n[1].w[1] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[1] * deriv_sig_n2                 self.n[1].b -= err_rate * self.n[2].w[1] * deriv_sig_n3 * deriv_sig_n2                  self.n[2].w[0] -= err_rate * n1 * deriv_sig_n3                 self.n[2].w[1] -= err_rate * n2 * deriv_sig_n3                 self.n[2].b -= err_rate * deriv_sig_n3<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043a\u043b\u0430\u0441\u0441 NeuronNet.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0430\u0439\u043b NeuronNet.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from Neuron import *  class NeuronNet:     def __init__(self):          self.n = []          for i in range(3):             self.n.append(Neuron(2))      def activate(self, inputs):         return self.n[2].activate(np.array([self.n[0].activate(inputs), self.n[1].activate(inputs)]))      def learn(self, inputs, answers):                  rate = 0.1         count_learn = 10000          for o in range(count_learn):             for inputt, answer in zip(inputs, answers):                  sum_n1 = self.n[0].w[0] * inputt[0] + self.n[0].w[1] * inputt[1] + self.n[0].b                 n1 = sig(sum_n1)                  sum_n2 = self.n[1].w[0] * inputt[0] + self.n[1].w[1] * inputt[1] + self.n[1].b                 n2 = sig(sum_n2)                  sum_n3 = self.n[2].w[0] * n1 + self.n[2].w[1] * n2 + self.n[2].b                 n3 = sig(sum_n3)                 out_res = n3                  err = -2 * (answer - out_res)                  err_rate = rate * err                  deriv_sig_n1 = deriv_sig(sum_n1)                 deriv_sig_n2 = deriv_sig(sum_n2)                 deriv_sig_n3 = deriv_sig(sum_n3)                  self.n[0].w[0] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[0] * deriv_sig_n1                 self.n[0].w[1] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[1] * deriv_sig_n1                 self.n[0].b -= err_rate * self.n[2].w[0] * deriv_sig_n3 * deriv_sig_n1                  self.n[1].w[0] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[0] * deriv_sig_n2                 self.n[1].w[1] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[1] * deriv_sig_n2                 self.n[1].b -= err_rate * self.n[2].w[1] * deriv_sig_n3 * deriv_sig_n2                  self.n[2].w[0] -= err_rate * n1 * deriv_sig_n3                 self.n[2].w[1] -= err_rate * n2 * deriv_sig_n3                 self.n[2].b -= err_rate * deriv_sig_n3 <\/code><\/pre>\n<p>\u0410 Math.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import numpy as np  def sig(x):     return 1 \/ (1 + np.exp(-x))   def deriv_sig(x):     return sig(x) * (1 - sig(x))     <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u0444\u0430\u0439\u043b main.py \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">learn_inputs = np.array([[1, 0], [0, 0], [0, 1]]) learn_answers = np.array([1, 0, 0])<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">net.learn(learn_inputs, learn_answers)<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043f\u043e\u0434\u0430\u0432 \u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u0434\u043e \u0440\u0435\u0448\u0438\u0442\u044c:<\/p>\n<pre><code class=\"python\">x = np.array([1, 1])  if (net.activate(x) &lt; 0.5):     print(\"0\") else:     print(\"1\")<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 main.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import numpy as np  from NeuronNet import *  net = NeuronNet()  learn_inputs = np.array([[1, 0], [0, 0], [0, 1]]) learn_answers = np.array([1, 0, 0])  net.learn(learn_inputs, learn_answers)  x = np.array([1, 1])  if (net.activate(x) &lt; 0.5):     print(\"0\") else:     print(\"1\") <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432\u0432\u0435\u0434\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c:<\/p>\n<pre><code>python main.py<\/code><\/pre>\n<p>\u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/537\/91a\/7e5\/53791a7e5d85fcb035e91aadbfb9eef5.png\" width=\"415\" height=\"37\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u043c\u0435\u0441\u0442\u043e<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"70,74.5\" width=\"70\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"74\" width=\"74\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"70\" width=\"70\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"74.5\" width=\"74.5\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"74\" width=\"74\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"70,84.5\" width=\"70\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"73\" width=\"73\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"70\" width=\"70\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"84.5\" width=\"84.5\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"73\" width=\"73\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d8c\/12c\/1e2\/d8c12c1e2a20731e80a41c2756d9ccbd.png\" width=\"415\" height=\"37\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433\u0438.<\/p>\n<p>\u0412 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u043c \u0441\u0435\u0442\u044f\u043c \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0432\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c<\/p>\n<\/li>\n<\/ol>\n<p>\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u043c\u043e\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 github: https:\/\/github.com\/AndreiShalupaey\/PyNeuronNet<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e: https:\/\/proglib.io\/p\/pishem-neyroset-na-python-s-nulya-2020-10-07<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/542574\/\"> https:\/\/habr.com\/ru\/post\/542574\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438.<\/p>\n<p>\u041c\u044b \u043e\u0431\u0443\u0447\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 \u0440\u044f\u0434\u0435 \u0447\u0438\u0441\u0435\u043b. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0441\u043b\u0430 0 \u0438 1.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043d\u0430\u0434\u043e \u0438\u043c\u0435\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0448\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"60,58\" width=\"60\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"60\" width=\"60\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"58\" width=\"58\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"78\" width=\"78\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"59,56\" width=\"59\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"69\" width=\"69\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"59\" width=\"59\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"56\" width=\"56\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"69\" width=\"69\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u044d\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u044c.<\/p>\n<p>\u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0442\u0435\u0440\u044c \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0412\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u044f \u0434\u0430\u043c \u0432\u0430\u043c \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439&nbsp;\u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435&nbsp;\u043f\u043e\u043d\u044f\u0442\u0435\u043d \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f&nbsp;\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u044b.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438, \u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f&nbsp;\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u044b&nbsp;\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Python \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def deriv_sig(x):     return sig(x) * (1 - sig(x))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b Math.py<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e 2 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b:<\/p>\n<p>rate &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<br \/>count_learn &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/p>\n<p>\u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 count_learn \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c, \u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u0410 \u0441 rate \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0432\u043e\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<p>rate = 0.1<br \/>count_learn = 10000<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435  \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043e\u0442 0 \u0434\u043e count_learn, \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0446\u0438\u043a\u043b \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043c \u0432\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def learn(self, inputs, answers):                  rate = 0.1         count_learn = 10000          for o in range(count_learn):             for inputt, answer in zip(inputs, answers):                  sum_n1 = self.n[0].w[0] * inputt[0] + self.n[0].w[1] * inputt[1] + self.n[0].b                 n1 = sig(sum_n1)                  sum_n2 = self.n[1].w[0] * inputt[0] + self.n[1].w[1] * inputt[1] + self.n[1].b                 n2 = sig(sum_n2)                  sum_n3 = self.n[2].w[0] * n1 + self.n[2].w[1] * n2 + self.n[2].b                 n3 = sig(sum_n3)                 out_res = n3                  err = -2 * (answer - out_res)                  err_rate = rate * err                  deriv_sig_n1 = deriv_sig(sum_n1)                 deriv_sig_n2 = deriv_sig(sum_n2)                 deriv_sig_n3 = deriv_sig(sum_n3)                  self.n[0].w[0] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[0] * deriv_sig_n1                 self.n[0].w[1] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[1] * deriv_sig_n1                 self.n[0].b -= err_rate * self.n[2].w[0] * deriv_sig_n3 * deriv_sig_n1                  self.n[1].w[0] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[0] * deriv_sig_n2                 self.n[1].w[1] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[1] * deriv_sig_n2                 self.n[1].b -= err_rate * self.n[2].w[1] * deriv_sig_n3 * deriv_sig_n2                  self.n[2].w[0] -= err_rate * n1 * deriv_sig_n3                 self.n[2].w[1] -= err_rate * n2 * deriv_sig_n3                 self.n[2].b -= err_rate * deriv_sig_n3<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043a\u043b\u0430\u0441\u0441 NeuronNet.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0430\u0439\u043b NeuronNet.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from Neuron import *  class NeuronNet:     def __init__(self):          self.n = []          for i in range(3):             self.n.append(Neuron(2))      def activate(self, inputs):         return self.n[2].activate(np.array([self.n[0].activate(inputs), self.n[1].activate(inputs)]))      def learn(self, inputs, answers):                  rate = 0.1         count_learn = 10000          for o in range(count_learn):             for inputt, answer in zip(inputs, answers):                  sum_n1 = self.n[0].w[0] * inputt[0] + self.n[0].w[1] * inputt[1] + self.n[0].b                 n1 = sig(sum_n1)                  sum_n2 = self.n[1].w[0] * inputt[0] + self.n[1].w[1] * inputt[1] + self.n[1].b                 n2 = sig(sum_n2)                  sum_n3 = self.n[2].w[0] * n1 + self.n[2].w[1] * n2 + self.n[2].b                 n3 = sig(sum_n3)                 out_res = n3                  err = -2 * (answer - out_res)                  err_rate = rate * err                  deriv_sig_n1 = deriv_sig(sum_n1)                 deriv_sig_n2 = deriv_sig(sum_n2)                 deriv_sig_n3 = deriv_sig(sum_n3)                  self.n[0].w[0] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[0] * deriv_sig_n1                 self.n[0].w[1] -= err_rate * self.n[2].w[0] * deriv_sig_n3 * inputt[1] * deriv_sig_n1                 self.n[0].b -= err_rate * self.n[2].w[0] * deriv_sig_n3 * deriv_sig_n1                  self.n[1].w[0] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[0] * deriv_sig_n2                 self.n[1].w[1] -= err_rate * self.n[2].w[1] * deriv_sig_n3 * inputt[1] * deriv_sig_n2                 self.n[1].b -= err_rate * self.n[2].w[1] * deriv_sig_n3 * deriv_sig_n2                  self.n[2].w[0] -= err_rate * n1 * deriv_sig_n3                 self.n[2].w[1] -= err_rate * n2 * deriv_sig_n3                 self.n[2].b -= err_rate * deriv_sig_n3 <\/code><\/pre>\n<p>\u0410 Math.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import numpy as np  def sig(x):     return 1 \/ (1 + np.exp(-x))   def deriv_sig(x):     return sig(x) * (1 - sig(x))     <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u0444\u0430\u0439\u043b main.py \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">learn_inputs = np.array([[1, 0], [0, 0], [0, 1]]) learn_answers = np.array([1, 0, 0])<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">net.learn(learn_inputs, learn_answers)<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043f\u043e\u0434\u0430\u0432 \u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u0434\u043e \u0440\u0435\u0448\u0438\u0442\u044c:<\/p>\n<pre><code class=\"python\">x = np.array([1, 1])  if (net.activate(x) &lt; 0.5):     print(\"0\") else:     print(\"1\")<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 main.py \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import numpy as np  from NeuronNet import *  net = NeuronNet()  learn_inputs = np.array([[1, 0], [0, 0], [0, 1]]) learn_answers = np.array([1, 0, 0])  net.learn(learn_inputs, learn_answers)  x = np.array([1, 1])  if (net.activate(x) &lt; 0.5):     print(\"0\") else:     print(\"1\") <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432\u0432\u0435\u0434\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c:<\/p>\n<pre><code>python main.py<\/code><\/pre>\n<p>\u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u043c\u0435\u0441\u0442\u043e<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"70,74.5\" width=\"70\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"74\" width=\"74\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"70\" width=\"70\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"74.5\" width=\"74.5\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"74\" width=\"74\">\n<p>1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\" data-colwidth=\"70,84.5\" width=\"70\">\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"73\" width=\"73\">\n<p>\u041e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"70\" width=\"70\">\n<p>0<\/p>\n<\/td>\n<td data-colwidth=\"84.5\" width=\"84.5\">\n<p>1<\/p>\n<\/td>\n<td data-colwidth=\"73\" width=\"73\">\n<p>0<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433\u0438.<\/p>\n<p>\u0412 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u043c \u0441\u0435\u0442\u044f\u043c \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0432\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c<\/p>\n<\/li>\n<\/ol>\n<p>\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u043c\u043e\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 github: https:\/\/github.com\/AndreiShalupaey\/PyNeuronNet<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e: https:\/\/proglib.io\/p\/pishem-neyroset-na-python-s-nulya-2020-10-07<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/542574\/\"> https:\/\/habr.com\/ru\/post\/542574\/<\/a><br \/><\/br><\/br><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318114","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318114"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318114\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}