List of usage examples for org.apache.commons.math3.analysis MultivariateFunction value
double value(double[] point);
From source file:eu.crisis_economics.abm.algorithms.optimization.BrentLineSearch.java
static public LineSearchResult doLineSearch(final MultivariateFunction function, final double[] startingPoint, final double[] vectorDirection, final double[] domainMaxima, final double[] domainMinima) { final double maximumDistanceToTravel = computeMaximumSearchDistanceFromDomainBounds(startingPoint, vectorDirection, domainMaxima, domainMinima); if (maximumDistanceToTravel == 0.) return new LineSearchResult(Arrays.copyOf(startingPoint, startingPoint.length), function.value(startingPoint)); return doLineSearch(function, startingPoint, vectorDirection, maximumDistanceToTravel, DEFAULT_MAXIMUM_EVALUATIONS, DEFAULT_ERROR_TARGET_RELATIVE, DEFAULT_ERROR_TARGET_ABSOLUTE); }
From source file:com.insightml.math.optimization.AbstractOptimizable.java
@Override public final Triple<double[], Double, Double> max(final MultivariateFunction test, final double[] initial) { Check.size(initial, 1, 999);//from ww w . j a v a2 s . c o m final double initialTrain = value(initial); final double initialTest = test == null ? Double.NEGATIVE_INFINITY : test.value(initial); PointValuePair result = new PointValuePair(initial, initialTrain); Triple<double[], Double, Double> bestTrain = Triple.create(initial, initialTrain, initialTest); Triple<double[], Double, Double> bestTest = Triple.create(initial, initialTrain, initialTest); while (true) { result = iteration(result); if (result.getSecond() < bestTrain.getSecond() + convergence.getAbsoluteThreshold()) { log("RESULT", result); break; } final double testScore = test == null ? 0 : test.value(result.getFirst()); bestTrain = Triple.create(result.getFirst(), result.getSecond(), testScore); if (test != null && testScore > bestTest.getThird()) { bestTest = bestTrain; } // todo: prevent doing NM twice if (bounds == null) { break; } } if (test == null) { return bestTrain; } final double improveTrain = bestTrain.getSecond() - bestTest.getSecond(); final double improveTest = bestTest.getThird() - bestTrain.getThird(); if (improveTest > improveTrain) { logger.info(bestTrain + " vs. " + bestTest); } return improveTest > improveTrain ? bestTest : bestTrain; }
From source file:org.moeaframework.analysis.sensitivity.SobolAnalysisTest.java
/** * Evaluates the given function on each input entry, returning the array of * outputs./*from w w w .java2 s. co m*/ * * @param function the function * @param input the array of inputs, where the outer index references each * set of input to the function * @return the array of outputs * @throws FunctionEvaluationException if an error occurred when evaluating * the function */ protected double[] evaluate(MultivariateFunction function, double[][] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = function.value(input[i]); } return output; }