本文整理汇总了Python中neuron.Neuron.get_output方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.get_output方法的具体用法?Python Neuron.get_output怎么用?Python Neuron.get_output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neuron.Neuron
的用法示例。
在下文中一共展示了Neuron.get_output方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import get_output [as 别名]
def main(train, test, out):
TRAIN_FILE = train
TEST_FILE = test
OUT_FILE = out
img = Image.open(TRAIN_FILE) # read double moons image from .png file
pixels = img.load() # generate pixel map
width = img.size[0]
height = img.size[1]
training_set = dict()
for i in range(width):
for j in range(height):
if pixels[i,j] == BLUE: # if pixel is blue
training_set[i,j] = BOT # set value to bottom
elif pixels[i,j] == RED: # if pixel is red
training_set[i,j] = TOP # set value to top
# create neuron with 2 input nodes
n = Neuron(2) # x-input, y-input
print "Neuron created."
# training
print "Training..."
counter = 0
while True:
errors = 0
for p in training_set:
errors += n.train_step(p, training_set[p])
counter += 1
print "====="
if errors < n.get_margin() * len(training_set):
break
print "Length of training set: " + str(len(training_set))
print "Iterations: " + str(counter)
# test cases
img = Image.open(TEST_FILE)
pixels = img.load()
width = img.size[0]
height = img.size[1]
for i in range(width):
for j in range(height):
if pixels[i,j] == BLACK:
n.set_input(0, i)
n.set_input(1, j)
n.activate()
ans = n.get_output()
if ans == TOP:
pixels[i,j] = RED
elif ans == BOT:
pixels[i,j] = BLUE
img.save(OUT_FILE, "PNG")