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