Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>instead of </p> <pre><code> Log.d("WEIGHTING: ", Double.toString(weighting));// break; </code></pre> <p>declare a keyword in logcat console, for example "output" and the write:</p> <pre><code> Log.d("output","WEIGHTING: "+Double.toString(weighting));// break; </code></pre> <p>The first parameter of Log. must be the keyword for Your logcat output.</p> <h2>EDIT</h2> <p>Logcat seems not to be the problem. So , the issue is at the for loop. If Your happyRating is definitely 10, following happens:</p> <pre><code> for (int i = 2; i &lt; 12; i++) { if (happyRating.get(i - 1) &lt; happyRating.size()){ </code></pre> <p>When i is reaching 11, it tries to get item nr. 10 from happyRating (because you sub 1). But there is none, maximum is item nr. 9 (because java is counting from 0). The maximum size You can reach here is 9, so You have to try another way if You need to execute the for loop for 12 times</p> <h2>EDIT</h2> <p>Sorry, I can´t test the code for now, if there is an error, don´t downvote, I will test it when I am at home. But this should work also...</p> <pre><code> public void train() { for (int i = 0; i &lt; happyRating.size()-1; i++) { if (happyRating.get(i) &lt; happyRating.size()){ int x, x1, x2, y, y1, y2; double learningRate = -0.00002; x1 = happyRating.get(i+1); x2 = happyRating.get(i); y1 = iteration[i+1]; y2 = iteration[i]; x = x2 - x1; y = y2 - y1; if (x == 0) { slope = 0; } else { slope = (y2 - y1) / (x2 - x1); } j++; Log.d("J: ", Integer.toString(j)); double weightAdj = happyRating.get(j) * slope * learningRate; weighting = (weighting + weightAdj); Log.d("WEIGHTING: ", Double.toString(weighting));// break; } else { break; } } </code></pre> <p>In this modification of Your code, the for loop only iterates until happyRating reaches the maximum size -2.So far I can see, You want to take with every loop the value of every first item and subtract the value of the second item from the first. The difference between this and Your code is, that You can get the last value without an exception. In Your code, when the loop reaches the maximum-1, You try to get an item of happyRating which is not existing. For example, imagine the integer "i" is at value 10. This is what Your code does:</p> <pre><code> x1 = happyRating.get(i - 1);//x1 = happyRating.get(9) x2 = happyRating.get(i - 2);//x2 = happyRating.get(8) y1 = iteration[i - 1];//y1 = iteration[9] y2 = iteration[i - 2];//y2 = iteration[8] </code></pre> <p>If Your happyRating size is maximum 9, x1 wants to have a value that is not there. The size of an ArrayList (or Array) is not similar to item number. if this size is 9, the number of the last item is 8, because Java/Android counts from 0. So, You cannot get item number 9. The for loop says, iterate as long as "i" is smaller than happyRating.size(). If happyRating.size() is 9, "i" iterates till 8 and then ends the iteration. This is what the modification of my code does, if happyRating.size() is 9:</p> <pre><code> x1 = happyRating.get(i+1);//x1=happyRating.get(8) x2 = happyRating.get(i);//x2=happyRating.get(7) y1 = iteration[i+1];//y1=iteration[8] y2 = iteration[i];//y2=iteration[7] </code></pre> <p>The loop only iterates until 7, because it says -> iterate as long as i is smaller than happyRating,size()-1 (smaller than means maximum 8 --> -1 means 7). </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload