本文整理汇总了Java中org.apache.commons.math3.optim.ConvergenceChecker类的典型用法代码示例。如果您正苦于以下问题:Java ConvergenceChecker类的具体用法?Java ConvergenceChecker怎么用?Java ConvergenceChecker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConvergenceChecker类属于org.apache.commons.math3.optim包,在下文中一共展示了ConvergenceChecker类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem}
* from the given elements. There will be no weights applied (unit weights).
*
* @param model the model function. Produces the computed values.
* @param observed the observed (target) values
* @param start the initial guess.
* @param weight the weight matrix
* @param checker convergence checker
* @param maxEvaluations the maximum number of times to evaluate the model
* @param maxIterations the maximum number to times to iterate in the algorithm
* @param lazyEvaluation Whether the call to {@link Evaluation#evaluate(RealVector)}
* will defer the evaluation until access to the value is requested.
* @param paramValidator Model parameters validator.
* @return the specified General Least Squares problem.
*
* @since 3.4
*/
public static LeastSquaresProblem create(final MultivariateJacobianFunction model,
final RealVector observed,
final RealVector start,
final RealMatrix weight,
final ConvergenceChecker<Evaluation> checker,
final int maxEvaluations,
final int maxIterations,
final boolean lazyEvaluation,
final ParameterValidator paramValidator) {
final LeastSquaresProblem p = new LocalLeastSquaresProblem(model,
observed,
start,
checker,
maxEvaluations,
maxIterations,
lazyEvaluation,
paramValidator);
if (weight != null) {
return weightMatrix(p, weight);
} else {
return p;
}
}
示例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>() {
/** {@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)
);
}
};
}
示例3: LocalLeastSquaresProblem
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* Create a {@link LeastSquaresProblem} from the given data.
*
* @param model the model function
* @param target the observed data
* @param start the initial guess
* @param checker the convergence checker
* @param maxEvaluations the allowed evaluations
* @param maxIterations the allowed iterations
* @param lazyEvaluation Whether the call to {@link Evaluation#evaluate(RealVector)}
* will defer the evaluation until access to the value is requested.
* @param paramValidator Model parameters validator.
*/
LocalLeastSquaresProblem(final MultivariateJacobianFunction model,
final RealVector target,
final RealVector start,
final ConvergenceChecker<Evaluation> checker,
final int maxEvaluations,
final int maxIterations,
final boolean lazyEvaluation,
final ParameterValidator paramValidator) {
super(maxEvaluations, maxIterations, checker);
this.target = target;
this.model = model;
this.start = start;
this.lazyEvaluation = lazyEvaluation;
this.paramValidator = paramValidator;
if (lazyEvaluation &&
!(model instanceof ValueAndJacobianFunction)) {
// Lazy evaluation requires that value and Jacobian
// can be computed separately.
throw new MathIllegalStateException(LocalizedFormats.INVALID_IMPLEMENTATION,
model.getClass().getName());
}
}
示例4: NonLinearConjugateGradientOptimizer
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* @param updateFormula formula to use for updating the β parameter,
* must be one of {@link Formula#FLETCHER_REEVES} or
* {@link Formula#POLAK_RIBIERE}.
* @param checker Convergence checker.
* @param preconditioner Preconditioner.
* @param relativeTolerance Relative threshold for line search.
* @param absoluteTolerance Absolute threshold for line search.
* @param initialBracketingRange Extent of the initial interval used to
* find an interval that brackets the optimum in order to perform the
* line search.
*
* @see LineSearch#LineSearch(MultivariateOptimizer,double,double,double)
* @since 3.3
*/
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
ConvergenceChecker<PointValuePair> checker,
double relativeTolerance,
double absoluteTolerance,
double initialBracketingRange,
final Preconditioner preconditioner) {
super(checker);
this.updateFormula = updateFormula;
this.preconditioner = preconditioner;
line = new LineSearch(this,
relativeTolerance,
absoluteTolerance,
initialBracketingRange);
}
示例5: PowellOptimizer
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* This constructor allows to specify a user-defined convergence checker,
* in addition to the parameters that control the default convergence
* checking procedure and the line search tolerances.
*
* @param rel Relative threshold for this optimizer.
* @param abs Absolute threshold for this optimizer.
* @param lineRel Relative threshold for the internal line search optimizer.
* @param lineAbs Absolute threshold for the internal line search optimizer.
* @param checker Convergence checker.
* @throws NotStrictlyPositiveException if {@code abs <= 0}.
* @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
*/
public PowellOptimizer(double rel,
double abs,
double lineRel,
double lineAbs,
ConvergenceChecker<PointValuePair> checker) {
super(checker);
if (rel < MIN_RELATIVE_TOLERANCE) {
throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
}
if (abs <= 0) {
throw new NotStrictlyPositiveException(abs);
}
relativeThreshold = rel;
absoluteThreshold = abs;
// Create the line search optimizer.
line = new LineSearch(this,
lineRel,
lineAbs,
1d);
}
示例6: CMAESOptimizer
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* @param maxIterations Maximal number of iterations.
* @param stopFitness Whether to stop if objective function value is smaller than
* {@code stopFitness}.
* @param isActiveCMA Chooses the covariance matrix update method.
* @param diagonalOnly Number of initial iterations, where the covariance matrix
* remains diagonal.
* @param checkFeasableCount Determines how often new random objective variables are
* generated in case they are out of bounds.
* @param random Random generator.
* @param generateStatistics Whether statistic data is collected.
* @param checker Convergence checker.
*
* @since 3.1
*/
public CMAESOptimizer(int maxIterations,
double stopFitness,
boolean isActiveCMA,
int diagonalOnly,
int checkFeasableCount,
RandomGenerator random,
boolean generateStatistics,
ConvergenceChecker<PointValuePair> checker) {
super(checker);
this.maxIterations = maxIterations;
this.stopFitness = stopFitness;
this.isActiveCMA = isActiveCMA;
this.diagonalOnly = diagonalOnly;
this.checkFeasableCount = checkFeasableCount;
this.random = random;
this.generateStatistics = generateStatistics;
}
示例7: 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)
);
}
};
}
示例8: testEvaluationCount
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
@Test
public void testEvaluationCount() {
//setup
LeastSquaresProblem lsp = new LinearProblem(new double[][] {{1}}, new double[] {1})
.getBuilder()
.checker(new ConvergenceChecker<Evaluation>() {
public boolean converged(int iteration, Evaluation previous, Evaluation current) {
return true;
}
})
.build();
//action
Optimum optimum = optimizer.optimize(lsp);
//verify
//check iterations and evaluations are not switched.
Assert.assertThat(optimum.getIterations(), is(1));
Assert.assertThat(optimum.getEvaluations(), is(2));
}
示例9: testPointCopy
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
@Test
public void testPointCopy() {
LinearProblem problem = new LinearProblem(new double[][]{
{1, 0, 0},
{-1, 1, 0},
{0, -1, 1}
}, new double[]{1, 1, 1});
//mutable boolean
final boolean[] checked = {false};
final LeastSquaresBuilder builder = problem.getBuilder()
.checker(new ConvergenceChecker<Evaluation>() {
public boolean converged(int iteration, Evaluation previous, Evaluation current) {
Assert.assertThat(
previous.getPoint(),
not(sameInstance(current.getPoint())));
Assert.assertArrayEquals(new double[3], previous.getPoint().toArray(), 0);
Assert.assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOl);
checked[0] = true;
return true;
}
});
optimizer.optimize(builder.build());
Assert.assertThat(checked[0], is(true));
}
示例10: testConverged
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/** check {@link ConvergenceChecker#converged(int, Object, Object)}. */
@Test
public void testConverged() {
//setup
ConvergenceChecker<Evaluation> checker = new EvaluationRmsChecker(0.1, 1);
Evaluation e200 = mockEvaluation(200);
Evaluation e1 = mockEvaluation(1);
//action + verify
//just matches rel tol
Assert.assertEquals(true, checker.converged(0, e200, mockEvaluation(210)));
//just matches abs tol
Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.9)));
//matches both
Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.01)));
//matches neither
Assert.assertEquals(false, checker.converged(0, e200, mockEvaluation(300)));
}
示例11: PowellOptimizer
import org.apache.commons.math3.optim.ConvergenceChecker; //导入依赖的package包/类
/**
* This constructor allows to specify a user-defined convergence checker,
* in addition to the parameters that control the default convergence
* checking procedure and the line search tolerances.
*
* @param rel Relative threshold for this optimizer.
* @param abs Absolute threshold for this optimizer.
* @param lineRel Relative threshold for the internal line search optimizer.
* @param lineAbs Absolute threshold for the internal line search optimizer.
* @param checker Convergence checker.
* @throws NotStrictlyPositiveException if {@code abs <= 0}.
* @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
*/
public PowellOptimizer(double rel,
double abs,
double lineRel,
double lineAbs,
ConvergenceChecker<PointValuePair> checker) {
super(checker);
if (rel < MIN_RELATIVE_TOLERANCE) {
throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
}
if (abs <= 0) {
throw new NotStrictlyPositiveException(abs);
}
relativeThreshold = rel;
absoluteThreshold = abs;
// Create the line search optimizer.
line = new LineSearch(lineRel,
lineAbs);
}