我試圖做一個神經網絡,我有幾個問題:神經網絡雙曲線函數
我的雙曲線函數是像一些
s = 1/(1+(2.7183**(-self.values)))
if s > self.weight:
self.value = 1
else:
self.value = 0
的self.values是的一個陣列連接的節點,例如HL(隱藏層)1中的HN(隱藏節點)連接到所有輸入節點,所以它是self.values是sum(inputnodes.values)。
在HL2的HNS連接到在所有HL1 HNS,它的self.values是總和(HL.values)
的問題是,每個節點是越來越1的值,沒有馬瑟它們的權重(除非它是太高了,像0.90〜0.99)
我的神經網絡的設置,像這樣:
(輸入,num_hidden_layers,num_hidden_nodes_per_layer,num_output_nodes) 輸入的二進制值的列表:
下面是顯示此行爲的日誌。
>>NeuralNetwork([1,0,1,1,1,0,0],3,3,1)# 3 layers, 3 nodes each, 1 output
Layer1
Node: y1 Sum: 4, Sigmoid: 0.98, Weight: 0.10, self.value: 1
Node: y2 Sum: 4, Sigmoid: 0.98, Weight: 0.59, self.value: 1
Node: y3 Sum: 4, Sigmoid: 0.98, Weight: 0.74, self.value: 1
Layer2
Node: y1 Sum: 3, Sigmoid: 0.95, Weight: 0.30, self.value: 1
Node: y2 Sum: 3, Sigmoid: 0.95, Weight: 0.37, self.value: 1
Node: y3 Sum: 3, Sigmoid: 0.95, Weight: 0.80, self.value: 1
Layer3
Node: y1 Sum: 3, Sigmoid: 0.95, Weight: 0.70, self.value: 1
Node: y2 Sum: 3, Sigmoid: 0.95, Weight: 0.56, self.value: 1
Node: y3 Sum: 3, Sigmoid: 0.95, Weight: 0.28, self.value: 1
即使我嘗試輸入使用浮動點原來是一樣的:在三層
>>NeuralNetwork([0.64, 0.57, 0.59, 0.87, 0.56],3,3,1)
Layer1
Node: y1 Sum: 3.23, Sigmoid: 0.96, Weight: 0.77, self.value: 1
Node: y2 Sum: 3.23, Sigmoid: 0.96, Weight: 0.45, self.value: 1
Node: y3 Sum: 3.23, Sigmoid: 0.96, Weight: 0.83, self.value: 1
Layer2
Node: y1 Sum: 3, Sigmoid: 0.95, Weight: 0.26, self.value: 1
Node: y2 Sum: 3, Sigmoid: 0.95, Weight: 0.39, self.value: 1
Node: y3 Sum: 3, Sigmoid: 0.95, Weight: 0.53, self.value: 1
Layer3
Node: y1 Sum: 3, Sigmoid: 0.95, Weight: 0.43, self.value: 1
Node: y2 Sum: 3, Sigmoid: 0.95, Weight: 0.52, self.value: 1
Node: y3 Sum: 3, Sigmoid: 0.95, Weight: 0.96, self.value: 0
注德節點Y3,即乙狀結腸後返回一個0,唯一的一個
我做錯了什麼?
此外,是否真的有必要將每個節點與上一層中的每個其他節點連接起來?讓它變得隨機是不是更好?
編輯: 忘了提及,這是一個正在開發的NN,我將使用遺傳算法來訓練網絡。
EDIT2:
class NeuralNetwork:
def __init__(self, inputs, num_hidden_layers, num_hidden_nodes_per_layer, num_output):
self.input_nodes = inputs
self.num_inputs = len(inputs)
self.num_hidden_layers = num_hidden_layers
self.num_hidden_nodes_per_layer = num_hidden_nodes_per_layer
self.num_output = num_output
self.createNodes()
self.weights = self.getWeights()
self.connectNodes()
self.updateNodes()
def createNodes(self):
self._input_nodes = []
for i, v in enumerate(self.input_nodes):
node = InputNode("x"+str(i+1),v)
self._input_nodes.append(node)
self._hidden_layers = []
for n in xrange(self.num_hidden_layers):
layer = HiddenLayer("Layer"+str(n+1),self.num_hidden_nodes_per_layer)
self._hidden_layers.append(layer)
def getWeights(self):
weights = []
for node in self._input_nodes:
weights.append(node.weight)
for layer in self._hidden_layers:
for node in layer.hidden_nodes:
weights.append(node.weight)
return weights
def connectNodes(self):
for i,layer in enumerate(self._hidden_layers):
for hidden_node in layer.hidden_nodes:
if i == 0:
for input_node in self._input_nodes:
hidden_node.connections.append(input_node)
else:
for previous_node in self._hidden_layers[i-1].hidden_nodes:
hidden_node.connections.append(previous_node)
def updateNodes(self):
for layer in self._hidden_layers:
for node in layer.hidden_nodes:
node.updateValue()
而這裏的節點updateValue()方法:
def updateValue(self):
value = 0
for node in self.connections:
value += node.value
self.sigmoid(value) # the function at the beginning of the question.
剛剛創建的節點有值,名稱和重量(隨機開始)。
請發佈您的'NeuralNetwork'的實現。 – Pradhan
看起來你並沒有對每個節點的單獨輸入進行加權。此外,您通常不會對隱藏圖層輸出進行閾值處理(我知道這一點),但我不確定在使用GA進行訓練時它將如何改變內容。 – AMacK
哦,該死的......我一直在這裏抨擊我幾個小時,因爲我忘記了這個小細節。 –