Mercurial > dive4elements > river
changeset 3009:4dda67a893da
FixA: Added the derivatives of all fitting functions.
flys-artifacts/trunk@4565 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 31 May 2012 16:32:03 +0000 (2012-05-31) |
parents | 9e0500d64524 |
children | 05a3fe8800b3 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java |
diffstat | 8 files changed, 180 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu May 31 16:32:03 2012 +0000 @@ -1,3 +1,17 @@ +2012-05-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java: + Added inner class Derivative representing the first derivative of the + function. Can be instantiated with a given set of parameters. + + * src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java: + Added the derivatives of all fitting functions. + 2012-05-30 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,25 @@ public class Exp extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = a^Q*log(a)*m") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double m = parameters[0]; + final double a = parameters[1]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return Math.pow(a, Q)*Math.log(a)*m; + } + }; + } + }; + public Exp() { super( "exp", @@ -23,5 +42,10 @@ 1d }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java Thu May 31 16:32:03 2012 +0000 @@ -14,6 +14,26 @@ protected String [] parameterNames; protected double [] initialGuess; + public static abstract class Derivative { + + protected String description; + + public Derivative() { + } + + public Derivative(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public abstract de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters); + + } // interface Derivative + public Function() { } @@ -72,5 +92,7 @@ } }; } + + public abstract Derivative getDerivative(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,24 @@ public class Linear extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = m") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double m = parameters[0]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return m; + } + }; + } + }; + public Linear() { super("linear", "W(Q) = m*Q + b", new String [] { "m", "b" }); } @@ -16,5 +34,10 @@ public double [] gradient(double x, double [] parameters) { return new double [] { x, 1d }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,25 @@ public class Log extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = m/(Q+b)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double m = parameters[0]; + final double b = parameters[1]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return m/(Q+b); + } + }; + } + }; + public Log() { super("log", "W(Q) = m*ln(Q + b)", new String [] { "m", "b" }); } @@ -19,5 +38,10 @@ parameters[0]/(x + parameters[0]) }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,26 @@ public class LogLinear extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = a*m/(m*Q + b)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double a = parameters[0]; + final double m = parameters[1]; + final double b = parameters[2]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return a*m/(m*Q + b); + } + }; + } + }; + public LogLinear() { super( "log-linear", @@ -24,5 +44,10 @@ parameters[0]/l }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,25 @@ public class Pow extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = a*c*Q^(c-1)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double a = parameters[0]; + final double c = parameters[1]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return a*c*Math.pow(Q, c-1); + } + }; + } + }; + public Pow() { super( "pow", @@ -26,5 +45,10 @@ 1d }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Wed May 30 17:59:19 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Thu May 31 16:32:03 2012 +0000 @@ -3,6 +3,25 @@ public class Quad extends Function { + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = 2*n*Q+m") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double n = parameters[0]; + final double m = parameters[1]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return 2*n*Q+m; + } + }; + } + }; + public Quad() { super( "quad", @@ -20,5 +39,10 @@ public double [] gradient(double x, double [] parameters) { return new double [] { x*x, x, 1d }; } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :