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.QRDecomposer;
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 SequentialGaussNewtonOptimizerWithQRTest
40 extends AbstractSequentialLeastSquaresOptimizerAbstractTest {
41
42 @Override
43 public int getMaxIterations() {
44 return 1000;
45 }
46
47 @Override
48 public void defineOptimizer(Evaluation evaluation) {
49 this.optimizer = new SequentialGaussNewtonOptimizer().
50 withDecomposer(new QRDecomposer(1.0e-11)).
51 withFormNormalEquations(false).
52 withEvaluation(evaluation);
53 }
54
55 @Override
56 @Test
57 public void testMoreEstimatedParametersUnsorted() {
58
59
60
61 try {
62 super.testMoreEstimatedParametersUnsorted();
63 fail(optimizer);
64 } catch (MathIllegalStateException mise) {
65 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, mise.getSpecifier());
66 }
67 }
68
69 @Test
70 public 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 defineOptimizer(null);
86 optimizer.optimize(lsp);
87 fail(optimizer);
88 } catch (MathIllegalStateException e) {
89 Assert.assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED,
90 e.getSpecifier());
91 }
92 }
93
94
95 @Override
96 @Test
97 public void testHahn1() throws IOException {
98 try {
99
100
101
102
103 super.testHahn1();
104 } catch (MathIllegalStateException mise) {
105 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, mise.getSpecifier());
106 }
107 }
108
109 }