public void update() {
    int counter = 0;
    //for (int id : randomNeighborSet) {
    for (int iter = 0; iter < r; iter++) {
      int id = rand.nextInt(similarities.size());
      TopKEntry entry = new TopKEntry(id, similarities.get(userID, id));
      if (!topr.contains(entry)) {
        topr.insert(entry);
        counter++;
      }
      if (counter > n) {
      //for (int currN = 0; currN < topk.size(); currN ++) {
        //double e = error(currN);
        double e = error(n);
        if (e < bestError) {
          bestError = e;
          //n = currN;
          bestNbrIndices.clear();
          for (int i = 0; i < topk.size(); i++) {
            int index = (i < topk.size() - n) ? i : i + n;
            bestNbrIndices.add(index);
          }
        }
      }
    }
  }