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 GaussNewtonOptimizerWithQRTest
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.QR);
47 }
48
49 @Override
50 @Test
51 public void testMoreEstimatedParametersUnsorted() {
52
53
54
55 try{
56 super.testMoreEstimatedParametersUnsorted();
57 fail(optimizer);
58 }catch (ConvergenceException e){
59
60 }
61 }
62
63 @Test
64 public void testMaxEvaluations() throws Exception {
65 try{
66 CircleVectorial circle = new CircleVectorial();
67 circle.addPoint( 30.0, 68.0);
68 circle.addPoint( 50.0, -6.0);
69 circle.addPoint(110.0, -20.0);
70 circle.addPoint( 35.0, 15.0);
71 circle.addPoint( 45.0, 97.0);
72
73 LeastSquaresProblem lsp = builder(circle)
74 .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
75 .maxIterations(Integer.MAX_VALUE)
76 .start(new double[]{98.680, 47.345})
77 .build();
78
79 optimizer.optimize(lsp);
80
81 fail(optimizer);
82 }catch (TooManyEvaluationsException e){
83
84 }
85 }
86
87 @Override
88 @Test
89 public void testCircleFittingBadInit() {
90
91
92
93 try{
94 super.testCircleFittingBadInit();
95 fail(optimizer);
96 }catch (ConvergenceException e){
97
98 }
99 }
100
101 @Override
102 @Test
103 public void testHahn1()
104 throws IOException {
105
106
107
108
109 try{
110 super.testHahn1();
111 fail(optimizer);
112 } catch (ConvergenceException e){
113
114 } catch (TooManyEvaluationsException e){
115
116 }
117 }
118 }