Mercurial > dive4elements > river
changeset 3181:de67497de5a0
Completed inverse functions.
flys-artifacts/trunk@4796 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 26 Jun 2012 10:54:12 +0000 |
parents | 4d5b15049ac2 |
children | f1e09a003f78 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java |
diffstat | 6 files changed, 173 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jun 26 10:54:12 2012 +0000 @@ -7,6 +7,16 @@ 2012-06-26 Sascha L. Teichmann <sascha.teichmann@intevation.de> + * src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java: + Completed inverse stubs. + +2012-06-26 Sascha L. Teichmann <sascha.teichmann@intevation.de> + * src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.java: Register the singletons instead of new objects.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java Tue Jun 26 10:54:12 2012 +0000 @@ -3,28 +3,57 @@ public class InvLogLinear extends Function { + public static final Derivative DERIVATIVE = + new Derivative("Q'(W) = e^(W/a)/(a*m)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double _1a = 1d/parameters[0]; + final double _1am = 1d/(parameters[0] * parameters[1]); + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double W) { + return Math.exp(W*_1a)*_1am; + } + }; + } + }; public static final Function INSTANCE = new InvLogLinear(); public InvLogLinear() { - // TODO: Implement me! + super( + "inv-log-linear", + "Q(W)=(e^(W/a)-b)/m", + new String [] { "a", "m", "b" }); } @Override public double value(double W, double [] parameters) { - // TODO: Implement me! - return 0d; + double a = parameters[0]; + double m = parameters[1]; + double b = parameters[2]; + return (Math.exp(W/a) - b)/m; } @Override - public double [] gradient(double Q, double [] parameters) { - // TODO: Implement me! - return null; + public double [] gradient(double W, double [] parameters) { + double a = parameters[0]; + double m = parameters[1]; + double b = parameters[2]; + double eWa = Math.exp(W/a); + return new double [] { + -(W*eWa)/(a*a*m) + -(eWa-b)/(m*m), + -1/m + }; } @Override public Derivative getDerivative() { - // TODO: Implement me! - return null; + return DERIVATIVE; } @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java Tue Jun 26 10:54:12 2012 +0000 @@ -3,22 +3,59 @@ public class InvPow extends Function { + public static final Derivative DERIVATIVE = + new Derivative("Q'(W) = ((W-d)/a)^(1/c)/(c*(W-d))") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + double a = parameters[0]; + final double c = parameters[1]; + final double d = parameters[2]; + final double _1a = 1d/a; + final double _1c = 1d/c; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double W) { + double Wd = W-d; + return Math.pow(Wd*_1a, _1c)/(c*Wd); + } + }; + } + }; + public static final Function INSTANCE = new InvPow(); public InvPow() { - // TODO: Implement me! + super( + "pow", + "Q(W) = ((W-d)/a)^(1/c)", + new String [] { "a", "c", "d" }); } @Override public double value(double W, double [] parameters) { - // TODO: Implement me! - return 0d; + double a = parameters[0]; + double c = parameters[1]; + double d = parameters[2]; + return Math.pow((W-d)/a, 1d/c); } @Override - public double [] gradient(double Q, double [] parameters) { - // TODO: Implement me! - return null; + public double [] gradient(double W, double [] parameters) { + double a = parameters[0]; + double c = parameters[1]; + double d = parameters[2]; + double _1c = 1d/c; + double Wdac = Math.pow((W-d)/a, 1d/c); + double Wd = W-d; + return new double [] { + -Wdac/(a*c), + (Wdac*Math.log(Wd/a))/(c*c), + -Wdac/(c*Wd) + }; } @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java Tue Jun 26 10:54:12 2012 +0000 @@ -3,28 +3,62 @@ public class InvQuad extends Function { + public static final Derivative DERIVATIVE = + new Derivative("Q'(W) = 1/sqrt(4*n*(W-b)+m^2)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + double n = parameters[0]; + double m = parameters[1]; + final double b = parameters[2]; + final double n4 = 4d*n; + final double mm = m*m; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double W) { + return 1d/Math.sqrt(n4*(W-b)+mm); + } + }; + } + }; + public static final Function INSTANCE = new InvQuad(); public InvQuad() { - // TODO: Implement me! + super( + "inv-quad", + "(sqrt(4*n*W-4*b*n+m^2)-m)/(2*n)", + new String [] { "n", "m", "b" }); } @Override public double value(double W, double [] parameters) { - // TODO: Implement me! - return 0d; + double n = parameters[0]; + double m = parameters[1]; + double b = parameters[2]; + return (Math.sqrt(4d*n*(W - b) + m*m)-m)/(2d*n); } @Override - public double [] gradient(double Q, double [] parameters) { - // TODO: Implement me! - return null; + public double [] gradient(double W, double [] parameters) { + double n = parameters[0]; + double m = parameters[1]; + double b = parameters[2]; + double Wb = W-b; + double sn4Wb = Math.sqrt(4d*n*Wb + m*m); + return new double [] { + Wb/(n*sn4Wb)-(sn4Wb-m)/(2d*n*n), + (m/sn4Wb-1d)/(2d*n), + -1d/sn4Wb + }; } @Override public Derivative getDerivative() { - // TODO: Implement me! - return null; + return DERIVATIVE; } @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java Tue Jun 26 10:54:12 2012 +0000 @@ -3,28 +3,57 @@ public class InvSQPow extends Function { + public static final Derivative DERIVATIVE = + new Derivative("Q'(S) = (S/a)^(1/b)/(b*S)") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double _1a = 1d/parameters[0]; + final double b = parameters[1]; + final double _1b = 1d/b; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double S) { + return Math.pow(S*_1a, _1b)/(b*S); + } + }; + } + }; public static final Function INSTANCE = new InvSQPow(); public InvSQPow() { - // TODO: Implement me! + super( + "inv-sq-pow", + "Q(S) = Q=(S/a)^(1/b)", + new String [] { "a", "b" }); } @Override - public double value(double W, double [] parameters) { - // TODO: Implement me! - return 0d; + public double value(double S, double [] parameters) { + double a = parameters[0]; + double b = parameters[1]; + return Math.pow(S/a, 1d/b); } @Override - public double [] gradient(double Q, double [] parameters) { - // TODO: Implement me! - return null; + public double [] gradient(double S, double [] parameters) { + double a = parameters[0]; + double b = parameters[1]; + double Sa = S/a; + double _1b = 1d/b; + double eSa1b = Math.pow(Sa, _1b); + return new double [] { + -eSa1b/(a*b), + -(eSa1b*Math.log(Sa))/(b*b) + }; } @Override public Derivative getDerivative() { - // TODO: Implement me! - return null; + return DERIVATIVE; } @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Tue Jun 26 10:45:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Tue Jun 26 10:54:12 2012 +0000 @@ -10,13 +10,13 @@ public de.intevation.flys.artifacts.math.Function instantiate(double [] parameters) { - final double n = parameters[0]; - final double m = parameters[1]; + final double n2 = 2d*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; + return n2*Q+m; } }; }