diff artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/AbstractLogLinear.java @ 9643:58f3fe98fd6b

Fitting new Option UI
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Mon, 02 Dec 2019 14:14:06 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/AbstractLogLinear.java	Mon Dec 02 14:14:06 2019 +0100
@@ -0,0 +1,72 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.math.fitting;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+/*
+ * Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+public abstract class AbstractLogLinear extends Function {
+    public static final Derivative DERIVATIVE = new Derivative("W'(Q) = a*m/(m*Q + b)") {
+
+        @Override
+        public org.dive4elements.river.artifacts.math.Function instantiate(final double[] parameters) {
+            final double a = parameters[0];
+            final double m = parameters[1];
+            final double b = parameters[2];
+
+            return new org.dive4elements.river.artifacts.math.Function() {
+                @Override
+                public double value(final double Q) {
+                    return a * m / (m * Q + b);
+                }
+            };
+        }
+    };
+
+    public AbstractLogLinear(final String name, final String description) {
+        super(name, description, new String[] { "a", "m", "b" });
+    }
+
+    @Override
+    public final double value(final double x, final double[] parameters) {
+        return parameters[0] * Math.log(parameters[1] * x + parameters[2]);
+    }
+
+    @Override
+    public double[] gradient(final double x, final double[] parameters) {
+        final double a = parameters[0];
+        final double m = parameters[1];
+        final double b = parameters[2];
+
+        final double lin = m * x + b;
+
+        return new double[] { Math.log(lin), a * x / lin, a / lin };
+    }
+
+    @Override
+    public final Derivative getDerivative() {
+        return DERIVATIVE;
+    }
+
+    @Override
+    public Function getInverse() {
+        return InvLogLinear.INSTANCE;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org