Multidimensional matrix

View: New views
8 Messages — Rating Filter:   Alert me  

Multidimensional matrix

by Alberto Frigerio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone, I've some questions about multidimensional matrix.

*) It is possible to create (maybe using a list) a multidimensional matrix A, i.e. every element of A is not a number but a couple, triplet, etc. of numbers ?
*) How can I multiply two multidimensional matrices ?

Thanks everybody,
   Alberto

Re: Multidimensional matrix

by Carlo de Falco-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:

>
> Hi everyone, I've some questions about multidimensional matrix.
>
> *) It is possible to create (maybe using a list) a multidimensional  
> matrix
> A, i.e. every element of A is not a number but a couple, triplet,  
> etc. of
> numbers ?
you could use a multi-index matrix

A = rand (2,4,5);
A (:,2,4)

or a cell-array of matrices

for ii=1:4
for jj=1:5
A{ii,jj} = rand(3,1);
endfor
endfor

A {2,4}

> *) How can I multiply two multidimensional matrices ?

in the second case you could use
cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)

> Thanks everybody,
>   Alberto
c.
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by David Grundberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alberto Frigerio wrote:

> Hi everyone, I've some questions about multidimensional matrix.
>
> *) It is possible to create (maybe using a list) a multidimensional matrix
> A, i.e. every element of A is not a number but a couple, triplet, etc. of
> numbers ?
> *) How can I multiply two multidimensional matrices ?
>
> Thanks everybody,
>    Alberto
>  

To create 3x3x8 double matrices, use something like:

A = [1 2 3; 4 5 6; 7 8 9];
A = repmat(A, [1, 1, 8]);
A

B = eye(3);
B = repmat(B, [1, 1, 8]);
# To make it more interesting, use indexing to change certain elements:
B(2,:,1:2) = 10;
B(2,:,3:4) = 100;
B(1,[1 3],5:6) = 1000;
B(1,[1 3],7:8) = 10000;
B(2,2,1:4) = -1;
B

#And to do element multiplication you could use the .* operator:
A .* B

hth
David
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by Alberto Frigerio-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, both they seem good ideas, but I've another problem .

In my mind I would like to extend the usual matrix product using multidimensional matrix. Hence, given a (d,t,s) matrix ,V I want to find two matrices W (d,r,s1) and H (r,t,s2) so that V = W*H  (eventually s=s1=s2) .In my problem I have s=2, i.e. every element of the matrix V is a couple of elements.

2009/11/5 Carlo de Falco <carlo.defalco@...>

On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:


Hi everyone, I've some questions about multidimensional matrix.

*) It is possible to create (maybe using a list) a multidimensional matrix
A, i.e. every element of A is not a number but a couple, triplet, etc. of
numbers ?
you could use a multi-index matrix

A = rand (2,4,5);
A (:,2,4)

or a cell-array of matrices

for ii=1:4
for jj=1:5
A{ii,jj} = rand(3,1);
endfor
endfor

A {2,4}


*) How can I multiply two multidimensional matrices ?

in the second case you could use
cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)

Thanks everybody,
 Alberto
c.


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by Alberto Frigerio-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OOPS I forgot one important information.

In my mind I would like to extend the usual matrix product using multidimensional matrix. Hence, given a (d,t,s) matrix ,V I want to find two matrices W (d,r,s1) and H (r,t,s2) so that V = W*H  (eventually s=s1=s2) .In my problem I have s=2, i.e. every element of the matrix V is a couple of elements.

I could obviously take the matrices V(:,:,1) , V(:,:,2) , etc, find the corrispective Wi and Hi and then create the matrices W and H by taking W(:,:,i)=Wi and H(:,:,i)=Hi. But it would mean to work in parallel, while I introduced the second parameter in s to have a better representation of V by W and H.


2009/11/5 Carlo de Falco <carlo.defalco@...>

On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:


Hi everyone, I've some questions about multidimensional matrix.

*) It is possible to create (maybe using a list) a multidimensional matrix
A, i.e. every element of A is not a number but a couple, triplet, etc. of
numbers ?
you could use a multi-index matrix

A = rand (2,4,5);
A (:,2,4)

or a cell-array of matrices

for ii=1:4
for jj=1:5
A{ii,jj} = rand(3,1);
endfor
endfor

