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