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.QRDecomposer;
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 SequentialGaussNewtonOptimizerWithQRTest
41 extends AbstractSequentialLeastSquaresOptimizerAbstractTest {
42
43 @Override
44 public int getMaxIterations() {
45 return 1000;
46 }
47
48 @Override
49 public void defineOptimizer(Evaluation evaluation) {
50 this.optimizer = new SequentialGaussNewtonOptimizer().
51 withDecomposer(new QRDecomposer(1.0e-11)).
52 withFormNormalEquations(false).
53 withEvaluation(evaluation);
54 }
55
56 @Override
57 @Test
58 public void testMoreEstimatedParametersUnsorted() {
59
60
61
62 try {
63 super.testMoreEstimatedParametersUnsorted();
64 customFail(optimizer);
65 } catch (MathIllegalStateException mise) {
66 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, mise.getSpecifier());
67 }
68 }
69
70 @Test
71 void testMaxEvaluations() throws Exception {
72 try {
73 CircleVectorial circle = new CircleVectorial();
74 circle.addPoint( 30.0, 68.0);
75 circle.addPoint( 50.0, -6.0);
76 circle.addPoint(110.0, -20.0);
77 circle.addPoint( 35.0, 15.0);
78 circle.addPoint( 45.0, 97.0);
79
80 LeastSquaresProblem lsp = builder(circle)
81 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
82 .maxIterations(Integer.MAX_VALUE)
83 .start(new double[]{98.680, 47.345})
84 .build();
85
86 defineOptimizer(null);
87 optimizer.optimize(lsp);
88 customFail(optimizer);
89 } catch (MathIllegalStateException e) {
90 assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED,
91 e.getSpecifier());
92 }
93 }
94
95
96 @Override
97 @Test
98 public void testHahn1() throws IOException {
99 try {
100
101
102
103
104 super.testHahn1();
105 } catch (MathIllegalStateException mise) {
106 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, mise.getSpecifier());
107 }
108 }
109
110 }