A {2,4}


*) How can I multiply two multidimensional matrices ?

in the second case you could use
cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)

Thanks everybody,
 Alberto
c.


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by David Grundberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have absolutely no idea what you are trying to say. Your idea of
"multiplication" is not something I recognize as multiplication.

Also, if you want to find W and H given V, it is misleading to say that
you are "extending the usual matrix product".


Alberto Frigerio wrote:

> OOPS I forgot one important information.
>
> In my mind I would like to extend the usual matrix product using
> multidimensional matrix. Hence, given a (d,t,s) matrix ,V I want to
> find two matrices W (d,r,s1) and H (r,t,s2) so that V = W*H  
> (eventually s=s1=s2) .In my problem I have s=2, i.e. every element of
> the matrix V is a couple of elements.
>
> I could obviously take the matrices V(:,:,1) , V(:,:,2) , etc, find
> the corrispective Wi and Hi and then create the matrices W and H by
> taking W(:,:,i)=Wi and H(:,:,i)=Hi. But it would mean to work in
> parallel, while I introduced the second parameter in s to have a
> better representation of V by W and H.
>
>
> 2009/11/5 Carlo de Falco <carlo.defalco@...
> <mailto:carlo.defalco@...>>
>
>
>     On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:
>
>
>         Hi everyone, I've some questions about multidimensional matrix.
>
>         *) It is possible to create (maybe using a list) a
>         multidimensional matrix
>         A, i.e. every element of A is not a number but a couple,
>         triplet, etc. of
>         numbers ?
>
>     you could use a multi-index matrix
>
>     A = rand (2,4,5);
>     A (:,2,4)
>
>     or a cell-array of matrices
>
>     for ii=1:4
>     for jj=1:5
>     A{ii,jj} = rand(3,1);
>     endfor
>     endfor
>
>     A {2,4}
>
>
>         *) How can I multiply two multidimensional matrices ?
>
>
>     in the second case you could use
>     cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)
>
>         Thanks everybody,
>          Alberto
>
>     c.
>
>

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by Alberto Frigerio-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK, you are right, I explained the problem in a terrible way. Let's restart with "usual" matrices.

I have a matrix V (sive(V)=[d,t]) of positive elements and, using an iterative algorithm, I found its non negative matrix factorization, V = W*H, where size(W)= [d,r] and size(H)=[r,t]. What I want now to do is improving the same thing for a multidimensional matrix.

Hence, if size(V)=[d,t,s] I wanna find two matrices W and H such as V = W*H . My first idea was to consider V(:,:,1) , to find W1 and H1 such as V(:,:,1)=W1*H1 with my algorithm, and then to repeat it for V(:,:,2) , V(:,:,3) , etc . At the end I will consider W={W1,W2,W3, etc.} and H={H1,H2,H3, etc.} .
But in this way I will consider V(:,:,1) , V(:,:,2) ,... as completely indipendent matrices, but it is not true. What I would like to do is to find the matrices W and H using, at the same time, all the V(:,:,i)'s. I don't know if I'm talking about something possible or not, it is just an idea I had yesterday looking at my algorithm ...

Hope I explained the problem in a better way!!!!!


2009/11/5 David Grundberg <individ@...>
I have absolutely no idea what you are trying to say. Your idea of "multiplication" is not something I recognize as multiplication.

Also, if you want to find W and H given V, it is misleading to say that you are "extending the usual matrix product".


Alberto Frigerio wrote:
OOPS I forgot one important information.

In my mind I would like to extend the usual matrix product using multidimensional matrix. Hence, given a (d,t,s) matrix ,V I want to find two matrices W (d,r,s1) and H (r,t,s2) so that V = W*H  (eventually s=s1=s2) .In my problem I have s=2, i.e. every element of the matrix V is a couple of elements.

I could obviously take the matrices V(:,:,1) , V(:,:,2) , etc, find the corrispective Wi and Hi and then create the matrices W and H by taking W(:,:,i)=Wi and H(:,:,i)=Hi. But it would mean to work in parallel, while I introduced the second parameter in s to have a better representation of V by W and H.


