1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.optim.nonlinear.vector.leastsquares;
18
19 import org.hipparchus.linear.RealMatrix;
20 import org.hipparchus.linear.RealVector;
21 import org.hipparchus.optim.ConvergenceChecker;
22 import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem.Evaluation;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26
27 public class EvaluationRmsCheckerTest {
28
29
30 @Test
31 public void testConverged() {
32
33 ConvergenceChecker<Evaluation> checker = new EvaluationRmsChecker(0.1, 1);
34 Evaluation e200 = mockEvaluation(200);
35 Evaluation e1 = mockEvaluation(1);
36
37
38
39 Assert.assertEquals(true, checker.converged(0, e200, mockEvaluation(210)));
40
41 Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.9)));
42
43 Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.01)));
44
45 Assert.assertEquals(false, checker.converged(0, e200, mockEvaluation(300)));
46 }
47
48
49
50
51
52
53
54 private static Evaluation mockEvaluation(final double rms) {
55 return new Evaluation() {
56 public RealMatrix getCovariances(double threshold) {
57 return null;
58 }
59
60 public RealVector getSigma(double covarianceSingularityThreshold) {
61 return null;
62 }
63
64 public double getRMS() {
65 return rms;
66 }
67
68 public RealMatrix getJacobian() {
69 return null;
70 }
71
72 public double getCost() {
73 return 0;
74 }
75
76 public double getChiSquare() {
77 return 0;
78 }
79
80 public double getReducedChiSquare(int n) {
81 return 0;
82 }
83
84 public RealVector getResiduals() {
85 return null;
86 }
87
88 public RealVector getPoint() {
89 return null;
90 }
91 };
92 }
93
94 }