Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError in sortModules #59

Closed
ghost opened this issue Dec 10, 2010 · 3 comments
Closed

KeyError in sortModules #59

ghost opened this issue Dec 10, 2010 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 10, 2010

I have an issue with the sortModules method throwing a KeyError.

Following the tutorial example, I created a script with the following:

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import scipy
import numpy as np

print "\nPython version: %s" % sys.version
print "Numpy version: %s" % np.version.version
print "Scipy version: %s" % scipy.version.version

from pybrain.structure import FeedForwardNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection

# Create network
nn = FeedForwardNetwork()

# Set network parameters
INPUT_NDS = 2
HIDDEN_NDS = 3
OUTPUT_NDS = 1

# Create Feed Forward Network layers
inLayer = LinearLayer(INPUT_NDS)
hiddenLayer = SigmoidLayer(HIDDEN_NDS)
outLayer = LinearLayer(OUTPUT_NDS)

# Fully connect all layers
in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)

# Add the connected layers to the network 
nn.addConnection(in_to_hidden)
nn.addConnection(hidden_to_out)

# Sort modules to prepare the NN for use
nn.sortModules()

Which gives me:
Python version: 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3]
Numpy version: 1.3.0
Scipy version: 0.7.0
Traceback (most recent call last):
File "/tmp/py7317Q6c", line 46, in
nn.sortModules()
File "/usr/local/lib/python2.6/dist-packages/PyBrain-0.3-py2.6.egg/pybrain/structure/networks/network.py", line 224, in sortModules
self._topologicalSort()
File "/usr/local/lib/python2.6/dist-packages/PyBrain-0.3-py2.6.egg/pybrain/structure/networks/network.py", line 188, in _topologicalSort
graph[c.inmod].append(c.outmod)
KeyError: <LinearLayer 'LinearLayer-3'>

I have the latest version of pybrain installed, so this seems strange. Especially as I when use the shortcut:

from pybrain.tools.shortcuts import buildNetwork
@schaul
Copy link
Collaborator

schaul commented Dec 10, 2010

You need to do nn.addModule(xLayer) for all the modules, before adding the connections.

@ghost
Copy link
Author

ghost commented Dec 10, 2010

Thanks for the quick reply.
I guess I should read the documentation a little more closely!
Sorry for the noob question and thanks for your help!

@schaul
Copy link
Collaborator

schaul commented Dec 10, 2010

You're welcome!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant