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