1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math4.legacy.fitting.leastsquares;
19
20 import org.apache.commons.math4.legacy.exception.ConvergenceException;
21 import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
22 import org.apache.commons.math4.legacy.fitting.leastsquares.GaussNewtonOptimizer.Decomposition;
23 import org.apache.commons.math4.legacy.optim.SimpleVectorValueChecker;
24 import org.junit.Test;
25
26 import java.io.IOException;
27
28
29
30
31
32
33
34
35
36 public class GaussNewtonOptimizerWithLUTest
37 extends AbstractLeastSquaresOptimizerAbstractTest {
38
39 @Override
40 public int getMaxIterations() {
41 return 1000;
42 }
43
44 @Override
45 public LeastSquaresOptimizer getOptimizer() {
46 return new GaussNewtonOptimizer(Decomposition.LU);
47 }
48
49 @Override
50 @Test
51 public void testMoreEstimatedParametersSimple() {
52
53
54
55 try {
56 super.testMoreEstimatedParametersSimple();
57 fail(optimizer);
58 } catch (ConvergenceException e) {
59
60 }
61 }
62
63 @Override
64 @Test
65 public void testMoreEstimatedParametersUnsorted() {
66
67
68
69 try{
70 super.testMoreEstimatedParametersUnsorted();
71 fail(optimizer);
72 }catch (ConvergenceException e){
73
74 }
75 }
76
77 @Test
78 public void testMaxEvaluations() throws Exception {
79 try{
80 CircleVectorial circle = new CircleVectorial();
81 circle.addPoint( 30.0, 68.0);
82 circle.addPoint( 50.0, -6.0);
83 circle.addPoint(110.0, -20.0);
84 circle.addPoint( 35.0, 15.0);
85 circle.addPoint( 45.0, 97.0);
86
87 LeastSquaresProblem lsp = builder(circle)
88 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
89 .maxIterations(Integer.MAX_VALUE)
90 .start(new double[]{98.680, 47.345})
91 .build();
92
93 optimizer.optimize(lsp);
94
95 fail(optimizer);
96 }catch (TooManyEvaluationsException e){
97
98 }
99 }
100
101 @Override
102 @Test
103 public void testCircleFittingBadInit() {
104
105
106
107 try{
108 super.testCircleFittingBadInit();
109 fail(optimizer);
110 }catch (ConvergenceException e){
111
112 }
113 }
114
115 @Override
116 @Test
117 public void testHahn1()
118 throws IOException {
119
120
121
122
123 try{
124 super.testHahn1();
125 fail(optimizer);
126 } catch (ConvergenceException e){
127
128 } catch (TooManyEvaluationsException e){
129
130 }
131 }
132 }