Exemplo n.º 1
0
  @Override
  public void step() {
    stateHidden.setSubVector(0, weights0.operate(stateIn));

    for (int i : series(h)) stateHidden.setEntry(i, activation.function(stateHidden.getEntry(i)));

    stateOut.setSubVector(0, weights1.operate(stateHidden));
  }
  /** {@inheritDoc} */
  public double value(final double[] point) throws FunctionEvaluationException {

    // compute residuals
    final double[] residuals = function.value(point);
    if (residuals.length != observations.length) {
      throw new FunctionEvaluationException(
          point, "dimension mismatch {0} != {1}", residuals.length, observations.length);
    }
    for (int i = 0; i < residuals.length; ++i) {
      residuals[i] -= observations[i];
    }

    // compute sum of squares
    double sumSquares = 0;
    if (weights != null) {
      for (int i = 0; i < residuals.length; ++i) {
        final double ri = residuals[i];
        sumSquares += weights[i] * ri * ri;
      }
    } else if (scale != null) {
      for (final double yi : scale.operate(residuals)) {
        sumSquares += yi * yi;
      }
    } else {
      for (final double ri : residuals) {
        sumSquares += ri * ri;
      }
    }

    return sumSquares;
  }