本文整理汇总了Python中neuron.Neuron.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.disconnect方法的具体用法?Python Neuron.disconnect怎么用?Python Neuron.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neuron.Neuron
的用法示例。
在下文中一共展示了Neuron.disconnect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Layer
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import disconnect [as 别名]
class Layer(object):
"""layer implementation"""
def __init__(self, num=None, next=None):
super(Layer, self).__init__()
if num == None:
num = MIN_NUM_OF_NEURONS
self.neurons = []
self.alpha_neuron = Neuron(is4alpha=True)
self.next_layer = []
self.prev_layer = []
self.history = []
for i in xrange(num):
self.add_neuron()
if not (next == None):
self.connect(next)
def set_input(self, arr):
if len(arr) != len(self.neurons):
raise Exception('Wrong input length')
for i, x in enumerate(self.neurons):
x.set_input(arr[i])
def null_input(self):
self.set_input([0] * len(self.neurons))
def get_value(self):
return [i.value for i in self.neurons]
"""
Добаление нейрона в слой
"""
def add_neuron(self):
# return True
if len(self.neurons) >= MAX_NUM_OF_NEURONS:
return False
new = Neuron()
self.neurons.append(new)
self.alpha_neuron.connect(new)
for i in self.next_layer:
for a in i.neurons:
new.connect(a)
for k in self.prev_layer:
for b in k.neurons:
b.connect(new)
self.history.append([1, `new`])
return True
"""
Удаление нейрона из слоя с ограничением на минимальное количество нейронов в слое
"""
def delete_neuron(self, neuron):
if len(self.neurons) <= MIN_NUM_OF_NEURONS:
return False
# try:
self.alpha_neuron.disconnect(neuron)
for i in self.prev_layer:
for j in i.neurons:
del j.axon[neuron]
del self.neurons[self.neurons.index(neuron)]
# except Exception, e:
# return False
self.history.append(2)
return True
"""
Добавить случайный нейрон
"""
def rand_add_neuron(self):
self.add_neuron()
return True
"""
Удалить случайный нейрон
"""
def rand_del_neuron(self):
self.delete_neuron(random.choice(self.neurons))
return True
"""
Изменение параметров случайного нейрона
"""
def rand_modify_neuron(self, tp):
random.choice(self.neurons).modify(tp)
self.history.append(3)
return True
# def connect_neuron(self,neuron):
# for i in self.neurons:
# i.connect(neuron)
# self.alpha_neuron.connect(neuron)
# return True
"""
Отработка всех нейронов в слое
#.........这里部分代码省略.........