/** Build an initial simplex. * @param startPoint the start point for optimization * @exception IllegalArgumentException if the start point does not match * simplex dimension */ private void buildSimplex(final double[] startPoint) throws IllegalArgumentException { final int n = startPoint.length; if (n != startConfiguration.length) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, startConfiguration.length); } // set first vertex simplex = new RealPointValuePair[n + 1]; simplex[0] = new RealPointValuePair(startPoint, Double.NaN); // set remaining vertices for (int i = 0; i < n; ++i) { final double[] confI = startConfiguration[i]; final double[] vertexI = new double[n]; for (int k = 0; k < n; ++k) { vertexI[k] = startPoint[k] + confI[k]; } simplex[i + 1] = new RealPointValuePair(vertexI, Double.NaN); } }
/** Build an initial simplex. * @param startPoint the start point for optimization * @exception IllegalArgumentException if the start point does not match * simplex dimension */ private void buildSimplex(final double[] startPoint) throws IllegalArgumentException { final int n = startPoint.length; if (n != startConfiguration.length) { throw MathRuntimeException.createIllegalArgumentException( DIMENSION_MISMATCH_MESSAGE, n, startConfiguration.length); } // set first vertex simplex = new RealPointValuePair[n + 1]; simplex[0] = new RealPointValuePair(startPoint, Double.NaN); // set remaining vertices for (int i = 0; i < n; ++i) { final double[] confI = startConfiguration[i]; final double[] vertexI = new double[n]; for (int k = 0; k < n; ++k) { vertexI[k] = startPoint[k] + confI[k]; } simplex[i + 1] = new RealPointValuePair(vertexI, Double.NaN); } }
/** Evaluate all the non-evaluated points of the simplex. * @param comparator comparator to use to sort simplex vertices from best to worst * @exception FunctionEvaluationException if no value can be computed for the parameters * @exception OptimizationException if the maximal number of evaluations is exceeded */ protected void evaluateSimplex(final Comparator<RealPointValuePair> comparator) throws FunctionEvaluationException, OptimizationException { // evaluate the objective function at all non-evaluated simplex points for (int i = 0; i < simplex.length; ++i) { final RealPointValuePair vertex = simplex[i]; final double[] point = vertex.getPointRef(); if (Double.isNaN(vertex.getValue())) { simplex[i] = new RealPointValuePair(point, evaluate(point), false); } } // sort the simplex from best to worst Arrays.sort(simplex, comparator); }
/** Evaluate all the non-evaluated points of the simplex. * @param comparator comparator to use to sort simplex vertices from best to worst * @exception FunctionEvaluationException if no value can be computed for the parameters * @exception OptimizationException if the maximal number of evaluations is exceeded */ protected void evaluateSimplex(final Comparator<RealPointValuePair> comparator) throws FunctionEvaluationException, OptimizationException { // evaluate the objective function at all non-evaluated simplex points for (int i = 0; i < simplex.length; ++i) { final RealPointValuePair vertex = simplex[i]; final double[] point = vertex.getPointRef(); if (Double.isNaN(vertex.getValue())) { simplex[i] = new RealPointValuePair(point, evaluate(point), false); } } // sort the simplex from best to worst Arrays.sort(simplex, comparator); }
/** Compute and evaluate a new simplex. * @param original original simplex (to be preserved) * @param coeff linear coefficient * @param comparator comparator to use to sort simplex vertices from best to poorest * @return best point in the transformed simplex * @exception FunctionEvaluationException if the function cannot be evaluated at some point * @exception OptimizationException if the maximal number of evaluations is exceeded */ private RealPointValuePair evaluateNewSimplex(final RealPointValuePair[] original, final double coeff, final Comparator<RealPointValuePair> comparator) throws FunctionEvaluationException, OptimizationException { final double[] xSmallest = original[0].getPointRef(); final int n = xSmallest.length; // create the linearly transformed simplex simplex = new RealPointValuePair[n + 1]; simplex[0] = original[0]; for (int i = 1; i <= n; ++i) { final double[] xOriginal = original[i].getPointRef(); final double[] xTransformed = new double[n]; for (int j = 0; j < n; ++j) { xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]); } simplex[i] = new RealPointValuePair(xTransformed, Double.NaN, false); } // evaluate it evaluateSimplex(comparator); return simplex[0]; }
return new RealPointValuePair(coefficients, f.getValue(coefficients));
xR[j] = centroid[j] + rho * (centroid[j] - xWorst[j]); final RealPointValuePair reflected = new RealPointValuePair(xR, evaluate(xR), false); xE[j] = centroid[j] + khi * (xR[j] - centroid[j]); final RealPointValuePair expanded = new RealPointValuePair(xE, evaluate(xE), false); xC[j] = centroid[j] + gamma * (xR[j] - centroid[j]); final RealPointValuePair outContracted = new RealPointValuePair(xC, evaluate(xC), false); xC[j] = centroid[j] - gamma * (centroid[j] - xWorst[j]); final RealPointValuePair inContracted = new RealPointValuePair(xC, evaluate(xC), false); x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]); simplex[i] = new RealPointValuePair(x, Double.NaN, false);
/** Compute and evaluate a new simplex. * @param original original simplex (to be preserved) * @param coeff linear coefficient * @param comparator comparator to use to sort simplex vertices from best to poorest * @return best point in the transformed simplex * @exception FunctionEvaluationException if the function cannot be evaluated at * some point * @exception OptimizationException if the maximal number of evaluations is exceeded */ private RealPointValuePair evaluateNewSimplex(final RealPointValuePair[] original, final double coeff, final Comparator<RealPointValuePair> comparator) throws FunctionEvaluationException, OptimizationException { final double[] xSmallest = original[0].getPointRef(); final int n = xSmallest.length; // create the linearly transformed simplex simplex = new RealPointValuePair[n + 1]; simplex[0] = original[0]; for (int i = 1; i <= n; ++i) { final double[] xOriginal = original[i].getPointRef(); final double[] xTransformed = new double[n]; for (int j = 0; j < n; ++j) { xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]); } simplex[i] = new RealPointValuePair(xTransformed, Double.NaN, false); } // evaluate it evaluateSimplex(comparator); return simplex[0]; }
return new RealPointValuePair(coefficients, f.getValue(coefficients));
xR[j] = centroid[j] + rho * (centroid[j] - xWorst[j]); final RealPointValuePair reflected = new RealPointValuePair(xR, evaluate(xR), false); xE[j] = centroid[j] + khi * (xR[j] - centroid[j]); final RealPointValuePair expanded = new RealPointValuePair(xE, evaluate(xE), false); xC[j] = centroid[j] + gamma * (xR[j] - centroid[j]); final RealPointValuePair outContracted = new RealPointValuePair(xC, evaluate(xC), false); xC[j] = centroid[j] - gamma * (centroid[j] - xWorst[j]); final RealPointValuePair inContracted = new RealPointValuePair(xC, evaluate(xC), false); x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]); simplex[i] = new RealPointValuePair(x, Double.NaN, false);
final RealPointValuePair previous = new RealPointValuePair(x1, fX); final RealPointValuePair current = new RealPointValuePair(x, fVal); if (getConvergenceChecker().converged(getIterations(), previous, current)) { if (goal == GoalType.MINIMIZE) {
current = new RealPointValuePair(point, objective); if (previous != null) { if (checker.converged(getIterations(), previous, current)) {
current = new RealPointValuePair(point, objective); if (previous != null) { if (checker.converged(getIterations(), previous, current)) {