@Override
 public double value(final Vec mu) {
   double result = 0.0;
   for (int i = 0; i < ds.length(); i++) {
     final double trans = binClassifier.value(ds.data().row(i));
     final double sigmoid = MathTools.sigmoid(trans);
     final double underLog =
         mu.get(target.label(i)) * sigmoid + (1 - mu.get(target.label(i))) * (1 - sigmoid);
     result -= Math.log(underLog);
   }
   result += c * VecTools.multiply(MxTools.multiply(laplacian, mu), mu);
   return result;
 }
예제 #2
0
파일: Layer.java 프로젝트: HrundelB/jmll
  public void backward() {
    Mx cnc = null;
    if (bias_b != 0) {
      cnc = leftContract(output);
    } else {
      cnc = VecTools.copy(output);
    }

    difference = MxTools.multiply(MxTools.transpose(cnc), activations);
    for (int i = 0; i < difference.dim(); i++) {
      difference.set(i, difference.get(i) / activations.rows());
    }

    input = MxTools.multiply(cnc, weights);

    rectifier.grad(activations, activations);
    for (int i = 0; i < input.dim(); i++) {
      input.set(i, input.get(i) * activations.get(i));
      if (dropoutFraction > 0) {
        input.set(i, input.get(i) * dropoutMask.get(i));
      }
    }
  }
예제 #3
0
파일: Layer.java 프로젝트: HrundelB/jmll
  public void forward() {
    if (bias != 0) {
      activations = leftExtend(input);
    } else {
      activations = VecTools.copy(input);
    }

    output = MxTools.multiply(activations, MxTools.transpose(weights));
    rectifier.value(output, output);

    if (dropoutFraction > 0) {
      if (isTrain) {
        dropoutMask = getDropoutMask();

        for (int i = 0; i < output.dim(); i++) {
          output.set(i, output.get(i) * dropoutMask.get(i));
        }
      } else {
        for (int i = 0; i < output.dim(); i++) {
          output.set(i, output.get(i) * (1 - dropoutFraction));
        }
      }
    }
  }