1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.optim.nonlinear.vector.leastsquares;
19
20 import org.hipparchus.exception.LocalizedCoreFormats;
21 import org.hipparchus.exception.MathIllegalStateException;
22 import org.hipparchus.linear.LUDecomposer;
23 import org.hipparchus.optim.LocalizedOptimFormats;
24 import org.hipparchus.optim.SimpleVectorValueChecker;
25 import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem.Evaluation;
26 import org.junit.jupiter.api.Test;
27
28 import java.io.IOException;
29
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31
32
33
34
35
36
37
38
39
40 public class SequentialGaussNewtonOptimizerWithLUTest
41 extends AbstractSequentialLeastSquaresOptimizerAbstractTest {
42
43
44
45 @Override
46 public int getMaxIterations() {
47 return 1000;
48 }
49
50 @Override
51 public void defineOptimizer(Evaluation evaluation) {
52 this.optimizer = new SequentialGaussNewtonOptimizer().
53 withDecomposer(new LUDecomposer(1.0e-11)).
54 withFormNormalEquations(true).
55 withEvaluation(evaluation);
56 }
57
58 @Override
59 @Test
60 public void testMoreEstimatedParametersSimple() {
61 try {
62
63
64
65 super.testMoreEstimatedParametersSimple();
66 customFail(optimizer);
67 } catch (MathIllegalStateException e) {
68 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
69 e.getSpecifier());
70 }
71 }
72
73 @Override
74 @Test
75 public void testMoreEstimatedParametersUnsorted() {
76 try {
77
78
79
80 super.testMoreEstimatedParametersUnsorted();
81 customFail(optimizer);
82 } catch (MathIllegalStateException e) {
83 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
84 e.getSpecifier());
85 }
86 }
87
88 @Test
89 void testMaxEvaluations() throws Exception {
90 try {
91 CircleVectorial circle = new CircleVectorial();
92 circle.addPoint( 30.0, 68.0);
93 circle.addPoint( 50.0, -6.0);
94 circle.addPoint(110.0, -20.0);
95 circle.addPoint( 35.0, 15.0);
96 circle.addPoint( 45.0, 97.0);
97
98 LeastSquaresProblem lsp = builder(circle)
99 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
100 .maxIterations(Integer.MAX_VALUE)
101 .start(new double[]{98.680, 47.345})
102 .build();
103
104 defineOptimizer(null);
105 optimizer.optimize(lsp);
106
107 customFail(optimizer);
108 } catch (MathIllegalStateException e) {
109 assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED, e.getSpecifier());
110 }
111 }
112
113
114 @Override
115 @Test
116 public void testHahn1()
117 throws IOException {
118
119
120
121
122 try {
123 super.testHahn1();
124 } catch (MathIllegalStateException e) {
125 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e.getSpecifier());
126 }
127 }
128 }