/** * Creates a copy of the given {@link FXYSum fxySum}. * * @param fxySum the {@link FXYSum} to copy * * @return a copy of the given {@link FXYSum} */ public static FXYSum createCopy(final FXYSum fxySum) { final double[] coefficients = new double[fxySum.getCoefficients().length]; System.arraycopy(fxySum.getCoefficients(), 0, coefficients, 0, coefficients.length); final FXYSum fxySumCopy = new FXYSum(fxySum.getFunctions(), fxySum.getOrder(), coefficients); return fxySumCopy; }
/** * Computes <i>z(x,y) = sum(c[i] * f[i](x,y), i = 0, n - 1)</i>. * * @param f the function vector * @param c the coeffcient vector * @param x the x value * @param y the y value * @return the z value */ public static double computeZ(final FXY[] f, double[] c, double x, double y) { return FXYSum.computeZ(f, c, x, y); }
/** * Returns this sum of function terms as human-readable C-code. * * @param fname the name of the function z(x,y) = sum(C[i]*F[i](x,y), i, n) * @param x the name of the x variable * @param y the name of the y variable * * @return the C-code */ public String createCFunctionCode(final String fname, final String x, final String y) { final StringBuffer sb = new StringBuffer(256 + getNumTerms() * 10); appendCFunctionCodeStart(fname, x, y, sb); appendCFunctionCodeBody(fname, x, y, sb); appendCFunctionCodeEnd(fname, x, y, sb); return sb.toString(); }
new FXYSum.Cubic(), new FXYSum.BiCubic(), new FXYSum(FXYSum.FXY_4TH, 4), new FXYSum(FXYSum.FXY_BI_4TH, 4 + 4) }; for (int i = 0; i < potentialPolynomials.length; i++) { FXYSum potentialPolynomial = potentialPolynomials[i]; final int order = potentialPolynomial.getOrder(); final int numPointsRequired; if (order >= 0) { numPointsRequired = (order + 2) * (order + 1) / 2; } else { numPointsRequired = 2 * potentialPolynomial.getNumTerms(); potentialPolynomial.approximate(data, indices); double rmse = potentialPolynomial.getRootMeanSquareError(); double maxError = potentialPolynomial.getMaxError(); if (rmse < rmseMin) { index = i;
public void testRawAgainstOptimized(FXYSum fxyRaw, FXYSum fxyOpt) { final int m = 100; double[][] data = new double[m][3]; double x, y, z; for (int i = 0; i < m; i++) { x = Math.PI * random(-0.5, +0.5); y = Math.PI * random(-0.5, +0.5); z = Math.sin((x * y) / 4.0 + (x + y) / 2.0); data[i][0] = x; data[i][1] = y; data[i][2] = z; } fxyRaw.approximate(data, null); fxyOpt.approximate(data, null); final boolean oldState = Debug.setEnabled(true); try { assertEquals(fxyRaw.getRootMeanSquareError(), fxyOpt.getRootMeanSquareError(), EPS); double zRaw, zOpt; for (int i = 0; i < 10; i++) { x = Math.PI * random(-0.5, +0.5); y = Math.PI * random(-0.5, +0.5); zRaw = fxyRaw.computeZ(x, y); zOpt = fxyOpt.computeZ(x, y); assertEquals(zRaw, zOpt, EPS); } } finally { Debug.setEnabled(oldState); } }
final double rmseX = fX.getRootMeanSquareError(); final double rmseY = fY.getRootMeanSquareError(); final double maxErrorX = fX.getMaxError(); final double maxErrorY = fY.getMaxError();
String.valueOf(fX.getRootMeanSquareError()), "pixels")); String.valueOf(fY.getRootMeanSquareError()), "pixels")); String.valueOf(fX.getMaxError()), "pixels")); String.valueOf(fY.getMaxError()), "pixels")); final String xCCode = fX.createCFunctionCode("compute_x", "lat", "lon"); if (xCCode != null) { sb.append("\n"); final String yCCode = fY.createCFunctionCode("compute_y", "lat", "lon"); if (yCCode != null) { sb.append("\n");
println(slmTags[0]); final int directOrder = fxyGeoCoding.getLatFunction().getOrder(); final int reverseOrder = fxyGeoCoding.getPixelXFunction().getOrder(); final double[] lambdaCoeffs = fxyGeoCoding.getLonFunction().getCoefficients(); final double[] phiCoeffs = fxyGeoCoding.getLatFunction().getCoefficients(); final double[] xCoeffs = fxyGeoCoding.getPixelXFunction().getCoefficients(); final double[] yCoeffs = fxyGeoCoding.getPixelYFunction().getCoefficients(); indent++; writeDirectLocationModel(indent, directOrder, lambdaCoeffs, phiCoeffs);
final double[] lambdaCoefficients = new double[]{6, 7, 8}; final double[] phiCoefficients = new double[]{9, 10, 11}; final FXYSum xFunction = new FXYSum(FXYSum.FXY_LINEAR, 1, xCoefficients); final FXYSum yFunction = new FXYSum(FXYSum.FXY_LINEAR, 1, yCoefficients); final FXYSum lambdaFunction = new FXYSum(FXYSum.FXY_LINEAR, 1, lambdaCoefficients); final FXYSum phiFunction = new FXYSum(FXYSum.FXY_LINEAR, 1, phiCoefficients); final float pixelOffsetX = 0; final float pixelOffsetY = 0; " </Geoposition_Insert>" + LS + " <Simplified_Location_Model>" + LS + " <Direct_Location_Model order=\"" + lambdaFunction.getOrder() + "\">" + LS + " <lc_List>" + LS + " <lc index=\"0\">" + lambdaCoefficients[0] + "</lc>" + LS + " </pc_List>" + LS + " </Direct_Location_Model>" + LS + " <Reverse_Location_Model order=\"" + xFunction.getOrder() + "\">" + LS + " <ic_List>" + LS + " <ic index=\"0\">" + xCoefficients[0] + "</ic>" + LS + " <ic index=\"1\">" + xCoefficients[1] + "</ic>" + LS +
public void testBiCubicOptimization() { FXYSum fxyRaw = new FXYSum(FXYSum.FXY_BI_CUBIC); FXYSum fxyOpt = new FXYSum.BiCubic(); testRawAgainstOptimized(fxyRaw, fxyOpt); }
protected void appendCFunctionCodeStart(final String fname, final String x, final String y, StringBuffer sb) { final double[] c = getCoefficients(); sb.append("double " + fname + "(double " + x + ", double " + y + ") {\n"); sb.append(" static double c[" + c.length + "] = {\n"); for (int i = 0; i < c.length; i++) { sb.append(" "); sb.append(c[i]); sb.append((i < c.length - 1) ? ",\n" : "};\n"); } }
final double[] yCoeffs = readCoefficients(jcElems); final FXYSum lambdaSum = FXYSum.createFXYSum(dlmOrder, lambdaCoeffs); final FXYSum phiSum = FXYSum.createFXYSum(dlmOrder, phiCoeffs); final FXYSum xSum = FXYSum.createFXYSum(rlmOrder, xCoeffs); final FXYSum ySum = FXYSum.createFXYSum(rlmOrder, yCoeffs);
" </Geoposition_Insert>" + LS + " <Simplified_Location_Model>" + LS + " <Direct_Location_Model order=\"" + fxyGeoCoding.getPixelXFunction().getOrder() + "\">" + LS + " <lc_List>" + LS + " <lc index=\"0\">" + _lonCoefficients[0] + "</lc>" + LS + " </pc_List>" + LS + " </Direct_Location_Model>" + LS + " <Reverse_Location_Model order=\"" + fxyGeoCoding.getLatFunction().getOrder() + "\">" + LS + " <ic_List>" + LS + " <ic index=\"0\">" + _xCoefficients[0] + "</ic>" + LS +
addRow("Center latitude", String.valueOf(approximation.getCenterLat()) + " degree"); addRow("Center longitude", String.valueOf(approximation.getCenterLon()) + " degree"); addRow("RMSE for X", String.valueOf(fX.getRootMeanSquareError()) + " pixels"); addRow("RMSE for Y", String.valueOf(fY.getRootMeanSquareError()) + " pixels"); addRow("Max. error for X", String.valueOf(fX.getMaxError()) + " pixels"); addRow("Max. error for Y", String.valueOf(fY.getMaxError()) + " pixels");
private void assertEqual(final FXYGeoCoding expectedGeoCoding, final FXYGeoCoding actualGeoCoding) { assertEquals(expectedGeoCoding.getDatum().getName(), actualGeoCoding.getDatum().getName()); assertEquals(expectedGeoCoding.getDatum().getEllipsoid().getName(), actualGeoCoding.getDatum().getEllipsoid().getName()); assertEquals(expectedGeoCoding.getDatum().getEllipsoid().getSemiMajor(), actualGeoCoding.getDatum().getEllipsoid().getSemiMajor(), 1.0e-6); assertEquals(expectedGeoCoding.getDatum().getEllipsoid().getSemiMinor(), actualGeoCoding.getDatum().getEllipsoid().getSemiMinor(), 1.0e-6); assertEquals(expectedGeoCoding.getLatFunction().getOrder(), actualGeoCoding.getLatFunction().getOrder()); assertTrue(ArrayUtils.equalArrays(expectedGeoCoding.getLatFunction().getCoefficients(), actualGeoCoding.getLatFunction().getCoefficients(), 1.0e-6)); assertEquals(expectedGeoCoding.getLonFunction().getOrder(), actualGeoCoding.getLonFunction().getOrder()); assertTrue(ArrayUtils.equalArrays(expectedGeoCoding.getLonFunction().getCoefficients(), actualGeoCoding.getLonFunction().getCoefficients(), 1.0e-6)); assertEquals(expectedGeoCoding.getPixelXFunction().getOrder(), actualGeoCoding.getPixelXFunction().getOrder()); assertTrue(ArrayUtils.equalArrays(expectedGeoCoding.getPixelXFunction().getCoefficients(), actualGeoCoding.getPixelXFunction().getCoefficients(), 1.0e-6)); assertEquals(expectedGeoCoding.getPixelYFunction().getOrder(), actualGeoCoding.getPixelYFunction().getOrder()); assertTrue(ArrayUtils.equalArrays(expectedGeoCoding.getPixelYFunction().getCoefficients(), actualGeoCoding.getPixelYFunction().getCoefficients(), 1.0e-6)); assertEquals(expectedGeoCoding.getPixelOffsetX(), actualGeoCoding.getPixelOffsetX(), 1.0e-6); assertEquals(expectedGeoCoding.getPixelOffsetY(), actualGeoCoding.getPixelOffsetY(), 1.0e-6); assertEquals(expectedGeoCoding.getPixelSizeX(), actualGeoCoding.getPixelSizeX(), 1.0e-6); assertEquals(expectedGeoCoding.getPixelSizeY(), actualGeoCoding.getPixelSizeY(), 1.0e-6); }
final double[] lonCoefficients1 = new double[]{6, 7, 8}; final double[] latCoefficients1 = new double[]{9, 10, 11}; final FXYSum xFunction1 = new FXYSum(FXYSum.FXY_LINEAR, 1, xCoefficients1); final FXYSum yFunction1 = new FXYSum(FXYSum.FXY_LINEAR, 1, yCoefficients1); final FXYSum lambdaFunction1 = new FXYSum(FXYSum.FXY_LINEAR, 1, lonCoefficients1); final FXYSum phiFunction1 = new FXYSum(FXYSum.FXY_LINEAR, 1, latCoefficients1); final double[] xCoefficients2 = new double[]{12, 13, 14}; final double[] yCoefficients2 = new double[]{15, 16, 17}; final double[] lonCoefficients2 = new double[]{18, 19, 20}; final double[] latCoefficients2 = new double[]{21, 22, 23}; final FXYSum xFunction2 = new FXYSum(FXYSum.FXY_LINEAR, 1, xCoefficients2); final FXYSum yFunction2 = new FXYSum(FXYSum.FXY_LINEAR, 1, yCoefficients2); final FXYSum lambdaFunction2 = new FXYSum(FXYSum.FXY_LINEAR, 1, lonCoefficients2); final FXYSum phiFunction2 = new FXYSum(FXYSum.FXY_LINEAR, 1, latCoefficients2); final float pixelOffsetX = 0; final float pixelOffsetY = 0; " </Geoposition_Insert>" + LS + " <Simplified_Location_Model>" + LS + " <Direct_Location_Model order=\"" + geoCoding1.getPixelXFunction().getOrder() + "\">" + LS + " <lc_List>" + LS + " <lc index=\"0\">" + lonCoefficients1[0] + "</lc>" + LS + " </pc_List>" + LS + " </Direct_Location_Model>" + LS + " <Reverse_Location_Model order=\"" + geoCoding1.getLatFunction().getOrder() + "\">" + LS + " <ic_List>" + LS + " <ic index=\"0\">" + xCoefficients1[0] + "</ic>" + LS +
public void testBiQuadricOptimization() { FXYSum fxyRaw = new FXYSum(FXYSum.FXY_BI_QUADRATIC); FXYSum fxyOpt = new FXYSum.BiQuadric(); testRawAgainstOptimized(fxyRaw, fxyOpt); }
assertTrue(_geoCoding.getLonFunction() != subsetGeoCoding.getLonFunction()); assertTrue(_geoCoding.getPixelXFunction().getCoefficients() != subsetGeoCoding.getPixelXFunction().getCoefficients()); assertTrue(_geoCoding.getPixelYFunction().getCoefficients() != subsetGeoCoding.getPixelYFunction().getCoefficients()); assertTrue(_geoCoding.getLatFunction().getCoefficients() != subsetGeoCoding.getLatFunction().getCoefficients()); assertTrue(_geoCoding.getLonFunction().getCoefficients() != subsetGeoCoding.getLonFunction().getCoefficients()); assertTrue(Arrays.equals(_geoCoding.getPixelXFunction().getCoefficients(), subsetGeoCoding.getPixelXFunction().getCoefficients())); assertTrue(Arrays.equals(_geoCoding.getPixelYFunction().getCoefficients(), subsetGeoCoding.getPixelYFunction().getCoefficients())); assertTrue(Arrays.equals(_geoCoding.getLatFunction().getCoefficients(), subsetGeoCoding.getLatFunction().getCoefficients())); assertTrue(Arrays.equals(_geoCoding.getLonFunction().getCoefficients(), subsetGeoCoding.getLonFunction().getCoefficients()));
public void testCreateFXYSum() { FXYSum fxySum; fxySum = FXYSum.createFXYSum(1, createArray(3)); assertTrue(fxySum instanceof FXYSum.Linear); fxySum = FXYSum.createFXYSum(2, createArray(4)); assertTrue(fxySum instanceof FXYSum.BiLinear); fxySum = FXYSum.createFXYSum(2, createArray(6)); assertTrue(fxySum instanceof FXYSum.Quadric); fxySum = FXYSum.createFXYSum(4, createArray(9)); assertTrue(fxySum instanceof FXYSum.BiQuadric); fxySum = FXYSum.createFXYSum(3, createArray(10)); assertTrue(fxySum instanceof FXYSum.Cubic); fxySum = FXYSum.createFXYSum(6, createArray(16)); assertTrue(fxySum instanceof FXYSum.BiCubic); // not able to create fxySum = FXYSum.createFXYSum(5, createArray(12)); assertTrue(fxySum == null); }
/** * Computes this sum of function terms <i>z(x,y) = sum(c[i] * f[i](x,y), i=0, n-1)</i>. * The method will return zero unless the {@link #approximate(double[][], int[])} is called in order to set * the coefficient vector <i>c</i>. * * @param x the x value * @param y the y value * * @return the z value * * @see #computeZ(FXY[], double[], double, double) */ public double computeZ(final double x, final double y) { return computeZ(_f, _c, x, y); }