[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Abdel Rahmen El Lahga" <rahmen.lahga@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: Re: st: re: interaction of column matrix |

Date |
Fri, 19 Oct 2007 18:00:42 +0200 |

Thanks to Nick Cox for his correction. AbdelRahmen 2007/10/19, n j cox <n.j.cox@durham.ac.uk>: > My reaction was like Kit's: in my ignorance > I had not heard of horizontal direct products, > and wondered about any connection to Kronecker. > > No matter. Abdel has working code, and his > approach is likely to be as direct as any other. > I think his code can be tweaked, although the > changes are essentially cosmetic. I would write: > > real matrix hdp(real matrix A, real matrix B) > { > assert(rows(A) == rows(B)) > real matrix C > C = J(rows(A), 0, .) > for (i = 1; i <= cols(A); i++) { > C = C, (A[, i] :* B) > } > return(C) > } > > What's different? Not much. > > 0. Style. I like to put spaces around most binary operators > and after commas, if there is space to spare. 100% of the publications > on Stata style agree. However, no spaces around * and / can be > good style, to indicate binding. > > 1. You don't need to declare n, which is used only once. > > 2. The cutest, and this is due to Bill Gould, not me, is > to initialise with a matrix of 0 columns. That way, you > need take away nothing (or, more precisely, need not take away > anything) at the end. > > I can't see a reason why this could not be generalised to > complex matrices. An official program would be more informative > if the -assert- failed. > > I presume there is a vertical direct product, and I guess > that in practice it is even less used. > > Abdel replied to Kit Baum who replied to Abdel Rahmen El Lahga > > > I've never heard of a 'horizontal direct product' but in a 2x2 > > example it seems to be the first and last rows of a conventional > > Kronecker product... > > the term "horizontal direct product" is used in Gauss manual ( and R i > think) and denoted by the operator > " *~ " and is different from the kronecker product in Gauss denoted by " > .*. " > You are right when tou say that "it appears that whatever this > construction might be it > > could be generated from a Kronecker" but the question is how to > automate such task in Mata. You know that with matrix A(k,l), B(m,n) ; > A#B =C(k*m,l*n) but here we want a new matrix C(k,l*n) asumming that > k=m. Hence my motivation to write my hdp() function > AbdelRahmen > > 2007/10/19, Kit Baum <kitbaum@mac.com>: > > Abdel wrote > > > > I've written this mata function as a solution to my own question > > yesterday. > > horizontal direct product (hdp). > > --------begin code------------ > > version 9.2 > > local mydir "." > > mata: > > mata clear > > real matrix hdp(real matrix A, real matrix B) > > { > > assert(rows(A)==rows(B)) > > real scalar n > > real matrix C > > n=rows(A) > > C=J(n,1,.) > > for (i=1; i<=cols(A); i++) { > > C=C,(A[.,i]:*B) > > } > > C=C[.,2..cols(C)] > > return(C) > > } > > > > > > I've never heard of a 'horizontal direct product' but in a 2x2 > > example it seems to be the first and last rows of a conventional > > Kronecker product: > > > > : a > > 1 2 > > +---------+ > > 1 | 1 2 | > > 2 | 3 4 | > > +---------+ > > > > : b > > 1 2 > > +---------+ > > 1 | 5 6 | > > 2 | 0 1 | > > +---------+ > > > > : c > > 1 2 3 4 > > +---------------------+ > > 1 | 5 6 10 12 | > > 2 | 0 3 0 4 | > > +---------------------+ > > > > : a#b > > 1 2 3 4 > > +---------------------+ > > 1 | 5 6 10 12 | > > 2 | 0 1 0 2 | > > 3 | 15 18 20 24 | > > 4 | 0 3 0 4 | > > +---------------------+ > > > > > > For a 3x3 example, it is the 1st, 5th and 9th rows of the Kronecker > > product. Thus it appears that whatever this construction might be it > > could be generated from a Kronecker. > > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > -- AbdelRahmen El Lahga * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: Re: st: re: interaction of column matrix***From:*n j cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: weighted scatter / different label size** - Next by Date:
**st: CI for adjusted mean** - Previous by thread:
**Re: Re: st: re: interaction of column matrix** - Next by thread:
**st: Before and After Pairwise Plots** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |