/* Returns the sum of each weight * value of each feature. */
  public double predictedValue(RegressionState state, double[] weight) {
    double sum = weight[0] * 1;
    for (int i = 1; i < TOTAL_FEATURES; i++) {
      sum += weight[i] * state.getFeature(i);
    }

    return sum;
  }
  /* calculate the gradient descent. */
  public void gradientDescent(double stepsize) {

    copyArr(weight, copy);

    int i = 0;
    while (i < TOTAL_FEATURES) {

      double sumAll = 0;
      double sumTotal = 0;

      Iterator<RegressionState> it = gameHistory.iterator();
      while (it.hasNext()) {
        RegressionState aState = it.next();
        sumAll = predictedValue(aState, copy);
        sumAll -= reward;

        sumTotal += sumAll * aState.getFeature(i);
      } // end inner while

      weight[i] = copy[i] - stepsize * ((double) 1 / gameHistory.size()) * sumTotal;
      i++;
    } // end while
  }