954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

can you help, please

Hi everyone,

Could any one help me with this code, please. I do not know why it's giving this kind of error. The code, which is a part of a lager program, is as given below. I will try explaining what each variables represent.

public void backwardComputation(int m, Double desiredOutput[][])
{
int i, j = 0;

deltaOutput[j] = (1 * (desiredOutput[m][j] - targetOutputA[j]));
System.out.println(deltaOutput[j]);

for(i = 0; i < hiddenNeurons; i++)
for(j = 0; j < outputNeurons; j++)
deltaHidden[i]=((hiddenA[i]*(1 - hiddenA[i]))*(deltaOutput[j] * outputToHiddenWeight[i][j]));
}

Let us say the variables outputNeurons and hiddenNeurons are given as 1 and 3 respectively, but each time i attempt to store ((hiddenA[i]*(1 - hiddenA[i]))*(deltaOutput[j] * outputToHiddenWeight[i][j])); into the array deltaHidden[i], it gives an error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundExceptions: 1" and I have checked that the array deltaHidden[] have enough spaces, and that all other arrays in the equation work out fine. Can you help looking into this please?

debee
Newbie Poster
19 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

No, not really, because you only posted a fragment of code that cannot be run and your indexes are going to vary at runtime. It's very simple for you to find the problem on your own though. Check your array sizes before you access them. Obviously one of those arrays only has a single element and you are trying to access a second.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

You are right indeed. I took a second look at all the arrays in that piece of code, and I found out that there is one which the length is supposed to be more than one, and which I have mistakenly made to be one. Thank you very much for your advice.

debee
Newbie Poster
19 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You