Discussion:
[theano-users] Is there a Theano operation for generating the set of all permutations of a vector?
Alexander Farley
2017-08-07 23:20:55 UTC
Permalink
I would like to define a Theano operation taking this vector:

[1,2,3]

To this array:

[[1,2,3],
[1,3,2],
[2,3,1],
[2,1,3],
[3,1,2],
[3,2,1]]

The problem I'm having is that while I can get the correct result using
numpy operations and arrays, I'm having trouble converting to Theano
operations. In numpy, I get the correct result using itertools.permutations:

np.array(list(itertools.permutations(x)))

However, if I swap in a Theano vector X as the argument:

X = T.vector()
np.array(list(itertools.permutations(X)))

then I get an error:
ValueError: length is not known

I think what's happening is that X is symbolic so it can't be evaluated by
itertools.permutations. Is there a simple way to do this in Theano or do I
have to construct the set of permutations from lower-level operations?
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alexander Farley
2017-08-08 02:42:54 UTC
Permalink
Ok, figured it out - the trick was to define a generic permutation-applying
function in theano, and generate the specific list of every permutation at
runtime in numpy. The actual list of permutations is then passed in as a
parameter to Theano, rather than being calculated from within Theano.
Post by Alexander Farley
[1,2,3]
[[1,2,3],
[1,3,2],
[2,3,1],
[2,1,3],
[3,1,2],
[3,2,1]]
The problem I'm having is that while I can get the correct result using
numpy operations and arrays, I'm having trouble converting to Theano
np.array(list(itertools.permutations(x)))
X = T.vector()
np.array(list(itertools.permutations(X)))
ValueError: length is not known
I think what's happening is that X is symbolic so it can't be evaluated by
itertools.permutations. Is there a simple way to do this in Theano or do I
have to construct the set of permutations from lower-level operations?
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...