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