Hello,
We are encountering some difficulties to use BracketingNthOrderBrentSolver. We have found that the solver continue iterations even after finding a solution.
It is like it searches for more precise solution besides the accuracy required at initialization.
This is a problem in our case because the function is executing some heavy/long computations and we cannot afford some extra iterations.
We have written a junit test to demonstrate the problem :
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.hipparchus.analysis.UnivariateFunction;
import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
import org.hipparchus.util.FastMath;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class HipparchusSolverTest {
private static class FunctionHipparcus implements UnivariateFunction {
List<Double> values = new ArrayList<>();
@Override
public double value(double x) {
double value = -0.01 * x * x + 20;
values.add(value);
return value;
}
}
public static final double ABSOLUTE_ACCURACY = 0.1;
private static final double VALUE_ACCURACY = 1.;
@Test
public void testSolverStopIteratingOnceSolutionIsFound() {
BracketingNthOrderBrentSolver solver = new BracketingNthOrderBrentSolver(1e-14, ABSOLUTE_ACCURACY, VALUE_ACCURACY, 5);
FunctionHipparcus function = new FunctionHipparcus();
solver.solve(100, function, -100, 100);
Assertions.assertEquals(1, function.values.stream().filter(value -> FastMath.abs(value) < VALUE_ACCURACY).count(), //
() -> String.format("Too many iterations : \n%s\n",
function.values.stream().map(value -> String.format("%f.3", value)).collect(Collectors.joining("\n"))));
}
}
It might be because of the relative accuracy ? We have tried some several relative accuracy but it is hard to find a relative accuracy that allow to find a solution below the value accuracy and without over-iterating.
Could you help us ? Do you think it is a bug or a bad use ?
Best regards,
Anne-Laure