{"id":411277,"date":"2024-06-29T21:52:33","date_gmt":"2024-06-29T21:52:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=411277"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=411277","title":{"rendered":"<span>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043d\u0430 Raspberry Pi Pico<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0440\u0438\u0432\u0435\u0442! P.S \u042d\u0442\u043e \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043d\u0430 Raspberry Pi Pico!<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c pico:<\/p>\n<pre><code class=\"python\">from random import random from math import exp  class NeyroNet: def __init__(self, n_inputs, hiddens_layer, n_outputs): self.network = list()  self.n_outputs = n_outputs  hidden_layer = [{'weights':[random() for i in range(n_inputs + 1)]} for i in range(hiddens_layer[0])] self.network.append(hidden_layer)  for layer in hiddens_layer[1:]: hidden_layer = [{'weights':[random() for i in range(len(self.network[-1])+1)]} for i in range(layer)] self.network.append(hidden_layer)  output_layer = [{'weights':[random() for i in range(hiddens_layer[-1] + 1)]} for i in range(n_outputs)] self.network.append(output_layer)  def activate(self, weights, inputs): activation = weights[-1] for i in range(len(weights)-1): activation += weights[i] * inputs[i] return activation  def transfer(self, activation): return 1.0 \/ (1.0 + exp(-activation))  def forward_propagate(self, row): inputs = row for layer in self.network: new_inputs = [] for neuron in layer: activation = self.activate(neuron['weights'], inputs) neuron['output'] = self.transfer(activation) new_inputs.append(neuron['output']) inputs = new_inputs return inputs  def transfer_derivative(self, output): return output * (1.0 - output)  def backward_propagate_error(self, expected): for i in reversed(range(len(self.network))): layer = self.network[i] errors = list() if i != len(self.network)-1: for j in range(len(layer)): error = 0.0 for neuron in self.network[i + 1]: error += (neuron['weights'][j] * neuron['delta']) errors.append(error) else: for j in range(len(layer)): neuron = layer[j] errors.append(expected[j] - neuron['output']) for j in range(len(layer)): neuron = layer[j] neuron['delta'] = errors[j] * self.transfer_derivative(neuron['output'])  def update_weights(self, row, l_rate): for i in range(len(self.network)): inputs = row[:-1] if i != 0: inputs = [neuron['output'] for neuron in self.network[i - 1]] for neuron in self.network[i]: for j in range(len(inputs)): neuron['weights'][j] += l_rate * neuron['delta'] * inputs[j] neuron['weights'][-1] += l_rate * neuron['delta']  def train_network(self, train, l_rate, n_epoch, err_val_threshold=0): for epoch in range(n_epoch): sum_error = 0 for row in train: outputs = self.forward_propagate(row) expected = [0 for i in range(self.n_outputs)] expected[row[-1]] = 1 sum_error += sum([(expected[i]-outputs[i])**2 for i in range(len(expected))]) self.backward_propagate_error(expected) self.update_weights(row, l_rate) pdat = '>epoch=%d, lrate=%.1f, error=%.10f' % (epoch, l_rate, sum_error) print(pdat, end='\\r') if(sum_error &lt; err_val_threshold): print(' ' * len(pdat), end='\\r') print('THRESHOLD WITH EPOCH > ' + str(epoch)) break  def predict(self, row): outputs = self.forward_propagate(row) return outputs.index(max(outputs))  def save(self, filename): with open(filename, 'w') as sv: sv.write(str(self.network)) sv.close()  def load(self, filename): with open(filename, 'r') as sv: data = sv.read() sv.close() self.network = eval(data)  <\/code><\/pre>\n<p>\u041d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c pico \u0447\u0435\u0440\u0435\u0437 minicom \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 thonny<\/p>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/p>\n<pre><code class=\"python\">import &lt;\u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0431\u0435\u0437 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438 .py> net = NeyroNet(3, [6], 2) # 3 - \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0445\u043e\u0434\u043e\u0432, [6] - \u042d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0451\u0432 (\u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u043e\u0435 6 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432), 2 - \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043e\u0432<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0435\u0440\u0451\u043c \u043b\u044e\u0431\u043e\u0439 dataset<\/p>\n<pre><code class=\"python\">dataset = [[1, 0 ,0 ,1], [1, 1, 0, 1], [0, 1, 1, 0], [0, 0, 1, 0]]<\/code><\/pre>\n<p>\u0412\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435: &#171;\u041f\u043e\u0447\u0435\u043c\u0443 \u0443 \u0442\u0435\u0431\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043f\u043e 4 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430 \u0432\u0445\u043e\u0434\u043e\u0432 \u0432\u0441\u0435\u0433\u043e 4?&#187;<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 &#8212; \u044d\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0435!<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c<\/p>\n<pre><code class=\"python\">net.train_network(dataset, l_rate=0.5, n_epoch=10000, err_val_threshold=0.0009)<\/code><\/pre>\n<p>P.S. \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 err_val_threshold \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0436\u0434\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u043e\u0439\u0434\u0451\u0442 \u0432\u0441\u0435  \u044d\u043f\u043e\u0445\u0438, \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442.e. \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u0442\u0441\u044f!<\/p>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u043c\u044b \u0438 \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c! \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0447\u0442\u043e \u043e\u043d\u0430 \u0432\u044b\u0434\u0430\u0451\u0442!<\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<pre><code class=\"python\">net.predict([1, 0, 1]) # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 1 \u0442.\u0435 \u043a\u0430\u043a\u043e\u0439 \u0432\u044b\u0445\u043e\u0434 (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0) net.forward_propagate([0, 0, 0]) # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 [0.99998464, 0.00006544]<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0432\u0435\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">net.save('&lt;\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430>')<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0435\u0441\u0430 \u0441\u0435\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u043e\u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0435\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0432\u044b\u0445\u043e\u0434\u043e\u0432, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438 \u0431\u044b\u043b\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e, \u0430 \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430!<\/p>\n<pre><code class=\"python\">net.load('&lt;\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430>')<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451!<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u0442\u0430\u0442\u044c\u044f!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/716844\/\"> https:\/\/habr.com\/ru\/articles\/716844\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0440\u0438\u0432\u0435\u0442! P.S \u042d\u0442\u043e \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043d\u0430 Raspberry Pi Pico!<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c pico:<\/p>\n<pre><code class=\"python\">from random import random from math import exp  class NeyroNet: def __init__(self, n_inputs, hiddens_layer, n_outputs): self.network = list()  self.n_outputs = n_outputs  hidden_layer = [{'weights':[random() for i in range(n_inputs + 1)]} for i in range(hiddens_layer[0])] self.network.append(hidden_layer)  for layer in hiddens_layer[1:]: hidden_layer = [{'weights':[random() for i in range(len(self.network[-1])+1)]} for i in range(layer)] self.network.append(hidden_layer)  output_layer = [{'weights':[random() for i in range(hiddens_layer[-1] + 1)]} for i in range(n_outputs)] self.network.append(output_layer)  def activate(self, weights, inputs): activation = weights[-1] for i in range(len(weights)-1): activation += weights[i] * inputs[i] return activation  def transfer(self, activation): return 1.0 \/ (1.0 + exp(-activation))  def forward_propagate(self, row): inputs = row for layer in self.network: new_inputs = [] for neuron in layer: activation = self.activate(neuron['weights'], inputs) neuron['output'] = self.transfer(activation) new_inputs.append(neuron['output']) inputs = new_inputs return inputs  def transfer_derivative(self, output): return output * (1.0 - output)  def backward_propagate_error(self, expected): for i in reversed(range(len(self.network))): layer = self.network[i] errors = list() if i != len(self.network)-1: for j in range(len(layer)): error = 0.0 for neuron in self.network[i + 1]: error += (neuron['weights'][j] * neuron['delta']) errors.append(error) else: for j in range(len(layer)): neuron = layer[j] errors.append(expected[j] - neuron['output']) for j in range(len(layer)): neuron = layer[j] neuron['delta'] = errors[j] * self.transfer_derivative(neuron['output'])  def update_weights(self, row, l_rate): for i in range(len(self.network)): inputs = row[:-1] if i != 0: inputs = [neuron['output'] for neuron in self.network[i - 1]] for neuron in self.network[i]: for j in range(len(inputs)): neuron['weights'][j] += l_rate * neuron['delta'] * inputs[j] neuron['weights'][-1] += l_rate * neuron['delta']  def train_network(self, train, l_rate, n_epoch, err_val_threshold=0): for epoch in range(n_epoch): sum_error = 0 for row in train: outputs = self.forward_propagate(row) expected = [0 for i in range(self.n_outputs)] expected[row[-1]] = 1 sum_error += sum([(expected[i]-outputs[i])**2 for i in range(len(expected))]) self.backward_propagate_error(expected) self.update_weights(row, l_rate) pdat = '>epoch=%d, lrate=%.1f, error=%.10f' % (epoch, l_rate, sum_error) print(pdat, end='\\r') if(sum_error &lt; err_val_threshold): print(' ' * len(pdat), end='\\r') print('THRESHOLD WITH EPOCH > ' + str(epoch)) break  def predict(self, row): outputs = self.forward_propagate(row) return outputs.index(max(outputs))  def save(self, filename): with open(filename, 'w') as sv: sv.write(str(self.network)) sv.close()  def load(self, filename): with open(filename, 'r') as sv: data = sv.read() sv.close() self.network = eval(data)  <\/code><\/pre>\n<p>\u041d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c pico \u0447\u0435\u0440\u0435\u0437 minicom \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 thonny<\/p>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/p>\n<pre><code class=\"python\">import &lt;\u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0431\u0435\u0437 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438 .py> net = NeyroNet(3, [6], 2) # 3 - \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0445\u043e\u0434\u043e\u0432, [6] - \u042d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0451\u0432 (\u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u043e\u0435 6 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432), 2 - \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043e\u0432<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0435\u0440\u0451\u043c \u043b\u044e\u0431\u043e\u0439 dataset<\/p>\n<pre><code class=\"python\">dataset = [[1, 0 ,0 ,1], [1, 1, 0, 1], [0, 1, 1, 0], [0, 0, 1, 0]]<\/code><\/pre>\n<p>\u0412\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435: &#171;\u041f\u043e\u0447\u0435\u043c\u0443 \u0443 \u0442\u0435\u0431\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043f\u043e 4 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430 \u0432\u0445\u043e\u0434\u043e\u0432 \u0432\u0441\u0435\u0433\u043e 4?&#187;<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 &#8212; \u044d\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0435!<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c<\/p>\n<pre><code class=\"python\">net.train_network(dataset, l_rate=0.5, n_epoch=10000, err_val_threshold=0.0009)<\/code><\/pre>\n<p>P.S. \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 err_val_threshold \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0436\u0434\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u043f\u0440\u043e\u0439\u0434\u0451\u0442 \u0432\u0441\u0435  \u044d\u043f\u043e\u0445\u0438, \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442.e. \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u0442\u0441\u044f!<\/p>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u043c\u044b \u0438 \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c! \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0447\u0442\u043e \u043e\u043d\u0430 \u0432\u044b\u0434\u0430\u0451\u0442!<\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<pre><code class=\"python\">net.predict([1, 0, 1]) # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 1 \u0442.\u0435 \u043a\u0430\u043a\u043e\u0439 \u0432\u044b\u0445\u043e\u0434 (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0) net.forward_propagate([0, 0, 0]) # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 [0.99998464, 0.00006544]<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0432\u0435\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">net.save('&lt;\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430>')<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0435\u0441\u0430 \u0441\u0435\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u043e\u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0435\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0432\u044b\u0445\u043e\u0434\u043e\u0432, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438 \u0431\u044b\u043b\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e, \u0430 \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430!<\/p>\n<pre><code class=\"python\">net.load('&lt;\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430>')<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451!<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u0442\u0430\u0442\u044c\u044f!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/716844\/\"> https:\/\/habr.com\/ru\/articles\/716844\/<\/a><br \/><\/br><\/br><\/p>\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-411277","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411277","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=411277"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411277\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}