1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.optim.nonlinear.vector.leastsquares;
23
24 import org.hipparchus.analysis.MultivariateMatrixFunction;
25 import org.hipparchus.analysis.MultivariateVectorFunction;
26 import org.hipparchus.linear.ArrayRealVector;
27 import org.hipparchus.linear.RealMatrix;
28 import org.hipparchus.linear.RealVector;
29 import org.hipparchus.optim.ConvergenceChecker;
30 import org.hipparchus.optim.PointVectorValuePair;
31 import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem.Evaluation;
32
33
34
35
36
37
38 public class LeastSquaresBuilder {
39
40
41 private int maxEvaluations;
42
43 private int maxIterations;
44
45 private ConvergenceChecker<Evaluation> checker;
46
47 private MultivariateJacobianFunction model;
48
49 private RealVector target;
50
51 private RealVector start;
52
53 private RealMatrix weight;
54
55
56
57
58 private boolean lazyEvaluation;
59
60
61
62 private ParameterValidator paramValidator;
63
64
65
66
67
68
69
70
71 public LeastSquaresBuilder() {
72
73 }
74
75
76
77
78
79
80 public LeastSquaresProblem build() {
81 return LeastSquaresFactory.create(model,
82 target,
83 start,
84 weight,
85 checker,
86 maxEvaluations,
87 maxIterations,
88 lazyEvaluation,
89 paramValidator);
90 }
91
92
93
94
95
96
97
98 public LeastSquaresBuilder maxEvaluations(final int newMaxEvaluations) {
99 this.maxEvaluations = newMaxEvaluations;
100 return this;
101 }
102
103
104
105
106
107
108
109 public LeastSquaresBuilder maxIterations(final int newMaxIterations) {
110 this.maxIterations = newMaxIterations;
111 return this;
112 }
113
114
115
116
117
118
119
120 public LeastSquaresBuilder checker(final ConvergenceChecker<Evaluation> newChecker) {
121 this.checker = newChecker;
122 return this;
123 }
124
125
126
127
128
129
130
131
132
133
134 public LeastSquaresBuilder checkerPair(final ConvergenceChecker<PointVectorValuePair> newChecker) {
135 return this.checker(LeastSquaresFactory.evaluationChecker(newChecker));
136 }
137
138
139
140
141
142
143
144
145 public LeastSquaresBuilder model(final MultivariateVectorFunction value,
146 final MultivariateMatrixFunction jacobian) {
147 return model(LeastSquaresFactory.model(value, jacobian));
148 }
149
150
151
152
153
154
155
156 public LeastSquaresBuilder model(final MultivariateJacobianFunction newModel) {
157 this.model = newModel;
158 return this;
159 }
160
161
162
163
164
165
166
167 public LeastSquaresBuilder target(final RealVector newTarget) {
168 this.target = newTarget;
169 return this;
170 }
171
172
173
174
175
176
177
178 public LeastSquaresBuilder target(final double[] newTarget) {
179 return target(new ArrayRealVector(newTarget, false));
180 }
181
182
183
184
185
186
187
188 public LeastSquaresBuilder start(final RealVector newStart) {
189 this.start = newStart;
190 return this;
191 }
192
193
194
195
196
197
198
199 public LeastSquaresBuilder start(final double[] newStart) {
200 return start(new ArrayRealVector(newStart, false));
201 }
202
203
204
205
206
207
208
209 public LeastSquaresBuilder weight(final RealMatrix newWeight) {
210 this.weight = newWeight;
211 return this;
212 }
213
214
215
216
217
218
219
220
221 public LeastSquaresBuilder lazyEvaluation(final boolean newValue) {
222 lazyEvaluation = newValue;
223 return this;
224 }
225
226
227
228
229
230
231
232
233 public LeastSquaresBuilder parameterValidator(final ParameterValidator newValidator) {
234 paramValidator = newValidator;
235 return this;
236 }
237 }