2014-04-28 84 views
2

我意識到newff輸出固定在範圍[-1,1],我做了以下測試,應該如何輸出範圍外的工作。Neurolab newff輸出範圍和來自網絡的不同結果

import neurolab as nl 
import numpy as np 

# Create train samples 
x = np.linspace(-7, 7, 20) 
y = x * 10 

size = len(x) 

inp = x.reshape(size,1) 
tar = y.reshape(size,1) 

norm_inp = nl.tool.Norm(inp) 
inp = norm_inp(inp) 

norm_tar = nl.tool.Norm(tar) 
tar = norm_tar(tar) 

# Create network with 2 layers and random initialized 
# as I normalized the inp, the input range is set to [0, 1] (BTW, I don't know how 
#to norm it to [-1, 1]) 
net = nl.net.newff([[0, 1]],[5, 1]) 

# Train network 
error = net.train(inp, tar, epochs=500, show=100, goal=0.02) 

# Simulate network 
out = norm_tar.renorm(net.sim([[ 0.21052632 ]])) 

print "final output:-----------------" 
print out 

inp before norm 
[[-7.  ] 
[-6.26315789] 
[-5.52631579] 
[-4.78947368] 
[-4.05263158] 
[-3.31578947] 
[-2.57894737] 
[-1.84210526] 
[-1.10526316] 
[-0.36842105] 
[ 0.36842105] 
[ 1.10526316] 
[ 1.84210526] 
[ 2.57894737] 
[ 3.31578947] 
[ 4.05263158] 
[ 4.78947368] 
[ 5.52631579] 
[ 6.26315789] 
[ 7.  ]] 

tar before norm 
[[-70.  ] 
[-62.63157895] 
[-55.26315789] 
[-47.89473684] 
[-40.52631579] 
[-33.15789474] 
[-25.78947368] 
[-18.42105263] 
[-11.05263158] 
[ -3.68421053] 
[ 3.68421053] 
[ 11.05263158] 
[ 18.42105263] 
[ 25.78947368] 
[ 33.15789474] 
[ 40.52631579] 
[ 47.89473684] 
[ 55.26315789] 
[ 62.63157895] 
[ 70.  ]] 

我想到了要重歸一化後,各地-40爲輸入0.21052632 但結果是不可重複的,有時是正確的(約-40),但有時是錯誤的(成爲-70)。

我很奇怪,爲什麼訓練結果並不穩定,是否有更好的方式來訓練產生的輸出值超出範圍[-1,1]

回答

1

沒有關於「newff」不同的訓練方法的神經網絡。根據library,您可以使用7種不同的火車功能。嘗試使用不同的火車功能。 Here是關於更改網絡屬性的示例。這裏是例子。

import neurolab as nl 
# Create 
net = nl.net.newff([[-1, 1]], [5, 1]) 
# Default train function (train_gdx) 
print net.trainf # Trainer(TrainGDX) 
# Change train function 
net.trainf = nl.train.train_bfgs 
+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – apaul

+0

想你@ apaul34208,這是我第一次回答一個問題。我對它做了一些改變。 –