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.LocalizedCoreFormats;
26 import org.hipparchus.exception.MathIllegalStateException;
27 import org.hipparchus.linear.LUDecomposer;
28 import org.hipparchus.optim.LocalizedOptimFormats;
29 import org.hipparchus.optim.SimpleVectorValueChecker;
30 import org.junit.jupiter.api.Test;
31
32 import java.io.IOException;
33
34 import static org.junit.jupiter.api.Assertions.assertEquals;
35
36
37
38
39
40
41
42
43
44 public class GaussNewtonOptimizerWithLUTest
45 extends AbstractLeastSquaresOptimizerAbstractTest {
46
47 @Override
48 public int getMaxIterations() {
49 return 1000;
50 }
51
52 @Override
53 public LeastSquaresOptimizer getOptimizer() {
54 return new GaussNewtonOptimizer(new LUDecomposer(1.0e-11), true);
55 }
56
57 @Override
58 @Test
59 public void testMoreEstimatedParametersSimple() {
60 try {
61
62
63
64 super.testMoreEstimatedParametersSimple();
65 customFail(optimizer);
66 } catch (MathIllegalStateException e) {
67 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
68 e.getSpecifier());
69 }
70 }
71
72 @Override
73 @Test
74 public void testMoreEstimatedParametersUnsorted() {
75 try {
76
77
78
79 super.testMoreEstimatedParametersUnsorted();
80 customFail(optimizer);
81 } catch (MathIllegalStateException e) {
82 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
83 e.getSpecifier());
84 }
85 }
86
87 @Test
88 void testMaxEvaluations() throws Exception {
89 try {
90 CircleVectorial circle = new CircleVectorial();
91 circle.addPoint( 30.0, 68.0);
92 circle.addPoint( 50.0, -6.0);
93 circle.addPoint(110.0, -20.0);
94 circle.addPoint( 35.0, 15.0);
95 circle.addPoint( 45.0, 97.0);
96
97 LeastSquaresProblem lsp = builder(circle)
98 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
99 .maxIterations(Integer.MAX_VALUE)
100 .start(new double[]{98.680, 47.345})
101 .build();
102
103 optimizer.optimize(lsp);
104
105 customFail(optimizer);
106 } catch (MathIllegalStateException e) {
107 assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED, e.getSpecifier());
108 }
109 }
110
111 @Override
112 @Test
113 public void testCircleFittingBadInit() {
114 try {
115
116
117
118 super.testCircleFittingBadInit();
119 customFail(optimizer);
120 } catch (MathIllegalStateException e) {
121 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
122 e.getSpecifier());
123 }
124 }
125
126 @Override
127 @Test
128 public void testHahn1() throws IOException {
129 try {
130
131
132
133
134 super.testHahn1();
135 customFail(optimizer);
136 } catch (MathIllegalStateException e) {
137 assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
138 e.getSpecifier());
139 }
140 }
141
142 }