本文整理汇总了Python中neuron.Neuron.train方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.train方法的具体用法?Python Neuron.train怎么用?Python Neuron.train使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neuron.Neuron
的用法示例。
在下文中一共展示了Neuron.train方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Neuron
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import train [as 别名]
from neuron import Neuron
myNeuron = Neuron(3,'step')
myNeuron.setWeights([0,0,0]) # the first weight is of Bias
myNeuron.setMaxInteractions(100)
# learning the AND function
bias = 1
trainingMatrix = [[bias,0,0],[bias,1,0],[bias,1,1]]
desiredArray = [0,0,1]
converged = myNeuron.train(trainingMatrix,desiredArray)
if converged:
print 'Training OK (%d interactions)' %(myNeuron.getTrainingInteractions())
else:
print 'Training FAILED (+%d interactions)' %(myNeuron.getMaxInteractions())
for i in myNeuron.rangeWeights():
print 'W'+str(i)+': '+str(myNeuron.getWeight(i))
myNeuron.setInputs([bias,0,1])
print myNeuron.getTrainingInteractions()
print 'Output: '+str(myNeuron.think()) #output desired is 0
示例2: dot
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import train [as 别名]
unit_step_d = lambda inputs, weights: dot(inputs, weights)
training_data = [
(array([0, 0, 1]), 0),
(array([0, 1, 1]), 1),
(array([1, 0, 1]), 0),
(array([1, 1, 1]), 1),
]
eta = 0.2
input_size = 3
training_times = 100
neuron_a = Neuron(eta, input_size, unit_step_a)
neuron_a.train(training_data, training_times)
neuron_b = Neuron(eta, input_size, unit_step_b)
neuron_b.train(training_data, training_times)
neuron_c = Neuron(eta, input_size, unit_step_c)
neuron_c.train(training_data, training_times)
neurons = [neuron_a, neuron_b, neuron_c]
new_training_data = []
for x, label in training_data:
print("=")
unities = []
for neuron in neurons:
示例3: dot
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import train [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from numpy import array, dot
from neuron import Neuron
unit_step = lambda inputs, weights: 0 if dot(inputs, weights) < 0 else 1
training_data = [
(array([0, 0, 1]), 0),
(array([0, 1, 1]), 1),
(array([1, 0, 1]), 0),
(array([1, 1, 1]), 1),
]
eta = 0.2
input_size = 3
training_times = 100
neuron = Neuron(eta, input_size, unit_step)
neuron.train(training_data, training_times)
for x, _ in training_data:
unit = neuron.get_unit_step(x)
print("{}: -> {}".format(x, unit))