簡體   English   中英

如何從LeastSquareOptimizer獲得最后一次猜測?

[英]How to get the last best guess from LeastSquareOptimizer?

有沒有辦法獲得LeastSquaresOptimizer的最后猜測?

我正在使用Apache Commons Math來執行最小二乘優化。 為此,我必須提供maxEvaluations()maxIterations()值。 問題是,如果優化在達到最大值的evaulations或迭代之前沒有收斂,則返回org.apache.commons.math4.exception.TooManyIterationsException: illegal state: maximal count (6,000) exceeded: iterations 如果發生這種情況,我想看看優化器的最后一次猜測是什么。 我該怎么做呢?

LeastSquaresProblem problem = new LeastSquaresBuilder()
                                     .start(new double[]{0,0,0,1,1,1,0,0,0})
                                     .model(costFunc)
                                     .target(gravity)
                                     .lazyEvaluation(false)
                                     .maxEvaluations(150000)
                                     .maxIterations(6000)
                                     .build();

LeastSquaresOptimizer.Optimum optimum;
try {
    optimum = new LevenbergMarquardtOptimizer()
                      .withCostRelativeTolerance(1.0e-10)
                      .optimize(problem);
} catch (Exception e) {
    throw new Exception(e);
} 

可能有更好的方法,但手動存儲最佳猜測呢? 優化器重復調用problem::evaluate(RealVector point) 當您使用自己的函數替換它時,您將獲得輸入和輸出。

這種替換應該是相當簡單的使用

LeastSquaresProblem wrappedProblem = new LeastSquaresAdapter(problem) {
    @Override public LeastSquaresProblem.Evaluation evaluate(RealVector point) {
        LeastSquaresProblem.Evaluation result = super(point);
        ... store the point and the result, if it's an improvement
        return result;
    }
}

我擔心,數據是可變的,所以你需要克隆它,所以它不會被覆蓋。


我可能錯了,因為我沒有這個庫的經驗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM