Mercurial > dive4elements > river
changeset 3061:49baebb39305
FixA: Add interpolation of parameters that better suits the instantiation real functions.
flys-artifacts/trunk@4641 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 Jun 2012 08:11:36 +0000 |
parents | 94d78e0dc5e9 |
children | 7660cfe5e8f6 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java |
diffstat | 2 files changed, 76 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Jun 11 14:55:03 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jun 12 08:11:36 2012 +0000 @@ -1,3 +1,20 @@ +2012-06-11 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/Parameters.java: + Added method double [] interpolate(keyName, key, columnNames). + This construct is better suited for the extraction of + coefficients for building functions. In pseudo code: + + fitting.Function function = + FunctionFactory.getInstance().getFunction("log"); + + double km = 42.35; + + double [] coeffs = parameters.interpolate( + "km", km, function.getParamterNames()); + + math.Function f = function.instantiate(coeffs); + 2012-06-11 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon Jun 11 14:55:03 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Tue Jun 12 08:11:36 2012 +0000 @@ -177,8 +177,11 @@ return interpolate(columnIndex(columnName), key, values); } - public double [] interpolate(int columnIndex, double key, double [] values) { - + public double [] interpolate( + int columnIndex, + double key, + double [] values + ) { int row = binarySearch(columnIndex, key, EPSILON); if (row >= 0) { @@ -204,6 +207,60 @@ return values; } + + public double [] interpolate( + String keyName, + double key, + String [] columnNames + ) { + int keyIndex = columnIndex(keyName); + return keyIndex < 0 + ? null + : interpolate(keyIndex, key, columnNames); + } + + public double [] interpolate( + int keyIndex, + double key, + String [] columnNames + ) { + int row = binarySearch(keyIndex, key, EPSILON); + + if (row >= 0) { // direct match + double [] values = new double[columnNames.length]; + for (int i = 0; i < values.length; ++i) { + int ci = columnIndex(columnNames[i]); + values[i] = ci < 0 + ? Double.NaN + : columns[ci].getQuick(row); + } + return values; + } + + row = -row - 1; + if (row < 1 || row >= size()) { // out of bounds + return null; + } + + double v1 = columns[keyIndex].getQuick(row-1); + double v2 = columns[keyIndex].getQuick(row); + double factor = Linear.factor(key, v1, v2); + + double [] values = new double[columnNames.length]; + + for (int i = 0; i < values.length; ++i) { + int ci = columnIndex(columnNames[i]); + values[i] = ci < 0 + ? Double.NaN + : Linear.weight( + factor, + columns[ci].getQuick(row-1), + columns[ci].getQuick(row)); + } + + return values; + } + public boolean isSorted(String columnName) { return isSorted(columnIndex(columnName)); }