# HG changeset patch # User Sascha L. Teichmann # Date 1340692417 0 # Node ID 585c0b49e696cd97531a89a6f1dd94082f6eb202 # Parent cbaa49896eca935435ee7f4bdd060a1ecc7c49af Added inverses of the fitting functions. flys-artifacts/trunk@4792 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jun 26 06:33:37 2012 +0000 @@ -1,3 +1,31 @@ +2012-06-26 Sascha L. Teichmann + + Implemenation of the inverses of the fitting functions. Needed + for the AT export of the calculated curves. + + * src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java: + Added abstract method getInverse() to get the inverse of the + function. + + * src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java: + Implements the getInverse() method. + + * src/main/java/de/intevation/flys/artifacts/math/fitting/InvLog.java, + 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/InvExp.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java, + src/main/java/de/intevation/flys/artifacts/math/fitting/InvLinear.java: + Implements the inverses of the function above. Some are still + stubs. + 2012-06-25 Felix Wolfsteller Fix issue663 ("step" curves for Q). diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java Tue Jun 26 06:33:37 2012 +0000 @@ -10,18 +10,21 @@ public de.intevation.flys.artifacts.math.Function instantiate(double [] parameters) { - final double m = parameters[0]; - final double a = parameters[1]; + double m = parameters[0]; + final double a = parameters[1]; + final double logam = Math.log(a)*m; return new de.intevation.flys.artifacts.math.Function() { @Override public double value(double Q) { - return Math.pow(a, Q)*Math.log(a)*m; + return Math.pow(a, Q)*logam; } }; } }; + public static final Function INSTANCE = new Exp(); + public Exp() { super( "exp", @@ -47,5 +50,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvExp.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Function.java Tue Jun 26 06:33:37 2012 +0000 @@ -94,5 +94,7 @@ } public abstract Derivative getDerivative(); + + public abstract Function getInverse(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvExp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvExp.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,66 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvExp +extends Function +{ + public static final Derivative DERIVATIVE = + new Derivative("W'(Q) = 1/(log(a)*(Q-b))") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double a = parameters[1]; + final double b = parameters[2]; + final double loga = Math.log(a); + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return 1d/(loga*(Q-a)); + } + }; + } + }; + + public static final Function INSTANCE = new InvExp(); + + public InvExp() { + super( + "inv-exp", + "Q(W) = log((W-b)/m)/log(a)", + new String [] { "m", "a", "b" }); + } + + @Override + public double value(double W, double [] parameters) { + double m = parameters[0]; + double a = parameters[1]; + double b = parameters[2]; + return Math.log((W-b)/m)/Math.log(a); + } + + @Override + public double [] gradient(double Q, double [] parameters) { + double m = parameters[0]; + double a = parameters[1]; + double b = parameters[2]; + double loga = Math.log(a); + return new double [] { + -1d/(loga*m), + -Math.log((Q-b)/m)/(a*loga*loga), + -1d/(loga*(Q-b)) + }; + } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } + + @Override + public Function getInverse() { + return Exp.INSTANCE; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLinear.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLinear.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,57 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvLinear +extends Function +{ + public static Function INSTANCE = new InvLinear(); + + public static final Derivative DERIVATIVE = + new Derivative("Q'(W) = 1/m") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double _1m = 1d/parameters[0]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double Q) { + return _1m; + } + }; + } + }; + + public InvLinear() { + super("inv-linear", "W(Q) = (Q-b)/m", new String [] { "m", "b" }); + } + + @Override + public double value(double Q, double [] parameters) { + double m = parameters[0]; + double b = parameters[1]; + return (Q-b)/m; + } + + @Override + public double [] gradient(double Q, double [] parameters) { + double m = parameters[0]; + double b = parameters[1]; + return new double [] { + -(Q-b)/(m*m), + -1d/m + }; + } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } + + @Override + public Function getInverse() { + return Linear.INSTANCE; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLog.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,56 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvLog +extends Function +{ + public static final Derivative DERIVATIVE = + new Derivative("Q'(W) = exp(W/m)/m") { + + @Override + public de.intevation.flys.artifacts.math.Function + instantiate(double [] parameters) + { + final double _1m = 1d / parameters[0]; + + return new de.intevation.flys.artifacts.math.Function() { + @Override + public double value(double W) { + return Math.exp(W*_1m)*_1m; + } + }; + } + }; + + public static final Function INSTANCE = new InvLog(); + + public InvLog() { + super("inv-log", "Q(W) = e^(W/m) - b", new String [] { "m", "b" }); + } + + @Override + public double value(double w, double [] parameters) { + double m = parameters[0]; + double b = parameters[1]; + return Math.exp(w/m) - b; + } + + @Override + public double [] gradient(double w, double [] parameters) { + double m = parameters[0]; + double b = parameters[1]; + double ewm = Math.exp(w/m); + return new double [] { -w*ewm/(m*m), -1 }; + } + + @Override + public Derivative getDerivative() { + return DERIVATIVE; + } + + @Override + public Function getInverse() { + return Log.INSTANCE; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : + diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLogLinear.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,36 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvLogLinear +extends Function +{ + public static final Function INSTANCE = new InvLogLinear(); + + public InvLogLinear() { + // TODO: Implement me! + } + + @Override + public double value(double W, double [] parameters) { + // TODO: Implement me! + return 0d; + } + + @Override + public double [] gradient(double Q, double [] parameters) { + // TODO: Implement me! + return null; + } + + @Override + public Derivative getDerivative() { + // TODO: Implement me! + return null; + } + + @Override + public Function getInverse() { + // TODO: Implement me! + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvPow.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,36 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvPow +extends Function +{ + public static final Function INSTANCE = new InvPow(); + + public InvPow() { + // TODO: Implement me! + } + + @Override + public double value(double W, double [] parameters) { + // TODO: Implement me! + return 0d; + } + + @Override + public double [] gradient(double Q, double [] parameters) { + // TODO: Implement me! + return null; + } + + @Override + public Derivative getDerivative() { + // TODO: Implement me! + return null; + } + + @Override + public Function getInverse() { + // TODO: Implement me! + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,36 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvQuad +extends Function +{ + public static final Function INSTANCE = new InvQuad(); + + public InvQuad() { + // TODO: Implement me! + } + + @Override + public double value(double W, double [] parameters) { + // TODO: Implement me! + return 0d; + } + + @Override + public double [] gradient(double Q, double [] parameters) { + // TODO: Implement me! + return null; + } + + @Override + public Derivative getDerivative() { + // TODO: Implement me! + return null; + } + + @Override + public Function getInverse() { + // TODO: Implement me! + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvSQPow.java Tue Jun 26 06:33:37 2012 +0000 @@ -0,0 +1,36 @@ +package de.intevation.flys.artifacts.math.fitting; + +public class InvSQPow +extends Function +{ + public static final Function INSTANCE = new InvSQPow(); + + public InvSQPow() { + // TODO: Implement me! + } + + @Override + public double value(double W, double [] parameters) { + // TODO: Implement me! + return 0d; + } + + @Override + public double [] gradient(double Q, double [] parameters) { + // TODO: Implement me! + return null; + } + + @Override + public Derivative getDerivative() { + // TODO: Implement me! + return null; + } + + @Override + public Function getInverse() { + // TODO: Implement me! + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Linear.java Tue Jun 26 06:33:37 2012 +0000 @@ -21,6 +21,8 @@ } }; + public static final Function INSTANCE = new Linear(); + public Linear() { super("linear", "W(Q) = m*Q + b", new String [] { "m", "b" }); } @@ -39,5 +41,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvLinear.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Log.java Tue Jun 26 06:33:37 2012 +0000 @@ -22,6 +22,8 @@ } }; + public static final Function INSTANCE = new Log(); + public Log() { super("log", "W(Q) = m*ln(Q + b)", new String [] { "m", "b" }); } @@ -46,5 +48,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvLog.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/LogLinear.java Tue Jun 26 06:33:37 2012 +0000 @@ -54,5 +54,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvLogLinear.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Pow.java Tue Jun 26 06:33:37 2012 +0000 @@ -50,5 +50,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvPow.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/Quad.java Tue Jun 26 06:33:37 2012 +0000 @@ -44,5 +44,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvQuad.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r cbaa49896eca -r 585c0b49e696 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java Mon Jun 25 19:13:16 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java Tue Jun 26 06:33:37 2012 +0000 @@ -49,5 +49,10 @@ public Derivative getDerivative() { return DERIVATIVE; } + + @Override + public Function getInverse() { + return InvSQPow.INSTANCE; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :