activation values for all nodes in a PyBrain network

我们两清 提交于 2019-11-30 08:32:34

问题


I feel like this should be trivial, but I've struggled to find anything useful in the PyBrain documentation, on here, or elsewhere.

The problem is this :

I have a three layer (input, hidden, output) feedforward network built and trained in PyBrain. Each layer has three nodes. I want to activate the network with novel inputs and store the resultant activation values of the nodes at the hidden layer. As far as I can tell, net.activate() and net.activateOnDataset() will only return the activation values of output layer nodes and are the only ways to activate a network.

How do I get at the hidden layer activations of a PyBrain network?

I'm not sure example code will help that much in this case, but here's some anyway (with a cut-down training set) :

from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer

net = buildNetwork(3, 3, 3)

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

# train until acceptable error reached
while trained == False :
    error = trainer.train()
    if error < acceptableError :
        trained = True

result = net.activate([0.5, 0.4, 0.7])
print result

In this case, desired functionality is to print a list of the hidden layer's activation values.


回答1:


It looks like this should work:

net['in'].outputbuffer[net['in'].offset]
net['hidden0'].outputbuffer[net['hidden0'].offset]

Purely based on looking at the source code.



来源:https://stackoverflow.com/questions/12436311/activation-values-for-all-nodes-in-a-pybrain-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!