@Test public void testInterpolate() { System.out.println("interpolate"); double[][] x = {{0, 0}, {1, 1}}; double[] y = {0, 1}; ShepardInterpolation instance = new ShepardInterpolation(x, y); double[] x1 = {0.5, 0.5}; assertEquals(0, instance.interpolate(x[0]), 1E-7); assertEquals(1, instance.interpolate(x[1]), 1E-7); assertEquals(0.5, instance.interpolate(x1), 1E-7); }
public double interpolate(double... x) { if (x.length != this.x[0].length) { throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length)); } double weight = 0.0, sum = 0.0; for (int i = 0; i < this.x.length; i++) { double r = MathEx.squaredDistance(x, this.x[i]); if (r == 0.0) { return y[i]; } double w = Math.pow(r, p/2); weight += w; sum += w * y[i]; } return sum / weight; }
ShepardInterpolation { public double interpolate(double... x) { if (x.length != this.x[0].length) { throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length)); } double weight = 0.0, sum = 0.0; for (int i = 0; i < this.x.length; i++) { double r = MathEx.squaredDistance(x, this.x[i]); if (r == 0.0) { return y[i]; } double w = Math.pow(r, p/2); weight += w; sum += w * y[i]; } return sum / weight; } }
ShepardInterpolation { public double interpolate(double... x) { if (x.length != this.x[0].length) { throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length)); } double weight = 0.0, sum = 0.0; for (int i = 0; i < this.x.length; i++) { double r = MathEx.squaredDistance(x, this.x[i]); if (r == 0.0) { return y[i]; } double w = Math.pow(r, p/2); weight += w; sum += w * y[i]; } return sum / weight; } ShepardInterpolation(double[][] x, double[] y);  ShepardInterpolation(double[][] x, double[] y, double p); }
ShepardInterpolation { public double interpolate(double... x) { if (x.length != this.x[0].length) { throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length)); } double weight = 0.0, sum = 0.0; for (int i = 0; i < this.x.length; i++) { double r = MathEx.squaredDistance(x, this.x[i]); if (r == 0.0) { return y[i]; } double w = Math.pow(r, p/2); weight += w; sum += w * y[i]; } return sum / weight; } ShepardInterpolation(double[][] x, double[] y);  ShepardInterpolation(double[][] x, double[] y, double p); double interpolate(double... x); @Override String toString(); }
ShepardInterpolation { public double interpolate(double... x) { if (x.length != this.x[0].length) { throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length)); } double weight = 0.0, sum = 0.0; for (int i = 0; i < this.x.length; i++) { double r = MathEx.squaredDistance(x, this.x[i]); if (r == 0.0) { return y[i]; } double w = Math.pow(r, p/2); weight += w; sum += w * y[i]; } return sum / weight; } ShepardInterpolation(double[][] x, double[] y);  ShepardInterpolation(double[][] x, double[] y, double p); double interpolate(double... x); @Override String toString();  }