2009/11/5 Carlo de Falco <carlo.defalco@... <mailto:carlo.defalco@...>>



   On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:


       Hi everyone, I've some questions about multidimensional matrix.

       *) It is possible to create (maybe using a list) a
       multidimensional matrix
       A, i.e. every element of A is not a number but a couple,
       triplet, etc. of
       numbers ?

   you could use a multi-index matrix

   A = rand (2,4,5);
   A (:,2,4)

   or a cell-array of matrices

   for ii=1:4
   for jj=1:5
   A{ii,jj} = rand(3,1);
   endfor
   endfor

   A {2,4}


       *) How can I multiply two multidimensional matrices ?


   in the second case you could use
   cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)

       Thanks everybody,
        Alberto

   c.





_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Multidimensional matrix

by David Grundberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your solution sounds reasonable to me. When the matrices are
independent, it doesn't matter in what order they are calculated.

Alberto Frigerio wrote:

> OK, you are right, I explained the problem in a terrible way. Let's
> restart with "usual" matrices.
>
> I have a matrix V (sive(V)=[d,t]) of positive elements and, using an
> iterative algorithm, I found its non negative matrix factorization, V
> = W*H, where size(W)= [d,r] and size(H)=[r,t]. What I want now to do
> is improving the same thing for a multidimensional matrix.
>
> Hence, if size(V)=[d,t,s] I wanna find two matrices W and H such as V
> = W*H . My first idea was to consider V(:,:,1) , to find W1 and H1
> such as V(:,:,1)=W1*H1 with my algorithm, and then to repeat it for
> V(:,:,2) , V(:,:,3) , etc . At the end I will consider W={W1,W2,W3,
> etc.} and H={H1,H2,H3, etc.} .
> But in this way I will consider V(:,:,1) , V(:,:,2) ,... as completely
> indipendent matrices, but it is not true. What I would like to do is
> to find the matrices W and H using, at the same time, all the
> V(:,:,i)'s. I don't know if I'm talking about something possible or
> not, it is just an idea I had yesterday looking at my algorithm ...
>
> Hope I explained the problem in a better way!!!!!
>
>
> 2009/11/5 David Grundberg <individ@... <mailto:individ@...>>
>
>     I have absolutely no idea what you are trying to say. Your idea of
>     "multiplication" is not something I recognize as multiplication.
>
>     Also, if you want to find W and H given V, it is misleading to say
>     that you are "extending the usual matrix product".
>
>
>     Alberto Frigerio wrote:
>
>         OOPS I forgot one important information.
>
>         In my mind I would like to extend the usual matrix product
>         using multidimensional matrix. Hence, given a (d,t,s) matrix
>         ,V I want to find two matrices W (d,r,s1) and H (r,t,s2) so
>         that V = W*H  (eventually s=s1=s2) .In my problem I have s=2,
>         i.e. every element of the matrix V is a couple of elements.
>
>         I could obviously take the matrices V(:,:,1) , V(:,:,2) , etc,
>         find the corrispective Wi and Hi and then create the matrices
>         W and H by taking W(:,:,i)=Wi and H(:,:,i)=Hi. But it would
>         mean to work in parallel, while I introduced the second
>         parameter in s to have a better representation of V by W and H.
>
>
>         2009/11/5 Carlo de Falco <carlo.defalco@...
>         <mailto:carlo.defalco@...>
>         <mailto:carlo.defalco@...
>         <mailto:carlo.defalco@...>>>
>
>
>
>            On 5 Nov 2009, at 10:35, Alberto Frigerio wrote:
>
>
>                Hi everyone, I've some questions about multidimensional
>         matrix.
>
>                *) It is possible to create (maybe using a list) a
>                multidimensional matrix
>                A, i.e. every element of A is not a number but a couple,
>                triplet, etc. of
>                numbers ?
>
>            you could use a multi-index matrix
>
>            A = rand (2,4,5);
>            A (:,2,4)
>
>            or a cell-array of matrices
>
>            for ii=1:4
>            for jj=1:5
>            A{ii,jj} = rand(3,1);
>            endfor
>            endfor
>
>            A {2,4}
>
>
>                *) How can I multiply two multidimensional matrices ?
>
>
>            in the second case you could use
>            cellfun (@(x,y) (x'*y), A, A, 'UniformOutput', false)
>
>                Thanks everybody,
>                 Alberto
>
>            c.
>
>
>
>

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave