Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pybrain LSTM层的激活为零_Python_Pybrain_Lstm - Fatal编程技术网

Python pybrain LSTM层的激活为零

Python pybrain LSTM层的激活为零,python,pybrain,lstm,Python,Pybrain,Lstm,我构建了一个LSTM网络来对序列数据进行回归。当我试图激活隐藏层(LSTM层)时,它返回零。网络只有一个隐藏层、一个输入层和一个输出层 我尝试使用以下代码片段获取隐藏层的值 print net.activate(data) print net['in'].outputbuffer[net['in'].offset] print net['hidden0'].outputbuffer[net['hidden0'].offset] 知道为什么吗?下面是一个更完整的代码片段 RopewayIn =

我构建了一个LSTM网络来对序列数据进行回归。当我试图激活隐藏层(LSTM层)时,它返回零。网络只有一个隐藏层、一个输入层和一个输出层

我尝试使用以下代码片段获取隐藏层的值

print net.activate(data)
print net['in'].outputbuffer[net['in'].offset]
print net['hidden0'].outputbuffer[net['hidden0'].offset]
知道为什么吗?下面是一个更完整的代码片段

RopewayIn = RopewayOverallData[:-1, :]
RopewayOut = RopewayOverallData[1:, :]
ds.newSequence()
for i in range(noDataFrames):
    ds.appendLinked( [RopewayIn[i,0],RopewayIn[i,1], RopewayIn[i,2], RopewayIn[i,3], RopewayIn[i,4], RopewayIn[i,5], RopewayIn[i,6], RopewayIn[i,7], RopewayIn[i,8], RopewayIn[i,9]], 
                     [RopewayOut[i,0],RopewayOut[i,1], RopewayOut[i,2], RopewayOut[i,3], RopewayOut[i,4], RopewayOut[i,5], RopewayOut[i,6], RopewayOut[i,7], RopewayOut[i,8], RopewayOut[i,9]] )

net = buildNetwork(10,20,10, hiddenclass=LSTMLayer,outclass=LinearLayer, bias=True, recurrent=True) 
trainer = RPropMinusTrainer(net, dataset=ds, verbose=True, weightdecay=0.01)

for i in range(10001):
     trainer.trainEpochs(2)

print net.activate(RopewayOverallData[0,4])
print net['in'].outputbuffer[net['in'].offset]
print net['hidden0'].outputbuffer[net['hidden0'].offset

这不是一个真正的答案,但它不适合在评论。我试着运行这个,混合了您的代码和前面的问题():

从pybrain.tools.shortcuts导入buildNetwork
从pybrain.dataset导入受监控的数据集
从pybrain.supervised.trainers导入BackpropTrainer
从pybrain.structure.modules导入LSTMLayer、LinearLayer
net=buildNetwork(3,3,3,hiddenclass=LSTMLayer,outclass=LinearLayer,bias=True,returnal=True)
数据集=受监控的数据集(3,3)
addSample((0,0,0),(0,0,0))
addSample((1,1,1),(0,0,0))
addSample((1,0,0)、(1,0,0))
addSample((0,1,0),(0,1,0))
addSample((0,0,1),(0,0,1))
培训师=BackpropTrainer(网络,数据集)
训练=错误
可接受误差=0.001
howmanytries=0
#训练,直到达到可接受的误差
而(训练==错误)和(训练次数<1000):
错误=trainer.train()
如果错误<可接受错误:
训练=正确
其他:
多少个系列+=1
结果=净激活([0.5,0.4,0.7])
净['in'].outputbuffer[net['in'].offset]
net['hidden0'].outputbuffer[net['hidden0'].offset]
打印结果

…它打印出了非常好的非零结果。我会从这里开始,一块一块地修改代码,看看它在哪里停止工作。

更多信息会有所帮助。这是什么较大的代码部分?网络是否正常工作,这只是你打印隐藏层激活的能力有问题吗?网络正常工作,但当我打印隐藏层激活时,它给出了一个零字符串。在这段代码中,你打印的是结果变量,即输出激活。试着用打印网['hidden0']打印hidden0值。outputbuffer[net['hidden0'].offset]我所有的都是打印出来的零。把这个放在上面代码的顶部:导入pprint…然后放在底部:pp=pprint.PrettyPrinter(indent=4)pp.pprint(net['hidden0'])。\uu dict\uuu…看看你得到了什么。我不熟悉LSTMLayer类的所有内容,但是其中有很多非零值。也许补偿并不是你真正想要的。例如,outputbuffer实际上是一个包含两个列表的列表,第一个列表非常非零。很抱歉,这并不是一个真正的答案,但它表明隐藏层中存在大量非零数据。狩猎快乐!
from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.modules import LSTMLayer,LinearLayer

net = buildNetwork(3,3,3, hiddenclass=LSTMLayer,outclass=LinearLayer, bias=True, recurrent=True)
dataSet = SupervisedDataSet(3, 3)
dataSet.addSample((0, 0, 0), (0, 0, 0))
dataSet.addSample((1, 1, 1), (0, 0, 0))
dataSet.addSample((1, 0, 0), (1, 0, 0))
dataSet.addSample((0, 1, 0), (0, 1, 0))
dataSet.addSample((0, 0, 1), (0, 0, 1))

trainer = BackpropTrainer(net, dataSet)
trained = False
acceptableError = 0.001

howmanytries = 0
# train until acceptable error reached
while (trained == False) and (howmanytries < 1000):
    error = trainer.train()
    if error < acceptableError :
        trained = True
    else:
        howmanytries += 1

result = net.activate([0.5, 0.4, 0.7])
net['in'].outputbuffer[net['in'].offset]
net['hidden0'].outputbuffer[net['hidden0'].offset]
print result