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 java.io.IOException;
21
22 import org.hipparchus.exception.LocalizedCoreFormats;
23 import org.hipparchus.exception.MathIllegalStateException;
24 import org.hipparchus.linear.LUDecomposer;
25 import org.hipparchus.optim.LocalizedOptimFormats;
26 import org.hipparchus.optim.SimpleVectorValueChecker;
27 import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem.Evaluation;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31
32
33
34
35
36
37
38
39 public class SequentialGaussNewtonOptimizerWithLUTest
40 extends AbstractSequentialLeastSquaresOptimizerAbstractTest {
41
42
43
44 @Override
45 public int getMaxIterations() {
46 return 1000;
47 }
48
49 @Override
50 public void defineOptimizer(Evaluation evaluation) {
51 this.optimizer = new SequentialGaussNewtonOptimizer().
52 withDecomposer(new LUDecomposer(1.0e-11)).
53 withFormNormalEquations(true).
54 withEvaluation(evaluation);
55 }
56
57 @Override
58 @Test
59 public void testMoreEstimatedParametersSimple() {
60 try {
61
62
63
64 super.testMoreEstimatedParametersSimple();
65 fail(optimizer);
66 } catch (MathIllegalStateException e) {
67 Assert.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 fail(optimizer);
81 } catch (MathIllegalStateException e) {
82 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
83 e.getSpecifier());
84 }
85 }
86
87 @Test
88 public 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 defineOptimizer(null);
104 optimizer.optimize(lsp);
105
106 fail(optimizer);
107 } catch (MathIllegalStateException e) {
108 Assert.assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED, e.getSpecifier());
109 }
110 }
111
112
113 @Override
114 @Test
115 public void testHahn1()
116 throws IOException {
117
118
119
120
121 try {
122 super.testHahn1();
123 } catch (MathIllegalStateException e) {
124 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e.getSpecifier());
125 }
126 }
127 }