public double[] initial(Random randGen) { double[] initial = new double[domainDimension()]; for (int i = 0; i < initial.length; i++) { initial[i] = randGen.nextDouble() + smallConst; // initial[i] = generator.nextDouble() * largeConst; // initial[i] = -1+2*(i); // initial[i] = (i == 0 ? 1 : 0); } return initial; }
@Override public int[][] getFeatureGrouping() { if (featureGrouping != null) return featureGrouping; else { int[][] fg = new int[1][]; fg[0] = ArrayMath.range(0, domainDimension()); return fg; } }
public double[] to1D(double[][] weights) { return to1D(weights, domainDimension()); }
public void calculateStochasticGradient(double[] x, int[] batch) { if (derivative == null) { derivative = new double[domainDimension()];
public double[] initial(Random randGen) { double[] initial = new double[domainDimension()]; for (int i = 0; i < initial.length; i++) { initial[i] = randGen.nextDouble() + smallConst; // initial[i] = generator.nextDouble() * largeConst; // initial[i] = -1+2*(i); // initial[i] = (i == 0 ? 1 : 0); } return initial; }
public double[] initial(Random randGen) { double[] initial = new double[domainDimension()]; for (int i = 0; i < initial.length; i++) { initial[i] = randGen.nextDouble() + smallConst; // initial[i] = generator.nextDouble() * largeConst; // initial[i] = -1+2*(i); // initial[i] = (i == 0 ? 1 : 0); } return initial; }
public double[] to1D(double[][] weights) { double[] newWeights = new double[domainDimension()]; int index = 0; for (int i = 0; i < weights.length; i++) { System.arraycopy(weights[i], 0, newWeights, index, weights[i].length); index += weights[i].length; } return newWeights; }
@Override public int[][] getFeatureGrouping() { if (featureGrouping != null) return featureGrouping; else { int[][] fg = new int[1][]; fg[0] = ArrayMath.range(0, domainDimension()); return fg; } }
@Override public int[][] getFeatureGrouping() { if (featureGrouping != null) return featureGrouping; else { int[][] fg = new int[1][]; fg[0] = ArrayMath.range(0, domainDimension()); return fg; } }
public double[] to1D(double[][] weights) { return to1D(weights, domainDimension()); }
public double[] to1D(double[][] weights) { return to1D(weights, domainDimension()); }
public void calculateStochasticGradient(double[] x, int[] batch) { if (derivative == null) { derivative = new double[domainDimension()];
/** * Performs stochastic gradient update based * on samples indexed by batch, but does not apply regularization. * * @param x - unscaled weights * @param batch - indices of which samples to compute function over */ @Override public void calculateStochasticGradient(double[] x, int[] batch) { if (derivative == null) { derivative = new double[domainDimension()]; } // int[][] wis = getWeightIndices(); // was: double[][] weights = to2D(x, 1.0); // but 1.0 should be the same as omitting 2nd parameter.... to2D(x, weights); setWeights(weights); // iterate over all the documents List<Integer> docIDs = new ArrayList<Integer>(batch.length); for (int m=0; m < batch.length; m++) docIDs.add(batch[m]); multiThreadGradient(docIDs, true); int index = 0; for (int i = 0; i < E.length; i++) { for (int j = 0; j < E[i].length; j++) { // real gradient should be empirical-expected; // but since we minimize -L(\theta), the gradient is -(empirical-expected) derivative[index++] = (E[i][j]-Ehat[i][j]); } } }