IntArrayList ys = space.getYs();
ArrayList<int[]> xs = space.getXs();
ArrayList<double[]> vs = space.getVs();
AbstractModel model = space.getModel();
double[] cWeights = new double[WS];
double[] aWeights = average ? new double[WS] : null;
double[] gs = new double[WS];
double stdev, prevScore, currScore = 0;
int[] indices = UTArray.range(N);
int i, j, correct, count = 1;
int yi;
int[] xi;
double[] vi = null;
for (i=0; i<MAX_ITER; i++)
{
UTArray.shuffle(new Random(5), indices, N);
prevScore = currScore;
Arrays.fill(gs, 0);
correct = 0;
for (j=0; j<N; j++)
{
yi = ys.get(indices[j]);
xi = xs.get(indices[j]);
if (space.hasWeight()) vi = vs.get(indices[j]);
if (average)
{
if (!update(L, yi, xi, vi, gs, cWeights, aWeights, count))
correct++;
count++;
}
else if (!update(L, yi, xi, vi, gs, cWeights))
correct++;
}
currScore = 100d * correct / N;
stdev = UTMath.stdev(prevScore, currScore);
LOG.info(String.format("%4d: acc = %5.2f, stdev = %7.4f\n", i+1, currScore, stdev));
if (stdev < d_eps) break;
}
if (average) model.setWeights(getWeights(cWeights, aWeights, count));
else model.setWeights(UTArray.toFloatArray(cWeights));
}