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.jupiter.api.Test;
24
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28
29 class EvaluationRmsCheckerTest {
30
31
32 @Test
33 void testConverged() {
34
35 ConvergenceChecker<Evaluation> checker = new EvaluationRmsChecker(0.1, 1);
36 Evaluation e200 = mockEvaluation(200);
37 Evaluation e1 = mockEvaluation(1);
38
39
40
41 assertTrue(checker.converged(0, e200, mockEvaluation(210)));
42
43 assertTrue(checker.converged(0, e1, mockEvaluation(1.9)));
44
45 assertTrue(checker.converged(0, e1, mockEvaluation(1.01)));
46
47 assertFalse(checker.converged(0, e200, mockEvaluation(300)));
48 }
49
50
51
52
53
54
55
56 private static Evaluation mockEvaluation(final double rms) {
57 return new Evaluation() {
58 public RealMatrix getCovariances(double threshold) {
59 return null;
60 }
61
62 public RealVector getSigma(double covarianceSingularityThreshold) {
63 return null;
64 }
65
66 public double getRMS() {
67 return rms;
68 }
69
70 public RealMatrix getJacobian() {
71 return null;
72 }
73
74 public double getCost() {
75 return 0;
76 }
77
78 public double getChiSquare() {
79 return 0;
80 }
81
82 public double getReducedChiSquare(int n) {
83 return 0;
84 }
85
86 public RealVector getResiduals() {
87 return null;
88 }
89
90 public RealVector getPoint() {
91 return null;
92 }
93 };
94 }
95
96 }