I have 2 variables... the number of inputs N and the length of the history M. These two variables determine the size of the matrix V which is n x m, i.e., n rows, m columns.
I have difficulties to come up with a algorithm which enables me to generate a certain amount of permutations (or sequences, how you see fit).
I would be really glad if someone could help me with a algorithm, if possible in Matlab, but a pseudo-algorithm would also be very nice.
I give you 3 examples:
- If the number of inputs is N = 1 and the length of the history is M = 2, I have (M+1)^N different combinations, in this case 3. The permutations are:
(In case you are not familiar with matlab matrix notation, ,
seperates columns, ;
seperates rows.)
V(1) = [1,0,0]
V(2) = [0,1,0]
V(3) = [0,0,1]
- If the number of inputs is N = 2 and the length of the history is M = 2, I have (M+1)^N different combinations, in this case 9.
The permutations are:
V(1) = [1,0,0; 1,0,0]
V(2) = [1,0,0; 0,1,0]
V(3) = [1,0,0; 0,0,1]
V(4) = [0,1,0; 1,0,0]
V(5) = [0,1,0; 0,1,0]
V(6) = [0,1,0; 0,0,1]
V(7) = [0,0,1; 1,0,0]
V(8) = [0,0,1; 0,1,0]
V(9) = [0,0,1; 0,0,1]
- If the number of inputs is N = 3 and the length of the history is M = 3, I have (M+1)^N different combinations, in this case 64.
The permutations are:
V(1) = [1,0,0,0; 1,0,0,0; 1,0,0,0]
V(2) = [1,0,0,0; 1,0,0,0; 0,1,0,0]
V(3) = [1,0,0,0; 1,0,0,0; 0,0,1,0]
V(4) = [1,0,0,0; 1,0,0,0; 0,0,0,1]
V(5) = [1,0,0,0; 0,1,0,0; 1,0,0,0]
...
V(8) = [1,0,0,0; 0,1,0,0; 0,0,0,1]
V(9) = [1,0,0,0; 0,0,1,0; 1,0,0,0]
...
V(16) = [1,0,0,0; 0,0,0,1; 0,0,0,1]
V(17) = [0,1,0,0; 1,0,0,0; 1,0,0,0]
...
V(64) = [0,0,0,1; 0,0,0,1; 0,0,0,1]
Edit: I just found a way to generate really large matrices W in which each row represents V(i)
For the first case:
W = eye(3)
Herein eye(k)
creates an identity matrix of size k x k
For the second case:
W = [kron(eye(3), ones(3,1)), ...
kron(ones(3,1), eye(3))]
Herein kron
is the kronecker product, and ones(k,l)
creates a matrix with ones of size k x l
For the third case:
W = [kron(kron(eye(4), ones(4,1)), ones(4,1)), ...
kron(kron(ones(4,1), eye(4)), ones(4,1)), ...
kron(kron(ones(4,1), ones(4,1)), eye(4))]
Now we have created the matrices W in which each row represents V(i) in vector form, V(i) is not yet a matrix.
Observe two things:
- When the input N is increased an extra column is added with an extra kronecker product and the identity matrix moves along the vector.
- When the length of the history M is increased the identity matrices vectors are increased, e.g., eye(4) -> eye(5), ones(4,1) -> ones(5,1).