neurospin / pylearn-parsimony_history

Sparse and Structured Machine Learning in Python
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Rank-1 start vectors #28

Closed duboism closed 10 years ago

duboism commented 10 years ago

Hello,

The RandomStartVector class cannot generate rank 1 arrays (i.e. vectors):

from parsimony import start_vectors
rv = start_vectors.RandomStartVector()
rv.get_vector((10,))

The error comes from the maths.norm function which suppose that shape is 2 dimensional. Therefore the bug also affects OnesStartVector when using the normalise=True option. I think that other classes are safe.

As you probably know, in numpy a (10, 1) array is not exactly the same than a (10, ) array and, in some situation, the latter is more convenient so it may be useful to fix that. This is rather trivial.

tomlof commented 10 years ago

Good catch! I'll fix this.

However, note that the package currently assumes that all vectors have shape (n, 1), so the start_vectors module should really only take an integer argument, n, that is the number of elements in the vector.

Another thing: The start_vectors module is in the wrong place, it should not be in the root of the library. Should we put it in the utils package?

tomlof commented 10 years ago

I fixed this. Now the start vectors only take a number of variables, size, and return a vector of shape (size, 1).

I also moved the start vectors to utils.