3

I´m using pybrain in order to train a simple neural network in which the input is going to be a 7x5 Matrix.

The following are the inputs:

    A = [[0, 0, 1, 0, 0],
    [0, 1, 1, 0, 0],
    [0, 1, 0, 1, 0],
    [0, 1, 0, 1, 0],
    [1, 1, 1, 1, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1]]

E = [[1, 1, 1, 1, 1],
    [1, 0, 0, 0, 0],
    [1, 0, 0, 0, 0],
    [1, 1, 1, 1, 0],
    [1, 0, 0, 0, 0],
    [1, 0, 0, 0, 0],
    [1, 1, 1, 1, 1]]
I = [[0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0]]

O = [[1, 1, 1, 1, 0],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 1, 1, 1, 0]]

U = [[1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 0, 1],
    [0, 1, 0, 0, 1],
    [0, 0, 1, 1, 0]]

I thought writing something like:

ds = SupervisedDataSet(1, 1)
ds.addSample((A), ("A",))

might work, but I´m getting:

ValueError: cannot copy sequence with size 7 to array axis with dimension 1

Is there any way I can give this datasets to pyBrain?

Pablo Estrada
  • 3,182
  • 4
  • 30
  • 74

1 Answers1

3

First you have to know that SupervisedDataSet works with list, so you will need to convert the 2D arrays into a list. You can do it with something like this:

def convertToList (matrix):
    list = [ y for x in matrix for y in x]
    return list

Then you will need to give the new list to the method SupervisedDataSet. Also if you would like to use that info to make the network you should use some number to identify the letter like A = 1, E = 2, I = 3, O = 4, U = 5. So to do this, the second parameter for SupervisedDataSet should be just a number 1. In this way you are saying something like "For a list with 35 elements use these numbers to identify a single number".

Finally your code should look like this:

ds = SupervisedDataSet(35, 1)

A2 = convertToList(A)
ds.addSample(A2, (1,))

E2 = convertToList(E)
ds.addSample(E2, (2,))

I2 = convertToList(I)
ds.addSample(I2, (3,))

O2 = convertToList(O)
ds.addSample(O2, (4,))

U2 = convertToList(U)
ds.addSample(U2, (5,))

Hope this could help.

Albert
  • 141
  • 3
  • 12