List of usage examples for org.apache.commons.math3.analysis BivariateFunction value
double value(double x, double y);
From source file:es.uvigo.ei.sing.laimages.core.operations.Interpolator.java
private static double[][] calculateNewValues(double[][] data, int interpolationLevel) { final int initialRows = data.length; final int initialColumns = data[0].length; final BivariateGridInterpolator interpolator = new BilinearInterpolator(); final BivariateFunction function = interpolator.interpolate( IntStream.range(0, initialRows).asDoubleStream().toArray(), IntStream.range(0, initialColumns).asDoubleStream().toArray(), data); final int newNumRows = CALCULATE_SIZE.applyAsInt(initialRows, interpolationLevel); final int newNumColumns = CALCULATE_SIZE.applyAsInt(initialColumns, interpolationLevel); final double[][] newValues = new double[newNumRows][newNumColumns]; final double xFactor = ((double) initialRows - 1d) / ((double) newNumRows - 1d); final double yFactor = ((double) initialColumns - 1d) / ((double) newNumColumns - 1d); for (int i = 0; i < newValues.length; i++) { for (int j = 0; j < newValues[i].length; j++) { newValues[i][j] = function.value((double) i * xFactor, (double) j * yFactor); }/*from w w w. j a v a 2 s .c om*/ } return newValues; }
From source file:org.meteoinfo.math.interpolate.InterpUtil.java
/** * Compute the value of the function/* ww w . ja v a 2 s . c o m*/ * @param func The function * @param x Input x data * @param y Input y data * @return Function value */ public static Array evaluate(BivariateFunction func, Array x, Array y) { Array r = Array.factory(DataType.DOUBLE, x.getShape()); for (int i = 0; i < r.getSize(); i++) r.setDouble(i, func.value(x.getDouble(i), y.getDouble(i))); return r; }
From source file:org.meteoinfo.math.interpolate.InterpUtil.java
/** * Compute the value of the function//from www . j a v a 2 s . c o m * @param func The function * @param x Input x data * @param y Input y data * @return Function value */ public static double evaluate(BivariateFunction func, Number x, Number y) { return func.value(x.doubleValue(), y.doubleValue()); }
From source file:uk.ac.diamond.scisoft.analysis.dataset.function.Interpolation2D.java
public static Dataset interpolate(IDataset oldx, IDataset oldy, IDataset oldxy, IDataset newx, IDataset newy, BivariateGridInterpolator interpolator) throws NonMonotonicSequenceException, NumberIsTooSmallException { //check shapes if (oldx.getRank() != 1) throw new IllegalArgumentException("oldx Shape must be 1D"); if (oldy.getRank() != 1) throw new IllegalArgumentException("oldy Shape must be 1D"); if (oldxy.getRank() != 2) throw new IllegalArgumentException("oldxy Shape must be 2D"); if (oldx.getShape()[0] != oldxy.getShape()[0]) throw new IllegalArgumentException("oldx Shape must match oldxy Shape[0]"); if (oldy.getShape()[0] != oldxy.getShape()[1]) throw new IllegalArgumentException("oldy Shape must match oldxy Shape[1]"); if (newx.getRank() != 1) throw new IllegalArgumentException("newx Shape must be 1D"); if (newy.getRank() != 1) throw new IllegalArgumentException("newx Shape must be 1D"); if (newy.getSize() != newx.getSize()) throw new IllegalArgumentException("newx and newy Size must be identical"); DoubleDataset oldx_dd = (DoubleDataset) DatasetUtils.cast(oldx, Dataset.FLOAT64); DoubleDataset oldy_dd = (DoubleDataset) DatasetUtils.cast(oldy, Dataset.FLOAT64); DoubleDataset oldxy_dd = (DoubleDataset) DatasetUtils.cast(oldxy, Dataset.FLOAT64); //unlike in Interpolation1D, we will not be sorting here, as it just too complicated //the user will be responsible for ensuring the arrays are properly sorted //oldxy_dd needs to be transformed into a double[][] array //this call may throw an exception that needs handling by the calling method BivariateFunction func = interpolator.interpolate(oldx_dd.getData(), oldy_dd.getData(), convertDoubleDataset2DtoPrimitive(oldxy_dd)); Dataset rv = DatasetFactory.zeros(new int[] { newx.getSize() }, Dataset.FLOAT64); rv.setName(oldxy.getName() + "_interpolated"); for (int i = 0; i < newx.getSize(); i++) { double val = 0.0; try {/*www. jav a2s . c om*/ val = func.value(newx.getDouble(i), newy.getDouble(i)); rv.set(val, i); } catch (OutOfRangeException e) { rv.set(0.0, i); } } return rv; }