本文整理汇总了Python中layer.Layer.set_input方法的典型用法代码示例。如果您正苦于以下问题:Python Layer.set_input方法的具体用法?Python Layer.set_input怎么用?Python Layer.set_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layer.Layer
的用法示例。
在下文中一共展示了Layer.set_input方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NeuroNet
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import set_input [as 别名]
class NeuroNet(object):
"""network over neurons"""
def __init__(self, input_num, output_num, lnum=3, delta=0):
super(NeuroNet, self).__init__()
self.input_layer = Layer(input_num)
self.output_layer = Layer(output_num)
self.layers = [Layer()]
self.connect_layers(self.input_layer, self.layers[0])
for i in xrange(lnum - 1):
self.layers.append(Layer())
self.connect_layers(self.layers[-2], self.layers[-1])
self.connect_layers(self.layers[-1], self.output_layer)
for i in self.layers:
i.modify(-1)
# for i in i.neurons:
# print i
self.set_input_delta(delta)
def set_input(self, inp_arr):
self.input_layer.set_input(inp_arr)
# return False
def calculate(self, steps=10):
for i in xrange(steps):
self.input_layer.calculate()
for j in self.layers:
j.calculate()
self.output_layer.calculate()
return self.output_layer.get_value()
"""
Соединить два слоя последовательно
"""
def connect_layers(self, l1, l2):
l1.connect(l2)
return True
"""
Добавить новый слой между двумя существующими, заданных индексами позиции
"""
def add_layer_indx(self, layer=None, prev_layer_indx=0, next_layer_indx=0):
# if len(self.layers) >= MAX_LAYERS_NUM:
# return False
if not (0 <= prev_layer_indx < len(self.layers) and 0 <= next_layer_indx < len(self.layers)):
return False
# if layer == None:
# layer = Layer(next = self.layers[next_layer_indx])
# self.layers.append(layer)
# self.connect_layers(self.layers[prev_layer_indx],layer)
self.add_layer(layer, self.layers[prev_layer_indx], self.layers[next_layer_indx])
return True
"""
Добавить слой в случайное место
"""
def rand_add_layer_indx(self, layer=None, np=0): # 0 - both, 1 - only directly, 2 - only backward
if len(self.layers) < 2:
pli = self.layers
pli, nli = random.sample(range(len(self.layers)), 2)
if ((np == 1) and (nli < pli)) or ((np == 2) and (nli > pli)):
pli, nli = nli, pli
self.add_layer_indx(layer, pli, nli)
return True
"""
Добавить слой между двумя заданными слоями, заданных объектами (main)
"""
def add_layer(self, layer=None, prev_layer=None, next_layer=None):
if len(self.layers) >= MAX_LAYERS_NUM:
return False
if (prev_layer is None) or (next_layer is None):
return False
if layer == None:
layer = Layer(next=next_layer)
else:
if (next_layer in layer.next_layer) or (prev_layer in layer.prev_layer):
print 'DA',
return False
self.layers.append(layer)
self.connect_layers(prev_layer, layer)
layer.modify(-1) # add random weight
return True
"""
Получить слой из общей карты слоев, включая:
- входной (0);
- промежуточные (1..n);
- выходной (n+1); """
def get_layer(self, num):
if num == 0:
return self.input_layer
if num == len(self.layers) + 1:
#.........这里部分代码省略.........