本文整理汇总了Java中org.apache.commons.math3.optim.univariate.UnivariatePointValuePair类的典型用法代码示例。如果您正苦于以下问题:Java UnivariatePointValuePair类的具体用法?Java UnivariatePointValuePair怎么用?Java UnivariatePointValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnivariatePointValuePair类属于org.apache.commons.math3.optim.univariate包,在下文中一共展示了UnivariatePointValuePair类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: optimizeUni
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
public double optimizeUni() throws Exception {
double maxLh=0;
BrentOptimizer optimizer = new BrentOptimizer(1e-6, 1e-12);
UnivariatePointValuePair optimum =
optimizer.optimize(new UnivariateObjectiveFunction(this),
new MaxEval(100),
GoalType.MAXIMIZE,
new SearchInterval(pfBoundsLower[0],pfBoundsUpper[0]));
//double point = optimum.getPoint();
//System.out.print("--> "+paramName+": "+paramValue+" point= "+point);
//System.out.print(" ");
//System.out.println("value = "+ optimum.getValue());
maxLh = optimum.getValue();
optPoint[0] = optimum.getPoint();
return maxLh;
}
开发者ID:mrc-ide,项目名称:PhyDyn,代码行数:20,代码来源:PhyDynSlice.java
示例2: search
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p Starting point.
* @param d Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d) {
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction() {
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = p[i] + alpha * d[i];
}
final double obj = PowellOptimizer.this.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = PowellOptimizer.this.getGoalType();
bracket.search(f, goal, 0, 1);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(new MaxEval(Integer.MAX_VALUE),
new UnivariateObjectiveFunction(f),
goal,
new SearchInterval(bracket.getLo(),
bracket.getHi(),
bracket.getMid()));
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:PowellOptimizer.java
示例3: findMin
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
private UnivariatePointValuePair findMin(UnivariatePointValuePair current, UnivariateOptimizer o,
UnivariateFunction f, double qValue, double factor)
{
try
{
BracketFinder bracket = new BracketFinder();
bracket.search(f, GoalType.MINIMIZE, qValue * factor, qValue / factor);
UnivariatePointValuePair next = o.optimize(GoalType.MINIMIZE, new MaxEval(3000),
new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()),
new UnivariateObjectiveFunction(f));
if (next == null)
return current;
//System.out.printf("LineMin [%.1f] %f = %f\n", factor, next.getPoint(), next.getValue());
if (current != null)
return (next.getValue() < current.getValue()) ? next : current;
return next;
}
catch (Exception e)
{
return current;
}
}
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:23,代码来源:FIRE.java
示例4: getStartPointPhase
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Calculates the 'canonical' start point. This version uses
* (a) a coarse search for a global maximum of fp() and subsequently
* (b) a numerical optimization using Brent's method
* (implemented with Apache Commons Math).
*
* @param Mp number of Fourier coefficient pairs
* @return start point phase
*/
public double getStartPointPhase(int Mp) {
Mp = Math.min(Mp, (G.length-1)/2);
UnivariateFunction fp = new TargetFunction(Mp);
// search for the global maximum in coarse steps
double cmax = Double.NEGATIVE_INFINITY;
int kmax = -1;
int K = 25; // number of steps over 180 degrees
for (int k = 0; k < K; k++) {
final double phi = Math.PI * k / K; // phase to evaluate
final double c = fp.value(phi);
if (c > cmax) {
cmax = c;
kmax = k;
}
}
// optimize using previous and next point as the bracket.
double minPhi = Math.PI * (kmax - 1) / K;
double maxPhi = Math.PI * (kmax + 1) / K;
UnivariateOptimizer optimizer = new BrentOptimizer(1E-4, 1E-6);
int maxIter = 20;
UnivariatePointValuePair result = optimizer.optimize(
new MaxEval(maxIter),
new UnivariateObjectiveFunction(fp),
GoalType.MAXIMIZE,
new SearchInterval(minPhi, maxPhi)
);
double phi0 = result.getPoint();
return phi0; // the canonical start point phase
}
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:40,代码来源:FourierDescriptor.java
示例5: getOptimalTime
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
Pair<LocalDateTime, Double> getOptimalTime(Path path,
TimeRange<LocalDateTime> timeRange, int starts) {
// the objective function to be passed to the BrentOptimizer
UnivariateFunction univariateFunction = (x) -> {
LocalDateTime time = timeRange.getFrom().plusSeconds((long) x);
Weighting weighting = routingHelper
.createWeighting(this.weightingType, time);
OptionalDouble value = objectiveFunctionPath.value(time, path,
weighting);
if (value.isPresent()) {
return value.getAsDouble();
} else {
return Double.MAX_VALUE;
}
};
// interval used for optimization is 0 and the duration between the
// lower and upper bound in seconds
double lower = 0;
double upper = timeRange.durationInSeconds() + 1;
logger.debug("lower = " + lower + ", upper = " + upper);
BrentOptimizer optimizer = new BrentOptimizer(RELATIVE_THRESHOLD,
ABSOLUTE_THRESHOLD);
MultiStartUnivariateOptimizer multiStartOptimizer = new MultiStartUnivariateOptimizer(
optimizer, starts, rng);
UnivariatePointValuePair res = multiStartOptimizer.optimize(
new MaxEval(MAX_EVAL), GOAL_TYPE,
new SearchInterval(lower, upper),
new UnivariateObjectiveFunction(univariateFunction));
return Pair.of(timeRange.getFrom().plusSeconds((long) res.getPoint()),
res.getValue());
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:39,代码来源:OptimalTimeFinderHeuristic.java
示例6: search
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Finds the number {@code alpha} that optimizes
* {@code f(startPoint + alpha * direction)}.
*
* @param startPoint Starting point.
* @param direction Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] startPoint,
final double[] direction) {
final int n = startPoint.length;
final UnivariateFunction f = new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = startPoint[i] + alpha * direction[i];
}
final double obj = mainOptimizer.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = mainOptimizer.getGoalType();
bracket.search(f, goal, 0, initialBracketingRange);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return lineOptimizer.optimize(new MaxEval(Integer.MAX_VALUE),
new UnivariateObjectiveFunction(f),
goal,
new SearchInterval(bracket.getLo(),
bracket.getHi(),
bracket.getMid()));
}
开发者ID:biocompibens,项目名称:SME,代码行数:38,代码来源:LineSearch.java
示例7: search
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Finds the number {@code alpha} that optimizes
* {@code f(startPoint + alpha * direction)}.
*
* @param startPoint Starting point.
* @param direction Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] startPoint,
final double[] direction) {
final int n = startPoint.length;
final UnivariateFunction f = new UnivariateFunction() {
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = startPoint[i] + alpha * direction[i];
}
final double obj = mainOptimizer.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = mainOptimizer.getGoalType();
bracket.search(f, goal, 0, initialBracketingRange);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return lineOptimizer.optimize(new MaxEval(Integer.MAX_VALUE),
new UnivariateObjectiveFunction(f),
goal,
new SearchInterval(bracket.getLo(),
bracket.getHi(),
bracket.getMid()));
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:37,代码来源:LineSearch.java
示例8: doLineSearch
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Perform a line search minimization. This function accepts as input:
* (a) a starting point (a vector),
* (b) a direction in which to travel (a vector),
* (c) limits on the total distance to travel along (b).
*
* With these inputs the function attempts to find the minimum of a
* scalar-valued multivariate function along the line starting at
* (a) and pointing in the direction of (b).
*
* @param function
* A scalar-valued multivariate function to minimize,
* @param startingPoint
* A vector starting point from which to begin the minimization (P),
* @param vectorDirection
* A vector direction along which to travel from P, (V)
* @param maximumDistanceToTravel
* The maximum distance to travel in the direction of V,
* @param maximumEvaluations
* The maximum number of function evaluations to identify the minimum,
* @param relativeErrorGoal
* The relative error target of the minimization,
* @param absoluteErrorGoal
* The absolute error target of the minimization.
* @return
* A lightweight immutable struct containing the vector solution and
* the evaluation of the function at this point.
*/
static public LineSearchResult doLineSearch(
final MultivariateFunction function,
final double[] startingPoint,
final double[] vectorDirection,
final double maximumDistanceToTravel,
final int maximumEvaluations,
final double relativeErrorGoal,
final double absoluteErrorGoal
) {
Preconditions.checkArgument(maximumEvaluations > 0);
Preconditions.checkArgument(relativeErrorGoal > 0. || absoluteErrorGoal > 0.);
Preconditions.checkArgument(maximumDistanceToTravel > 0.);
final LineSearchObjectiveFunction lineSearcher =
new LineSearchObjectiveFunction(function, startingPoint, vectorDirection);
final UnivariateOptimizer optimizer =
new BrentOptimizer(relativeErrorGoal, absoluteErrorGoal);
UnivariatePointValuePair result = optimizer.optimize(
new MaxEval(maximumEvaluations),
new UnivariateObjectiveFunction(lineSearcher),
GoalType.MINIMIZE,
new SearchInterval(0, maximumDistanceToTravel, 0)
);
final double[] vectorSolution = new double[startingPoint.length];
for(int i = 0; i< vectorDirection.length; ++i)
vectorSolution[i] = lineSearcher.startingPoint[i] +
lineSearcher.normalizedDirection[i] * result.getPoint();
final LineSearchResult solution =
new LineSearchResult(vectorSolution, result.getValue());
return solution;
}
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:59,代码来源:BrentLineSearch.java
示例9: search
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p
* Starting point.
* @param d
* Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d)
{
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction()
{
public double value(double alpha)
{
final double[] x = new double[n];
for (int i = 0; i < n; i++)
{
x[i] = p[i] + alpha * d[i];
}
applyBounds(x);
final double obj = BoundedNonLinearConjugateGradientOptimizer.this.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = BoundedNonLinearConjugateGradientOptimizer.this.getGoalType();
bracket.search(f, goal, 0, initialStep);
//System.out.printf("Bracket %f (%f) - %f (%f) - %f (%f)\n", bracket.getHi(), bracket.getFHi(),
// bracket.getMid(), bracket.getFMid(), bracket.getLo(), bracket.getFLo());
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(new MaxEval(Integer.MAX_VALUE), new UnivariateObjectiveFunction(f), goal,
new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()));
}
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:40,代码来源:BoundedNonLinearConjugateGradientOptimizer.java
示例10: search
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p
* Starting point.
* @param d
* Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d)
{
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction()
{
final double[] x = new double[n];
public double value(double alpha)
{
for (int i = 0; i < n; i++)
{
x[i] = p[i] + alpha * d[i];
}
// Ensure the point is within bounds
applyBounds(x);
return CustomPowellOptimizer.this.computeObjectiveValue(x);
}
};
final GoalType goal = CustomPowellOptimizer.this.getGoalType();
bracket.search(f, goal, 0, 1);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(new MaxEval(Integer.MAX_VALUE), new UnivariateObjectiveFunction(f), goal,
new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()));
}
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:39,代码来源:CustomPowellOptimizer.java
示例11: getOptimalTime
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Helper function to find the optimal point in time.
*
* @param start
* the start point
* @param place
* the place to find the optimal time for
* @param timeRange
* the lower and upper interval limits in which should be
* searched for the optimal value
* @param minWalkingTime
* minimum time required to walk from {@code start} to
* {@code place}
* @param starts
* number of start to be performed by the Brent optimizer
* @return optimal point in time and the optimal value of the objective
* function
*/
Pair<LocalDateTime, Double> getOptimalTime(GHPoint start, GHPoint place,
TimeRange<LocalDateTime> timeRange, long minWalkingTime,
int starts) {
// the objective function to be passed to the BrentOptimizer
UnivariateFunction univariateFunction = (x) -> {
LocalDateTime time = timeRange.getFrom().plusSeconds((long) x);
OptionalDouble value = objectiveFunction.value(time, start, place,
timeRange, minWalkingTime);
if (value.isPresent()) {
return value.getAsDouble();
} else {
// if no value is returned by the objectiveFunction than either
// the constrain has be violated or there is no value available
logger.debug("constrains violated! (time = " + time
+ ", timeRange = " + timeRange + ", lastWalkingTime = "
+ Utils.formatDurationMills(objectiveFunction
.getLastWalkingTime().getAsLong())
+ ", start = " + start + ", place = " + place + ")");
return Double.MAX_VALUE;
}
};
// interval used for optimization is 0 and the duration between the
// lower and upper bound in seconds
double lower = 0;
double upper = timeRange.durationInSeconds() + 1;
BrentOptimizer optimizer = new BrentOptimizer(RELATIVE_THRESHOLD,
ABSOLUTE_THRESHOLD);
MultiStartUnivariateOptimizer multiStartOptimizer = new MultiStartUnivariateOptimizer(
optimizer, starts, rng);
UnivariatePointValuePair res = multiStartOptimizer.optimize(
new MaxEval(MAX_EVAL), GOAL_TYPE,
new SearchInterval(lower, upper),
new UnivariateObjectiveFunction(univariateFunction));
return Pair.of(timeRange.getFrom().plusSeconds((long) res.getPoint()),
res.getValue());
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:59,代码来源:OptimalTimeFinder.java
示例12: maximize
import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair; //导入依赖的package包/类
/**
* Maximizes a univariate function using a grid search followed by Brent's algorithm.
*
* @param fn the likelihood function to minimize
* @param gridStart the lower bound for the grid search
* @param gridEnd the upper bound for the grid search
* @param gridStep step size for the grid search
* @param relErr relative error tolerance for Brent's algorithm
* @param absErr absolute error tolerance for Brent's algorithm
* @param maxIter maximum # of iterations to perform in Brent's algorithm
* @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm
*
* @return the value of the parameter that maximizes the function
*/
public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd,
double gridStep, double relErr, double absErr, int maxIter, int maxEval) {
Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep);
BrentOptimizer bo = new BrentOptimizer(relErr, absErr);
UnivariatePointValuePair max = bo.optimize(
new MaxIter(maxIter),
new MaxEval(maxEval),
new SearchInterval(interval.getInf(), interval.getSup()),
new UnivariateObjectiveFunction(fn),
GoalType.MAXIMIZE);
return max.getPoint();
}
开发者ID:googlegenomics,项目名称:dataflow-java,代码行数:27,代码来源:Solver.java
注:本文中的org.apache.commons.math3.optim.univariate.UnivariatePointValuePair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论