annotate artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/InvExp.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children af13ceeba52a
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3177
diff changeset
9 package org.dive4elements.river.artifacts.math.fitting;
3177
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 public class InvExp
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 extends Function
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 public static final Derivative DERIVATIVE =
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 new Derivative("W'(Q) = 1/(log(a)*(Q-b))") {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 @Override
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3177
diff changeset
18 public org.dive4elements.river.artifacts.math.Function
3177
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 instantiate(double [] parameters)
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 final double a = parameters[1];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 final double b = parameters[2];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 final double loga = Math.log(a);
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3177
diff changeset
25 return new org.dive4elements.river.artifacts.math.Function() {
3177
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 @Override
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public double value(double Q) {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 return 1d/(loga*(Q-a));
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 };
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 };
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public static final Function INSTANCE = new InvExp();
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public InvExp() {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 super(
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 "inv-exp",
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 "Q(W) = log((W-b)/m)/log(a)",
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 new String [] { "m", "a", "b" });
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 @Override
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public double value(double W, double [] parameters) {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 double m = parameters[0];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 double a = parameters[1];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 double b = parameters[2];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 return Math.log((W-b)/m)/Math.log(a);
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 @Override
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 public double [] gradient(double Q, double [] parameters) {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 double m = parameters[0];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 double a = parameters[1];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 double b = parameters[2];
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 double loga = Math.log(a);
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 return new double [] {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 -1d/(loga*m),
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 -Math.log((Q-b)/m)/(a*loga*loga),
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 -1d/(loga*(Q-b))
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 };
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 @Override
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public Derivative getDerivative() {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 return DERIVATIVE;
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 @Override
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 public Function getInverse() {
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 return Exp.INSTANCE;
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }
585c0b49e696 Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org