2

So I have a ClassificationDataSet in PyBrain which I have trained with the appropriate data. Namely, the input is the following:

trainSet.addSample([0,0,0,0],[1])
trainSet.addSample([0,0,0,1],[0])
trainSet.addSample([0,0,1,0],[0])
trainSet.addSample([0,0,1,1],[1])
trainSet.addSample([0,1,0,0],[0])
trainSet.addSample([0,1,0,1],[1])
trainSet.addSample([0,1,1,0],[1])
trainSet.addSample([0,1,1,1],[0])
trainSet.addSample([1,0,0,0],[0])
trainSet.addSample([1,0,0,1],[1])

The pattern is simple. If there is an even number of 1's then the output should be 1, otherwise it is 0. I want to run the following inputs:

[1,0,0,1],[1]
[1,1,0,1],[0]
[1,0,1,1],[0]
[1,0,1,0],[1]

And see whether the neural network will recognise the pattern. As said previously, I've already trained the network. How do I validate it against the inputs above?

Thanks for your time!

user2398832
  • 177
  • 1
  • 3
  • 10

1 Answers1

5

You first have to create a network and train it on your dataset.

Then you have to use activate to get a result from your inputs and test if it matches the desired output.

One easy way to do it is:

testOutput = { [1,0,0,1] : [1], [1,1,0,1] : [0], [1,0,1,1]:[0], [1,0,1,0]:[1] }

for input, expectedOutput in testInput.items():
    output = net.activate(input)
    if output != expectedOutput:
        print "{} didn't match the desired output." 
        print "Expected {}, got {}".format(input, expectedOutput, output)
halflings
  • 1,540
  • 1
  • 13
  • 34
  • What does .activate() return? I keep getting floats and it is confusing me.. Care to explain? – user2398832 May 19 '13 at 17:36
  • Added a link to the documentation (on activate) ; I'm not a PyBrain user, currently installing the package to do a minimal test of this method. – halflings May 19 '13 at 17:48
  • Oops. I had mistaken your dataset for a network. Added some links to clarify things. – halflings May 19 '13 at 17:55
  • Hey thanks so much for your effort!!! I have already created a network and a dataset and trained the net using the dataset.. However.. I keep getting funny results.. Like [[ 0. ] [ 0.64476526] [ 0.54229964] [ 0.3103782 ]] after i call activate on those values.. can you tell me what those value mean?? – user2398832 May 19 '13 at 17:57
  • 1
    The values returned depends on the kind of networks you used. I guess some networks do some kind of interpolation between the inputs given in the dataset. (and may not return the exact data you've given them) – halflings May 19 '13 at 18:44