Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 9363:0274c7444b2d
Fixed: missing commit
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
Removed old outliers theme.
Also consider showpoints property.
Also consider pointsize property.
author | gernotbelger |
---|---|
date | Thu, 02 Aug 2018 09:59:48 +0200 |
parents | 202fd59b4f21 |
children | 9744ce3c3853 |
comparison
equal
deleted
inserted
replaced
9362:392745cccede | 9363:0274c7444b2d |
---|---|
40 | 40 |
41 public static final String[] STANDARD_COLUMNS = { "km", "chi_sqr", "max_q", "std-dev" }; | 41 public static final String[] STANDARD_COLUMNS = { "km", "chi_sqr", "max_q", "std-dev" }; |
42 | 42 |
43 protected static class FitResult { | 43 protected static class FitResult { |
44 | 44 |
45 protected Parameters parameters; | 45 private final Parameters parameters; |
46 protected KMIndex<QWD[]> referenced; | 46 private final KMIndex<QWD[]> fixings; |
47 protected KMIndex<QWD[]> outliers; | 47 |
48 | 48 public FitResult(final Parameters parameters, final KMIndex<QWD[]> fixings) { |
49 public FitResult() { | |
50 } | |
51 | |
52 public FitResult(final Parameters parameters, final KMIndex<QWD[]> referenced, final KMIndex<QWD[]> outliers) { | |
53 this.parameters = parameters; | 49 this.parameters = parameters; |
54 this.referenced = referenced; | 50 this.fixings = fixings; |
55 this.outliers = outliers; | |
56 } | 51 } |
57 | 52 |
58 public Parameters getParameters() { | 53 public Parameters getParameters() { |
59 return this.parameters; | 54 return this.parameters; |
60 } | 55 } |
61 | 56 |
62 public KMIndex<QWD[]> getReferenced() { | 57 public KMIndex<QWD[]> getFixings() { |
63 return this.referenced; | 58 return this.fixings; |
64 } | 59 } |
65 | 60 } |
66 public KMIndex<QWD[]> getOutliers() { | |
67 return this.outliers; | |
68 } | |
69 } // class FitResult | |
70 | 61 |
71 /** | 62 /** |
72 * Helper class to bundle the meta information of a column | 63 * Helper class to bundle the meta information of a column |
73 * and the real data. | 64 * and the real data. |
74 */ | 65 */ |
268 final double[] ws = new double[qs.length]; | 259 final double[] ws = new double[qs.length]; |
269 final boolean[] interpolated = new boolean[ws.length]; | 260 final boolean[] interpolated = new boolean[ws.length]; |
270 | 261 |
271 final Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() { | 262 final Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() { |
272 @Override | 263 @Override |
273 public QWD create(final double q, final double w, boolean isOutlier) { | 264 public QWD create(final double q, final double w, double deltaW, boolean isOutlier) { |
274 // Check all the event columns for close match | 265 // Check all the event columns for close match |
275 // and take the description and the date from meta. | 266 // and take the description and the date from meta. |
276 for (int i = 0; i < qs.length; ++i) { | 267 for (int i = 0; i < qs.length; ++i) { |
277 if (Math.abs(qs[i] - q) < EPSILON && Math.abs(ws[i] - w) < EPSILON) { | 268 if (Math.abs(qs[i] - q) < EPSILON && Math.abs(ws[i] - w) < EPSILON) { |
278 final Column column = eventColumns.get(i); | 269 final Column column = eventColumns.get(i); |
279 return new QWD(qs[i], ws[i], column.getDescription(), column.getDate(), interpolated[i], 0d, column.getId(), isOutlier); // Use database id here | 270 return new QWD(qs[i], ws[i], column.getDescription(), column.getDate(), interpolated[i], deltaW, column.getId(), isOutlier); // Use database id here |
280 } | 271 } |
281 } | 272 } |
282 log.warn("cannot find column for (" + q + ", " + w + ")"); | 273 log.warn("cannot find column for (" + q + ", " + w + ")"); |
283 return new QWD(q, w, isOutlier); | 274 return new QWD(q, w, isOutlier); |
284 } | 275 } |
285 }; | 276 }; |
286 | 277 |
287 final Fitting fitting = new Fitting(func, qwdFactory, this.preprocessing); | |
288 | |
289 final String[] parameterNames = func.getParameterNames(); | 278 final String[] parameterNames = func.getParameterNames(); |
290 | 279 |
291 final Parameters results = new Parameters(StringUtils.join(STANDARD_COLUMNS, parameterNames)); | 280 final Parameters results = new Parameters(StringUtils.join(STANDARD_COLUMNS, parameterNames)); |
292 | 281 |
293 boolean invalid = false; | 282 boolean invalid = false; |
296 | 285 |
297 if (debug) { | 286 if (debug) { |
298 log.debug("number of kms: " + kms.length); | 287 log.debug("number of kms: " + kms.length); |
299 } | 288 } |
300 | 289 |
301 final KMIndex<QWD[]> outliers = new KMIndex<>(); | 290 final KMIndex<QWD[]> fixings = new KMIndex<>(); |
302 final KMIndex<QWD[]> referenced = new KMIndex<>(kms.length); | |
303 | 291 |
304 final int kmIndex = results.columnIndex("km"); | 292 final int kmIndex = results.columnIndex("km"); |
305 final int chiSqrIndex = results.columnIndex("chi_sqr"); | 293 final int chiSqrIndex = results.columnIndex("chi_sqr"); |
306 final int maxQIndex = results.columnIndex("max_q"); | 294 final int maxQIndex = results.columnIndex("max_q"); |
307 final int stdDevIndex = results.columnIndex("std-dev"); | 295 final int stdDevIndex = results.columnIndex("std-dev"); |
308 final int[] parameterIndices = results.columnIndices(parameterNames); | 296 final int[] parameterIndices = results.columnIndices(parameterNames); |
309 | 297 |
310 int numFailed = 0; | 298 int numFailed = 0; |
311 | 299 |
312 for (final double km2 : kms) { | 300 for (final double km : kms) { |
313 final double km = km2; | |
314 | 301 |
315 // Fill Qs and Ws from event columns. | 302 // Fill Qs and Ws from event columns. |
316 for (int j = 0; j < ws.length; ++j) { | 303 for (int j = 0; j < ws.length; ++j) |
317 interpolated[j] = !eventColumns.get(j).getQW(km, qs, ws, j); | 304 interpolated[j] = !eventColumns.get(j).getQW(km, qs, ws, j); |
318 } | 305 |
319 | 306 final Fitting fitting = Fitting.fit(func, qwdFactory, this.preprocessing, qs, ws); |
320 fitting.reset(); | 307 if (fitting == null) { |
321 | |
322 if (!fitting.fit(qs, ws)) { | |
323 log.debug("Fitting for km: " + km + " failed"); | 308 log.debug("Fitting for km: " + km + " failed"); |
324 ++numFailed; | 309 ++numFailed; |
325 addProblem(km, "fix.fitting.failed"); | 310 addProblem(km, "fix.fitting.failed"); |
326 continue; | 311 continue; |
327 } | 312 } |
328 | 313 |
329 final QWD[] refs = fitting.referencedToArray(); | 314 final QWD[] fixingsArray = fitting.getFixingsArray(); |
330 | 315 fixings.add(km, fixingsArray); |
331 referenced.add(km, refs); | |
332 | |
333 if (fitting.hasOutliers()) { | |
334 outliers.add(km, fitting.outliersToArray()); | |
335 } | |
336 | 316 |
337 final int row = results.newRow(); | 317 final int row = results.newRow(); |
338 final double[] values = fitting.getParameters(); | 318 final double[] values = fitting.getParameters(); |
339 | 319 |
340 results.set(row, kmIndex, km); | 320 results.set(row, kmIndex, km); |
356 if (invalid) { | 336 if (invalid) { |
357 addProblem("fix.invalid.values"); | 337 addProblem("fix.invalid.values"); |
358 results.removeNaNs(); | 338 results.removeNaNs(); |
359 } | 339 } |
360 | 340 |
361 outliers.sort(); | 341 fixings.sort(); |
362 referenced.sort(); | 342 |
363 | 343 return new FitResult(results, fixings); |
364 return new FitResult(results, referenced, outliers); | |
365 } | 344 } |
366 | 345 |
367 public CalculationResult calculate() { | 346 public CalculationResult calculate() { |
368 final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river); | 347 final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river); |
369 | 348 |
385 if (result != null) { | 364 if (result != null) { |
386 // Workaraound to deal with same dates in data set | 365 // Workaraound to deal with same dates in data set |
387 final Object o = result.getData(); | 366 final Object o = result.getData(); |
388 if (o instanceof FixResult) { | 367 if (o instanceof FixResult) { |
389 final FixResult fr = (FixResult) o; | 368 final FixResult fr = (FixResult) o; |
390 fr.makeReferenceEventsDatesUnique(); | 369 fr.makeEventsDatesUnique(); |
391 fr.remapReferenceIndicesToRank(); | 370 fr.remapEventIndicesToRank(); |
392 } | 371 } |
393 } | 372 } |
394 | 373 |
395 return result; | 374 return result; |
396 } | 375 } |
397 | 376 |
398 protected abstract CalculationResult innerCalculate(FixingsOverview overview, Function function); | 377 protected abstract CalculationResult innerCalculate(FixingsOverview overview, Function function); |
399 } | 378 } |
400 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |