views:

195

answers:

1

Hi all.

I'm currently trying to automatically generate a set of fuzzy rules for a set of observations which contain four values for each observation, where each observation will correspond to a state (a good example is with Fisher's Iris Data).

In Matlab I am creating a four dimensional rule table where a single cell (a,b,c,d) will contain the corresponding state. To reduce the table I am following the Hong and Lee method of row and column similarity checking but I am having difficulty understanding how to address the third and fourth dimensions' rows and columns. From the method it is my understanding that each dimension is addressed individually and if the rule is true, the table is simplified. The rules for merging are as follows:

  1. If all cells in adjacent columns or rows are the same.
  2. If two cells are the same or if either of them is empty in adjacent
    columns or rows and at least one cell in both is not empty.
  3. If all cells in a column or row are empty and if cells in its two
    adjacent columns or rows are the same, merge the three.
  4. If all cells in a column or row are empty and if cells in its two
    adjacent columns or rows are the same or either of them is empty, merge the three.
  5. If all cells in a column or row are empty and if all the non-empty
    cells in the column or row to its left have the same region, and all the non-empty cells in the column or row to its right have the same region, but one different from the previously mentioned region, merge these three columns into two parts.

Now for the confusing bit. Simply checking if the entire row/column is the same as the adjacent (rule 1) seems simple enough:

if (a,:,:,:) == (a+1,:,:,:)
   (:,b,:,:) == (:,b+1,:,:)
   (:,:,c,:) == (:,:,c+1,:)
   (:,:,:,d) == (:,:,:,d+1)

is this correct?

but to check if the elements in the row/column match, or either is zero (rules 2 and 4), I am a bit lost. Would it be something along these lines:

for a = 1:20
    for i = 1:length(b)
        if (a+1,i,:,:) == (a,i,:,:)
        ...
        else if (a+1,i,:,:) == 0
        ...
        else if (a,i,:,:) == 0      etc.

and for the third and fourth dimensions:

for c = 1:20
    for i = 1:length(a)
        if (i,:,c,:) == (i,:,c+1,:)
        ...
        else if (i,:,c+1,:) == 0
        ...
        else if (i,:,c,:) == 0      etc.

for d = 1:20
    for i = 1:length(a)
        if (i,:,:,d) == (i,:,:,d+1)
        ...
        else if (i,:,:,d+1) == 0
        ...
        else if (i,:,:,d) == 0      etc.

even any help with four dimensional arrays would be useful as I'm so confused by the thought of more than three! I would advise you look at the paper to understand my meaning - they themselves have used the Iris data but only given an example with a 2D table.

Thanks in advance, hopefully!

+1  A: 

I'm not sure if this is what you are asking, but here is how to check to see if the values in two rows are either the same as each other, or if not the same, that at least one is 0

table(a,:,:,:) == table(a+1,:,:,:) | table(a,:,:,:) == 0 | table(a+1,:,:,:) = 0;

if you want to be really clever, but somewhat cryptic,

(diff(table, [], 1) == 0) | table(1:(end-1),:,:,:) == 0 | table(2:end, :,:,:) == 0

for the first dimension

(diff(table, [], 2) == 0) | table(:,1:(end-1),:,:) == 0 | table(:,2:end, :,:) == 0

for the second, and so on

Marc
That is rather cryptic, but by the look of it it may work for this thank you. What may be a better (and simpler) question is how would I access the first element of the third and fourth dimensions, given that the first element of the first is (a,1,:,:), the second (1,b,:,:) etc?
Cate
Actually, that checks the entire row/column for it being "empty" as a whole, doesn't it? My issue is checking individual cells in the adjacent rows/columns to see if they match or if either is empty; if for the entire row/column cells either match or at least one is empty then the two rows/columns may be merged.
Cate
== does an element by element comparison, so [1 2 3 4 5] == [5 4 3 2 1] yields [0 0 1 0 0]I'm not sure what you're asking in your first comment. To access an individual element of a 4 d array, arr(i,j,k,m) to get all the elements that have the first 3 indices == i,j,k, arr(i,j,k,:). etc.
Marc
I was just saying in this matrix an empty cell holds a 0. Checking element by element == 0 will return 1 if all hold a 0, and return 0 if not. My other question needs clarification though:To access the first element of the 1stD in a 2D matrix = (1,1), the second = (1,2).To access the first element of the 2ndD in a 2D matrix = (1,1), the second = (2,1).Now if I had 3D, the first element of the 3rdD would be (1, :, 1) therefore giving all values of the 2ndD corresponding to the first row. So how do you access the first of a 4D? (1,:,:,1)? (:,1,:,1)? (:,:,1,1)? something else?Thanks
Cate
Checking element by element == 0 will return 1 if all hold a 0: no, x == 0 will return a matrix of the same size as x, with a 1 wherever x == 0 and a 0 otherwise. Try it.Call the 1st dimension the row, the 2nd dimension the column, and the 3rd dimension the plane.arr(1,:,:) returns a 2D array of elements from the first rowarr(:,1,:) returns a 2D array of elements from the first columnarr(:,:,1) returns a 2D array of elements from the first planearr(1,:,1) is a 1D vector of elements from the first row and the first plane, and so on
Marc
I have and I think I didn't make myself clear enough. if(x == 0) will check if each element of x is equal to 0 and if indeed it is, it will return a 1 and proceed with the consequence of the if statement. If not, the condition isn't met and nothing happens. This is how I check if the entire plane for that dimension is empty i.e. if(1,:,:,:)==0 etc tells me whether I can remove that row. And I can understand 3 dimensional matrices but the 4 dimensional matrix is what I am unsure of. I think maybe my question is a little too perplexing to answer succinctly!
Cate

related questions