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