I have an arraylist of Integers. When there is a button click the data in the text field gets converted and added to the array list as an int. Here is my code for that below
public void onClick(View v) {
// TODO Auto-generated method stub
String rate = happy.getText().toString();
int rating = Integer.valueOf(rate);
counter += 1;
if (counter == 10) {
train();
}
if (rating > 0 && rating < 11) {
happyRating.add(rating);
test = happyRating.get(0);
Log.d("Value: ", Integer.toString(test));
} else {
InputAlertHandler.post(new Runnable() {
public void run() {
int duration = Toast.LENGTH_LONG;
CharSequence text = "Please enter Happiness Indicator between 1 and 10";
Context context = getApplicationContext();
inputAlert = Toast
.makeText(context, text, duration);
inputAlert.show();
}
});
}
}
In the function train(); I am getting data from this array list and using it in calculations.
public void train() {
for (int i = 2; i < 12; i++) {
if (happyRating.get(i - 1) < happyRating.size()){
int x, x1, x2, y, y1, y2;
double learningRate = -0.00002;
x1 = happyRating.get(i - 1);
x2 = happyRating.get(i - 2);
y1 = iteration[i - 1];
y2 = iteration[i - 2];
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;
}
}
As I am using slope for my calculations I am getting the slope of the previous two points, so that's why I'm setting int i = 2 in my for loop.
I've put in the check to ensure I don't get an Index out of bounds exception. My problem is, neither J nor WEIGHTING are showing up in my logcat. Now whether this means they're not calculated or what I don't know, but they are initialised as two globals so at least that value should print? I need to figure this out as soon as possible so if there's anyone out there that could shed some light on this, I'm sure it's something simple, but I've been looking at this project for so long my eyes hurt!!!
Thanks!