Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: does Matlab have any such function Date: Wed, 4 Feb 2009 06:19:01 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 25 Message-ID: <gmbc0l$gbr$1@fred.mathworks.com> References: <2115737.1233628719570.JavaMail.jakarta@nitrogen.mathforum.org> <5124452.1233717244446.JavaMail.jakarta@nitrogen.mathforum.org> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1233728341 16763 172.30.248.38 (4 Feb 2009 06:19:01 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 4 Feb 2009 06:19:01 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:515890 Will <william108@gmail.com> wrote in message <5124452.1233717244446.JavaMail.jakarta@nitrogen.mathforum.org>... > As I understand it x(i,j) is the number of times the i in CL occurs in the ..... Will, I'll try to answer each of your questions. The first one is: "But the diagonal here is relevant to the first permutation of CL. Then I thought what you meant was do the next permutation of CL and form X again and then the diagonal would be relevant to that permutation. Isn't this correct?" No, that is not correct. X is formed only once, before ever entering the part where permutations are examined one-by-one. Otherwise there would be no point in computing X. The same X matrix serves for all different permutations. The picture you should have in mind is that each permutation defines some 15-element path through X in such a way that each column and each row is visited only once. There are 15 factorial such paths, an enormous number. Look at the line c = sum(X(p+(0:15:210))); and notice the p there. That is defining the path I am talking about. For example if p = [9 2 5 1 7 ....] then X(p+(0:15:210)) would be the elements X(9,1),X(2,2),X(5,3),X(1,4),X(7,5), etc. and this is some "path" winding through array X. The sum of all these terms along the path would give that particular value of the "match" count c. This is a particular "path" through matrix X which visits each row and each column just once. It represents the matching score you would get if you transformed the values in CL by that permutation: a 1 in place of 9, a 2 which remains as is, a 3 which replaces a 5, a 4 which replaces a 1, a 5 in place of the 7, etc. This is in accordance with your instruction that the actual numbering within CL is arbitrary with only the "patterns" being preserved. Perhaps you are wondering about the notation in c = sum(X(p+(0:15:210))); and in particular how the row and column numbers emerge from all of this. You should examine the matlab 'sub2ind' function which converts from a pair of subscripts into a single index. For example, in p+(0:15:210), the first value in the above example is just 9+0=9 which means row 9 and column 1. The next one is 2+15=17 which is the single index for row 2, column 2. The third one is 5+30+35 which translates to row 5, column 3. Single indices start in the upper left corner, move down the column to the bottom, and then go the top of the next column and move down again, etc. That is why in a 15 x 15 array the single index of 5+30=35 carries you over to the 5th row of the 3rd column. You also asked "Now I don't really understand the importance of the other values in X [besides the diagonals.} You seem to be suggesting that you have some way of looking at the other values of X and knowing about the other permutations but I don't understand that." The diagonals give the counts of those cases where the values in the original CL and Var match. It is only pertinent if you are considering the identity permutation - that is, no permutation at all. Remember you have stated that the values in CL were arbitrary and could be changed by a permutation among its values. The off-diagonal elements of the (unchanging) X are relevant to these other permutations. For example row 5, column 3 in X above contains the count of all the 5's in CL which are paired with 3's in Var, and this is done to handle any case where 5's have been transformed to 3's in CL, because this would then be a match such as you have defined. My advice would be to examine very carefully the simple example I gave earlier with 25000 reduced to 30 and 15 reduced to 3. It is fully representative of the larger case. Try to analyze it carefully until you can understand completely what is happening there. If you do, you will be in good shape for the larger case. Roger Stafford