Beispiel #1
0
  public void init(ObjectiveFunction function) {

    this.function = function;
    dimension = function.getDimension();

    min = Math.max(min, function.getMinimum()[0]);
    max = Math.min(max, function.getMaximum()[0]);

    xNew = new double[dimension];
    xDelta = new double[dimension];
    y = new double[dimension];
    H = new double[dimension][dimension];

    Hy = new double[dimension];
    xH = new double[dimension];

    direction = new double[dimension];

    switch (lineSearch) {
      case BRENT_WITHOUT:
        this.lineSearchMethod = new LineSearchBrentNoDerivatives(function);
        break;
      case BRENT_WITH:
        this.lineSearchMethod = new LineSearchBrentWithDerivatives(function);
        break;
      default:
        throw new IllegalStateException("Unknown line search method");
    }

    x = Point.random(dimension, min, max).toArray();
    solution = ValuePoint.at(Point.at(x), function);
    this.stopCondition.setInitialValue(solution.getValue());

    g = function.gradientAt(Point.at(x)).toArray();

    for (int i = 0; i < dimension; i++) {
      direction[i] = -g[i];
      H[i][i] = 1.0;
      y[i] = -1;
    }
  }
Beispiel #2
0
  public void init(ObjectiveFunction function) {

    generator = new Random();

    this.function = function;
    dimension = function.getDimension();

    min = Math.max(min, function.getMinimum()[0]);
    max = Math.min(max, function.getMaximum()[0]);

    means = new double[dimension];
    deviations = new double[dimension];
    paths = new ValuePoint[populationSize];

    best = ValuePoint.at(Point.getDefault(), Double.POSITIVE_INFINITY);
    stopCondition.setInitialValue(Double.POSITIVE_INFINITY);

    for (int i = 0; i < dimension; i++) {
      means[i] = (generator.nextDouble() * (max - min)) + min;
      deviations[i] = (max - min) / 2;
    }
  }