本文整理汇总了Java中org.apache.commons.math3.optim.ConvergenceChecker.converged方法的典型用法代码示例。如果您正苦于以下问题:Java ConvergenceChecker.converged方法的具体用法?Java ConvergenceChecker.converged怎么用?Java ConvergenceChecker.converged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.optim.ConvergenceChecker
的用法示例。
在下文中一共展示了ConvergenceChecker.converged方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluationChecker
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/**
* View a convergence checker specified for a {@link PointVectorValuePair} as one
* specified for an {@link Evaluation}.
*
* @param checker the convergence checker to adapt.
* @return a convergence checker that delegates to {@code checker}.
*/
public static ConvergenceChecker<Evaluation> evaluationChecker(final ConvergenceChecker<PointVectorValuePair> checker) {
return new ConvergenceChecker<Evaluation>() {
/** {@inheritDoc} */
public boolean converged(final int iteration,
final Evaluation previous,
final Evaluation current) {
return checker.converged(
iteration,
new PointVectorValuePair(
previous.getPoint().toArray(),
previous.getResiduals().toArray(),
false),
new PointVectorValuePair(
current.getPoint().toArray(),
current.getResiduals().toArray(),
false)
);
}
};
}
示例2: evaluationChecker
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/**
* View a convergence checker specified for a {@link PointVectorValuePair} as one
* specified for an {@link Evaluation}.
*
* @param checker the convergence checker to adapt.
* @return a convergence checker that delegates to {@code checker}.
*/
public static ConvergenceChecker<Evaluation> evaluationChecker(final ConvergenceChecker<PointVectorValuePair> checker) {
return new ConvergenceChecker<Evaluation>() {
public boolean converged(final int iteration,
final Evaluation previous,
final Evaluation current) {
return checker.converged(
iteration,
new PointVectorValuePair(
previous.getPoint().toArray(),
previous.getResiduals().toArray(),
false),
new PointVectorValuePair(
current.getPoint().toArray(),
current.getResiduals().toArray(),
false)
);
}
};
}
示例3: optimize
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Optimum optimize(final LeastSquaresProblem lsp) {
//create local evaluation and iteration counts
final Incrementor evaluationCounter = lsp.getEvaluationCounter();
final Incrementor iterationCounter = lsp.getIterationCounter();
final ConvergenceChecker<Evaluation> checker
= lsp.getConvergenceChecker();
// Computation will be useless without a checker (see "for-loop").
if (checker == null) {
throw new NullArgumentException();
}
RealVector currentPoint = lsp.getStart();
// iterate until convergence is reached
Evaluation current = null;
while (true) {
iterationCounter.incrementCount();
// evaluate the objective function and its jacobian
Evaluation previous = current;
// Value of the objective function at "currentPoint".
evaluationCounter.incrementCount();
current = lsp.evaluate(currentPoint);
final RealVector currentResiduals = current.getResiduals();
final RealMatrix weightedJacobian = current.getJacobian();
currentPoint = current.getPoint();
// Check convergence.
if (previous != null &&
checker.converged(iterationCounter.getCount(), previous, current)) {
return new OptimumImpl(current,
evaluationCounter.getCount(),
iterationCounter.getCount());
}
// solve the linearized least squares problem
final RealVector dX = this.decomposition.solve(weightedJacobian, currentResiduals);
// update the estimated parameters
currentPoint = currentPoint.add(dX);
}
}
示例4: doOptimize
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
checkParameters();
// Indirect call to "computeObjectiveValue" in order to update the
// evaluations counter.
final MultivariateFunction evalFunc
= new MultivariateFunction() {
/** {@inheritDoc} */
public double value(double[] point) {
return computeObjectiveValue(point);
}
};
final boolean isMinim = getGoalType() == GoalType.MINIMIZE;
final Comparator<PointValuePair> comparator
= new Comparator<PointValuePair>() {
/** {@inheritDoc} */
public int compare(final PointValuePair o1,
final PointValuePair o2) {
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
// Initialize search.
simplex.build(getStartPoint());
simplex.evaluate(evalFunc, comparator);
PointValuePair[] previous = null;
int iteration = 0;
final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
while (true) {
if (getIterations() > 0) {
boolean converged = true;
for (int i = 0; i < simplex.getSize(); i++) {
PointValuePair prev = previous[i];
converged = converged &&
checker.converged(iteration, prev, simplex.getPoint(i));
}
if (converged) {
// We have found an optimum.
return simplex.getPoint(0);
}
}
// We still need to search.
previous = simplex.getPoints();
simplex.iterate(evalFunc, comparator);
incrementIterationCount();
}
}
示例5: optimize
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Optimum optimize(final LeastSquaresProblem lsp) {
//create local evaluation and iteration counts
final Incrementor evaluationCounter = lsp.getEvaluationCounter();
final Incrementor iterationCounter = lsp.getIterationCounter();
final ConvergenceChecker<Evaluation> checker
= lsp.getConvergenceChecker();
// Computation will be useless without a checker (see "for-loop").
if (checker == null) {
throw new NullArgumentException();
}
RealVector currentPoint = lsp.getStart();
// iterate until convergence is reached
Evaluation current = null;
while (true) {
iterationCounter.incrementCount();
// evaluate the objective function and its jacobian
Evaluation previous = current;
// Value of the objective function at "currentPoint".
evaluationCounter.incrementCount();
current = lsp.evaluate(currentPoint);
final RealVector currentResiduals = current.getResiduals();
final RealMatrix weightedJacobian = current.getJacobian();
currentPoint = current.getPoint();
// Check convergence.
if (previous != null) {
if (checker.converged(iterationCounter.getCount(), previous, current)) {
return new OptimumImpl(
current,
evaluationCounter.getCount(),
iterationCounter.getCount());
}
}
// solve the linearized least squares problem
final RealVector dX = this.decomposition.solve(weightedJacobian, currentResiduals);
// update the estimated parameters
currentPoint = currentPoint.add(dX);
}
}
示例6: doOptimize
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
checkParameters();
// Indirect call to "computeObjectiveValue" in order to update the
// evaluations counter.
final MultivariateFunction evalFunc
= new MultivariateFunction() {
public double value(double[] point) {
return computeObjectiveValue(point);
}
};
final boolean isMinim = getGoalType() == GoalType.MINIMIZE;
final Comparator<PointValuePair> comparator
= new Comparator<PointValuePair>() {
public int compare(final PointValuePair o1,
final PointValuePair o2) {
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
// Initialize search.
simplex.build(getStartPoint());
simplex.evaluate(evalFunc, comparator);
PointValuePair[] previous = null;
int iteration = 0;
final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
while (true) {
if (getIterations() > 0) {
boolean converged = true;
for (int i = 0; i < simplex.getSize(); i++) {
PointValuePair prev = previous[i];
converged = converged &&
checker.converged(iteration, prev, simplex.getPoint(i));
}
if (converged) {
// We have found an optimum.
return simplex.getPoint(0);
}
}
// We still need to search.
previous = simplex.getPoints();
simplex.iterate(evalFunc, comparator);
incrementIterationCount();
}
}
示例7: doOptimize
import org.apache.commons.math3.optim.ConvergenceChecker; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize()
{
final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
double[] p = getStartPoint();
// Assume minimisation
sign = -1;
LineStepSearch lineSearch = new LineStepSearch();
// In case there are no restarts
if (restarts <= 0)
return bfgsWithRoundoffCheck(checker, p, lineSearch);
PointValuePair lastResult = null;
PointValuePair result = null;
//int lastConverge = 0;
int iteration = 0;
//int initialConvergenceIteration = 0;
//int[] count = new int[3];
while (iteration <= restarts)
{
iteration++;
result = bfgsWithRoundoffCheck(checker, p, lineSearch);
//count[converged]++;
//if (lastResult == null)
// initialConvergenceIteration = getIterations();
if (converged == GRADIENT)
{
// If no gradient remains then we cannot move anywhere so return
break;
}
if (lastResult != null)
{
//// Check if the optimum was improved using the last convergence criteria
//if (lastConverge == CHECKER)
//{
// if (checker.converged(getIterations(), lastResult, result))
// {
// break;
// }
//}
//else
//{
// if (positionChecker.converged(lastResult.getPointRef(), result.getPointRef()))
// {
// break;
// }
//}
// Check if the optimum was improved using the convergence criteria
if (checker != null && checker.converged(getIterations(), lastResult, result))
{
break;
}
if (positionChecker.converged(getIterations(), lastResult, result))
{
break;
}
}
// Store the new optimum and repeat
lastResult = result;
//lastConverge = converged;
p = lastResult.getPointRef();
}
//System.out.printf("Iter=%d (%d > %d): %s\n", iteration, initialConvergenceIteration, getIterations(),
// java.util.Arrays.toString(count));
return result;
}