Exemplo n.º 1
0
  protected void doOnePassBinomial(
      double[][] x,
      double[] theta,
      double[] y,
      final double tl2,
      double[] w,
      double[] pTrain,
      double[] rTrain) {
    for (int j = 0; j < x.length; j++) {
      if (Math.abs(theta[j]) <= MathUtils.EPSILON) {
        continue;
      }

      double[] v = x[j];
      double eta = VectorUtils.dotProduct(rTrain, v);

      double wNew = (w[j] * theta[j] + eta) / (theta[j] + tl2);
      double delta = wNew - w[j];
      w[j] = wNew;

      // Update predictions
      for (int i = 0; i < pTrain.length; i++) {
        pTrain[i] += delta * v[i];
        rTrain[i] = OptimUtils.getPseudoResidual(pTrain[i], y[i]);
      }
    }
  }
Exemplo n.º 2
0
  protected void doOnePassGaussian(
      double[][] x, double[] sq, final double tl2, double[] w, double[] rTrain) {
    for (int j = 0; j < x.length; j++) {
      double[] v = x[j];
      // Calculate weight updates using naive updates
      double eta = VectorUtils.dotProduct(rTrain, v);
      double wNew = (w[j] * sq[j] + eta) / (sq[j] + tl2);

      double delta = wNew - w[j];
      w[j] = wNew;

      // Update residuals
      for (int i = 0; i < rTrain.length; i++) {
        rTrain[i] -= delta * v[i];
      }
    }
  }