当前位置: 首页>>代码示例>>Python>>正文


Python Neuron.train方法代码示例

本文整理汇总了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
开发者ID:mauricioribeiro,项目名称:pyNeural,代码行数:26,代码来源:test-neuron.py

示例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:
开发者ID:LucianoPC,项目名称:perceptron_study,代码行数:32,代码来源:perceptron.py

示例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))
开发者ID:LucianoPC,项目名称:perceptron_study,代码行数:27,代码来源:perceptron2.py


注:本文中的neuron.Neuron.train方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。