comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/fitting/ChiSquare.java @ 9646:0380717105ba

Implemented alternative fitting strategy for Log-Linear function.
author Gernot Belger <g.belger@bjoernsen.de>
date Mon, 02 Dec 2019 17:56:15 +0100
parents
children
comparison
equal deleted inserted replaced
9645:eb1a29fe823f 9646:0380717105ba
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.artifacts.model.fixings.fitting;
11
12 import java.util.Arrays;
13
14 import org.apache.commons.math3.exception.MathIllegalArgumentException;
15 import org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic;
16 import org.apache.commons.math3.stat.descriptive.UnivariateStatistic;
17
18 /**
19 * @author Gernot Belger
20 */
21 final class ChiSquare extends AbstractUnivariateStatistic {
22
23 private final double[] observation;
24
25 public ChiSquare(final double[] observation) {
26 this.observation = observation;
27 }
28
29 @Override
30 public UnivariateStatistic copy() {
31 /* stateless, hence we can return this */
32 return this;
33 }
34
35 @Override
36 public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException {
37 test(values, begin, length, true);
38
39 final double[] residualsWeights = new double[length];
40 Arrays.fill(residualsWeights, 0, length - 1, 1.0);
41
42 double cost = 0;
43
44 for (int i = begin; i < begin + length; i++) {
45 final double residual = values[i + begin] - this.observation[i + begin];
46 // final double wresiduals = residual * FastMath.sqrt(residualsWeights[i]);
47 cost += residualsWeights[i] * residual * residual;
48 }
49
50 return cost;
51 }
52 }

http://dive4elements.wald.intevation.org