Exemplo n.º 1
0
 public RepeatingLSH(List<LSH> lshList) throws MathException {
   super(lshList.get(0).getDim(), lshList.get(0).getRandomGenerator());
   this.lshList = lshList;
   RandomGenerator rg = lshList.get(0).getRandomGenerator();
   RandomData rd = new RandomDataImpl(rg);
   /*
    * Compute a random vector of lshList.size() with each component taken from U(0,10)
    */
   randomVec = new ArrayRealVector(lshList.size());
   for (int i = 0; i < randomVec.getDimension(); ++i) {
     randomVec.setEntry(i, rd.nextUniform(0, 10.0));
   }
 }
Exemplo n.º 2
0
  /**
   * Modifies this map through a single backpropagation iteration using the given error values on
   * the output nodes.
   *
   * @param error
   */
  public void train(List<Double> error, double learningRate) {
    RealVector eOut = new ArrayRealVector(error.size());
    for (int i : series(error.size())) eOut.setEntry(i, error.get(i));

    // * gHidden: delta for the non-bias nodes of the hidden layer
    gHidden.setSubVector(0, stateHidden.getSubVector(0, n)); // optimize

    for (int i : Series.series(gHidden.getDimension()))
      gHidden.setEntry(i, activation.derivative(gHidden.getEntry(i)));

    eHiddenL = weights1.transpose().operate(eOut);
    eHidden.setSubVector(0, eHiddenL.getSubVector(0, h));
    for (int i : series(h)) eHidden.setEntry(i, eHidden.getEntry(i) * gHidden.getEntry(i));

    weights1Delta = MatrixTools.outer(eOut, stateHidden);
    weights1Delta = weights1Delta.scalarMultiply(-1.0 * learningRate); // optimize

    weights0Delta = MatrixTools.outer(eHidden, stateIn);
    weights0Delta = weights0Delta.scalarMultiply(-1.0 * learningRate);

    weights0 = weights0.add(weights0Delta);
    weights1 = weights1.add(weights1Delta);
  }
Exemplo n.º 3
0
 public static String realVecToString(RealVector r) {
   String res = "RealVector(" + r.getDimension() + ") of type '" + r.getClass().getName() + "'\n";
   return res += Arrays.toString(r.getData()) + "\n";
 }