本文整理汇总了Java中org.apache.commons.math3.analysis.MultivariateFunction.value方法的典型用法代码示例。如果您正苦于以下问题:Java MultivariateFunction.value方法的具体用法?Java MultivariateFunction.value怎么用?Java MultivariateFunction.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.analysis.MultivariateFunction
的用法示例。
在下文中一共展示了MultivariateFunction.value方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doLineSearch
import org.apache.commons.math3.analysis.MultivariateFunction; //导入方法依赖的package包/类
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
);
}
示例2: gradient
import org.apache.commons.math3.analysis.MultivariateFunction; //导入方法依赖的package包/类
public static double[] gradient(MultivariateFunction f, double[] x) {
double[] grad = new double[x.length];
for (int i = 0; i < x.length; i++) {
double h = MachineAccuracy.SQRT_EPSILON * (Math.abs(x[i]) + 1.0);
/* codeml step size: double h = 1e-6 * 2 * Math.abs(x[i] + 1.); */
double oldx = x[i];
x[i] = oldx + h;
double fxplus = -f.value(x); // notice this is -ve! For L-BFGS-S [minimising] optimiser
x[i] = oldx - h;
double fxminus = -f.value(x); // notice this is -ve!
x[i] = oldx;
// Centered first derivative
grad[i] = (fxplus - fxminus) / (2.0 * h);
}
return grad;
}
示例3: max
import org.apache.commons.math3.analysis.MultivariateFunction; //导入方法依赖的package包/类
@Override
public final Triple<double[], Double, Double> max(final MultivariateFunction test, final double[] initial) {
Check.size(initial, 1, 999);
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;
}
示例4: evaluate
import org.apache.commons.math3.analysis.MultivariateFunction; //导入方法依赖的package包/类
/**
* Evaluate all the non-evaluated points of the simplex.
*
* @param evaluationFunction Evaluation function.
* @param comparator Comparator to use to sort simplex vertices from best to worst.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the maximal number of evaluations is exceeded.
*/
public void evaluate(final MultivariateFunction evaluationFunction,
final Comparator<PointValuePair> comparator) {
// Evaluate the objective function at all non-evaluated simplex points.
for (int i = 0; i < simplex.length; i++) {
final PointValuePair vertex = simplex[i];
final double[] point = vertex.getPointRef();
if (Double.isNaN(vertex.getValue())) {
simplex[i] = new PointValuePair(point, evaluationFunction.value(point), false);
}
}
// Sort the simplex from best to worst.
Arrays.sort(simplex, comparator);
}