示例#1
0
  public void reset(FeatureVector wv) {
    this.iter = 0;

    Arrays.fill(dir, 0);
    Arrays.fill(this.steepestDescDir, 0);

    Arrays.fill(w, 0);
    Arrays.fill(newW, 0);

    Arrays.fill(grad, 0);
    Arrays.fill(newGrad, 0);

    for (int i = 0; i < wv.size(); ++i) {
      int fid = wv.idByIndex(i);
      double v = wv.valueByIndex(i);

      w[fid - 1] = v;
    }
    lossFunction.eval(w, grad);

    Arrays.fill(alphas, 0);
    this.sList.clear();
    this.yList.clear();
    this.roList.clear();

    this.prevVals.clear();
    this.value = evalL1();
  }
示例#2
0
  /**
   * eval loss + L1 reg
   *
   * @return
   */
  protected double evalL1() {
    double val = lossFunction.eval(newW, newGrad);

    if (DEBUG || verbose) {
      stderr.println("loss:" + val);
    }

    if (C > 0) {
      for (int i = 1; i < dim; ++i) {
        val += Math.abs(newW[i]) * C;
      }
    }

    return val;
  }
示例#3
0
  public void init() {
    stderr.println(this.getClass().getName() + "#init()");
    this.iter = 0;

    this.alphas = new double[m];

    this.dir = new double[dim + 1];
    this.steepestDescDir = new double[dim + 1];
    this.grad = new double[dim + 1];
    this.w = new double[dim + 1];

    this.newGrad = new double[dim + 1];
    this.newW = new double[dim + 1];

    lossFunction.eval(this.w, this.grad);

    this.sList = new Stack<double[]>();
    this.yList = new Stack<double[]>();
    this.roList = new Stack<Double>();

    this.value = evalL1();
    this.prevVals = new Stack<Double>();
  }