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.CholeskyDecomposer;
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 GaussNewtonOptimizerWithCholeskyTest
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 CholeskyDecomposer(1.0e-11, 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 CircleVectorial circle = new CircleVectorial();
89 circle.addPoint( 30.0, 68.0);
90 circle.addPoint( 50.0, -6.0);
91 circle.addPoint(110.0, -20.0);
92 circle.addPoint( 35.0, 15.0);
93 circle.addPoint( 45.0, 97.0);
94
95 LeastSquaresProblem lsp = builder(circle)
96 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
97 .maxIterations(Integer.MAX_VALUE)
98 .start(new double[]{98.680, 47.345})
99 .build();
100
101 try {
102 optimizer.optimize(lsp);
103 fail(optimizer);
104 } catch (MathIllegalStateException e) {
105 Assert.assertEquals(LocalizedCoreFormats.MAX_COUNT_EXCEEDED, e.getSpecifier());
106 }
107 }
108
109 @Override
110 @Test
111 public void testCircleFittingBadInit() {
112 try {
113
114
115
116 super.testCircleFittingBadInit();
117 fail(optimizer);
118 } catch (MathIllegalStateException e) {
119 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
120 e.getSpecifier());
121 }
122
123 }
124
125 @Override
126 @Test
127 public void testHahn1()
128 throws IOException {
129 try {
130
131
132
133
134 super.testHahn1();
135 fail(optimizer);
136 } catch (MathIllegalStateException e) {
137 Assert.assertEquals(LocalizedOptimFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM,
138 e.getSpecifier());
139 }
140 }
141
142 }