• Post Reply Bookmark Topic Watch Topic
  • New Topic

No 2nd dimension in Double[][] ArrayList  RSS feed

 
shahbaaz ahmed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I can't figure out while i cant compare a second item in a double[][]. It works perfectly fine for the grades array.



Main bit:



So the grades array allows me to do grades[0] and grades[1] but i can't do this for the mins array. In the debug mode under mins I can only see mins[0] and not mins[1], but for grades I see them both there [0] and [1].

I have no idea why its doing this, I am usually exactly the same code for mins as I did for grades.

Appreciate any help.

Regards
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My, that is confusing code. It looks like code where you are guessing. You can guess 1000000× and you will probably get it right if all the guesses are different. You only have to work out which guess is right and which 999999 are wrong
Or you can work out what you want to do and get it right with one try.

Start by telling us what you want to do. Why have you got Lists of arrays rather than some other sort of Object? What does minimum mean? Why has it got two array elements? Why are you starting from 2.0? You cannot work out what to code until you have worked out what you want to do.

And welcome to the Ranch
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shahbaaz ahmed wrote:I have no idea why its doing this, I am usually exactly the same code for mins as I did for grades.

Actually you're not. Look at lines 7 and 8.

However, I have to admit to being slightly puzzled myself. If I have a lightbulb moment, I'll let you know.

That said, your code is incredibly tortuous. Why are grades and mins arrays at all, since all you ever do is reference elements by their literal indexes? Two separate named variables would seem to me a much better idea - and a LOT easier to read.

Winston
 
shahbaaz ahmed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:My, that is confusing code. It looks like code where you are guessing. You can guess 1000000× and you will probably get it right if all the guesses are different. You only have to work out which guess is right and which 999999 are wrong
Or you can work out what you want to do and get it right with one try.

Start by telling us what you want to do. Why have you got Lists of arrays rather than some other sort of Object? What does minimum mean? Why has it got two array elements? Why are you starting from 2.0? You cannot work out what to code until you have worked out what you want to do.

And welcome to the Ranch


Thank you for the warm welcome.
Yes it is confusing code lol, its part of bigger class which is a fuzzy decision classifier system.
I'll try explain.

So the arraylist ruleGrades contains a double[][] array. It contains grades which are double values. Each grade is a type-2 fuzzy set has two double values for representing two membership grades, for example [[1.2],[1.5]] so 1.2 is grade1 and 1.5 is grade2. So before we start the first for loop, ruleGrades is populated with a number of grades, the size of the array is 8. It looks like this:
[0]=[[0.0, 1.0], [0.0, 1.0]]
[1]=[[0.0, 1.0], [1.0, 0.0], [0.0, 1.0]]
[2]=[[0.0, 1.0], [1.0, 0.0], [1.0, 0.0], [1.0, 0.0]]
[3]=[[0.0, 1.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 0.0]]
[4]=[[0.0, 1.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0], [0.0, 1.0]]
[5]=[[1.0, 0.0], [1.0, 0.0]]
[6]=[[1.0, 0.0], [0.0, 1.0], [1.0, 0.0]]
[7]=[[1.0, 0.0], [0.0, 1.0], [0.0, 1.0]]

Now the purpose of the min arrayList is to get the minimum of each of those grades, so [0.0,1.0] is the set which is going to be the minimum for all of them. But then a probability is used and multiplied, so we'll have different values. After going through the ruleGrades loop, the min array looks like this:
[0]=[[0.0], [0.951]]
[1]=[[0.0], [0.966]]
[2]=[[1.0], [0.0]]
[3]=[[0.744], [0.0]]
[4]=[[0.0], [0.769]]
[5]=[[0.861], [0.0]]
[6]=[[0.699], [0.0]]
[7]=[[0.0], [0.85]]

Now I want to get the MAX set which is [1.0],[0.0] and store that in a variable called max which will used later. And this is where i get the error.

I hope that makes some sense, I am not a great coder so there certainly is a better way to do this but I don't have much time as i have made this system for a research project at uni and atm i just need to get it working asap so i can run some experiments.

Appreciate any help.
kind regards
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shahbaaz ahmed wrote: . . .
I hope that makes some sense
. . .
I am afraid it doesn't. What it tells me is that you have tried to program before you know what you are trying to do. Tell us what you want to do not how you intend to do it. You do that with youir computer turned off and with a pencil and paper. You will need an eraser, the most important piece of kit. You will also need a large recycling bin. Every time the words List or Array appear on your paper, it goes into the recycling bin.

Yes, I know this seems harsh but start by reading this FAQ and this one.
 
shahbaaz ahmed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
shahbaaz ahmed wrote:I have no idea why its doing this, I am usually exactly the same code for mins as I did for grades.

Actually you're not. Look at lines 7 and 8.

However, I have to admit to being slightly puzzled myself. If I have a lightbulb moment, I'll let you know.

That said, your code is incredibly tortuous. Why are grades and mins arrays at all, since all you ever do is reference elements by their literal indexes? Two separate named variables would seem to me a much better idea - and a LOT easier to read.

Winston


thank you i have tired that:


however still same error (arrayindexoutofbounds), still can't see mins[1] for some reason.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read our replies. Turn your computer off and write down what you want to do. You are simply guessing and tying yourself in knots.
 
shahbaaz ahmed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Read our replies. Turn your computer off and write down what you want to do. You are simply guessing and tying yourself in knots.


okay thanks
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're reading your error message incorrectly. With your modified code, once you create a double[] of size 2, that won't change in size at any point. So its inconceivable that you would be able to access the first element but not the second. My guess is that its you're ArrayList which isn't large enough because it wasn't populated properly. It might be a little tedious, but its probably best to temporarily check and print out the size and contents of your arraylist and arrays through your actual program (as opposed to debugger).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!