Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvLog.java @ 3177:585c0b49e696
Added inverses of the fitting functions.
flys-artifacts/trunk@4792 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 26 Jun 2012 06:33:37 +0000 |
parents | |
children | 9422b559b2d5 |
line wrap: on
line diff
--- /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 : +