IntegerBootstrapping.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.estimation.measurements.gnss;

  18. import org.hipparchus.linear.MatrixUtils;
  19. import org.hipparchus.linear.QRDecomposer;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.hipparchus.special.Erf;
  22. import org.hipparchus.util.FastMath;;

  23. /** Bootstrapping engine for ILS problem solving.
  24.  * This method is base on the following paper: <a
  25.  * href="https://www.researchgate.net/publication/225773077_Success_probability_of_integer_GPS_ambiguity_rounding_and_bootstrapping">
  26.  * Success probability of integer GPs ambiguity rounding and bootstrapping</a> by P. J. G. Teunissen 1998 and
  27.  * <a
  28.  * href="https://repository.tudelft.nl/islandora/object/uuid%3A1a5b8a6e-c9d6-45e3-8e75-48db6d27a523">
  29.  * Influence of ambiguity precision on the success rate of GNSS integer ambiguity bootstrapping</a> by
  30.  * P. J. G. Teunissen 2006.
  31.  * <p>
  32.  *  This method is really faster for integer ambiguity resolution than LAMBDA or MLAMBDA method but its success rate
  33.  *  is really smaller. The method  extends LambdaMethod as it uses LDL' factorization  and reduction methods from LAMBDA method.
  34.  *  The method is really different from LAMBDA as the solution found is not a least-square solution. It is a solution which asses
  35.  *  a probability of success of the solution found. The probability increase with the does with LDL' factorization and reduction
  36.  *  methods.
  37.  *  </p> <p>
  38.  *  If one want to use this method for integer ambiguity resolution, one just need to construct IntegerBootstrapping
  39.  *  only with a double which is the minimal probability of success one wants.
  40.  *  Then from it, one can call the solveILS method.
  41.  *  @author David Soulard
  42.  *  @since 10.2
  43.  */

  44. public class IntegerBootstrapping extends LambdaMethod {

  45.     /** Minimum probability for acceptance. */
  46.     private double minProb;

  47.     /** Upperbound of the probability. */
  48.     private boolean boostrapUse;

  49.     /** Integer ambiguity solution from bootstrap method. */
  50.     private long[]  a_B;

  51.     /** Probability of success of the solution found.*/
  52.     private double p_aB;

  53.     /** Constructor for the bootstrapping ambiguity estimator.
  54.      * @param prob minimum probability acceptance  for the bootstrap
  55.      */
  56.     public IntegerBootstrapping(final double prob) {
  57.         this.minProb = prob;
  58.     }

  59.     /**
  60.      * Compute the solution by the bootstrap method from equation (13) in
  61.      * P.J.G. Teunissen November 2006. The solution is a solution in the
  62.      * distorted space from LdL' and Z transformation.
  63.      */
  64.     @Override
  65.     protected void discreteSearch() {
  66.         //If the probability success upper bound is greater than the min probability, bootstrapUse = true, false otherwise
  67.         this.boostrapUse = upperBoundProbabilitySuccess() > this.minProb;
  68.         //Getter of the diagonal part and lower part of the covariance matrix
  69.         final double[] diag = getDiagReference();
  70.         final double[] low  = getLowReference();
  71.         final int n = diag.length;
  72.         if (boostrapUse) {
  73.             final RealMatrix I = MatrixUtils.createRealIdentityMatrix(n);
  74.             a_B = new long[n];
  75.             final RealMatrix L = getSymmetricMatrixFromLowPart(low);
  76.             final RealMatrix invL_I  = new QRDecomposer(1.0e-10).
  77.                                 decompose(L).getInverse().subtract(I);
  78.             final double[] decorrelated = getDecorrelatedReference();
  79.             a_B[0] = (long) FastMath.rint(decorrelated[0]);
  80.             for (int i = 1; i < a_B.length; i++) {
  81.                 double a_b = 0;
  82.                 for (int j = 0; j < i; j++) {
  83.                     a_b += invL_I.getEntry(i, j) * a_B[j];
  84.                 }
  85.                 a_B[i] = (long) FastMath.rint(decorrelated[i] + a_b);
  86.             }
  87.             // Compute the probability of correct integer estimation
  88.             p_aB = bootstrappedSuccessRate(diag, a_B);
  89.             if (p_aB > minProb) {
  90.                 this.boostrapUse = true;
  91.             } else {
  92.                 this.boostrapUse = false;
  93.             }
  94.         }
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     protected IntegerLeastSquareSolution[] recoverAmbiguities() {
  99.         if (boostrapUse) {
  100.             // get references to the diagonal and lower triangular parts
  101.             final double[] diag = getDiagReference();
  102.             final int n = diag.length;
  103.             final int[] zInverseTransformation = getZInverseTransformationReference();
  104.             final long[] a = new long[n];
  105.             for (int i = 0; i < n; ++i) {
  106.                 // compute a = Z⁻ᵀ.s
  107.                 long ai = 0;
  108.                 int l = zIndex(0, i);
  109.                 for (int j = 0; j < n; ++j) {
  110.                     ai += zInverseTransformation[l] * a_B[j];
  111.                     l  += n;
  112.                 }
  113.                 a[i] = ai;
  114.             }
  115.             a_B = a;
  116.             final IntegerLeastSquareSolution sol = new IntegerLeastSquareSolution(a_B, p_aB);
  117.             return new IntegerLeastSquareSolution[] {sol};
  118.         }
  119.         else {
  120.             // Return an empty array
  121.             return new IntegerLeastSquareSolution[0];
  122.         }
  123.     }

  124.     /** Return the matrix symmetric from its low triangular part (1 on the diagonal).

  125.      * @param l lower triangular part of the matrix
  126.      * @return matrix
  127.      */
  128.     private RealMatrix getSymmetricMatrixFromLowPart(final double[] l) {
  129.         final double[] diag = getDiagReference();
  130.         final int n = diag.length;
  131.         final RealMatrix L = MatrixUtils.createRealMatrix(n, n);
  132.         for (int i = 0; i < n; i++) {
  133.             for (int j = 0; j < i; j++) {
  134.                 L.setEntry(i, j, l[lIndex(i, j)]);
  135.             }
  136.             L.setEntry(i, i, 1.0);
  137.         }
  138.         return L;
  139.     }

  140.     /**Compute the success rate of a bootstraped ILS problem solution.
  141.      * @param D diagonal of the covaraicne matrix
  142.      * @param aB bootstrapped solution
  143.      * @return probability of success
  144.      */
  145.     private double bootstrappedSuccessRate(final double[] D, final long[] aB) {
  146.         double p = 2.0 * phi(1 / (2.0 * D[0]) - 1.0);
  147.         for (int i = 1; i < D.length; i++) {
  148.             p = p * (2.0 * phi(1.0 / (2.0 * D[i])) - 1.0);
  149.         }
  150.         return p;
  151.     }

  152.     /** Compute at point x the the value of phi function.
  153.      * Where phi = 1/2 *(1 + Erf(x/sqrt(2))
  154.      * @param x value at which we compute phi function
  155.      * @return value of phi(x)
  156.      */
  157.     private double phi(final double x) {
  158.         return 0.5 * (1.0 + Erf.erf(x / FastMath.sqrt(2.0)));
  159.     }

  160.     /** Compute the upper bound probability of the ILS problem.
  161.      * @return upper bound probability of the ILS problem
  162.      */
  163.     private double upperBoundProbabilitySuccess() {
  164.         //covariance matrix determinant
  165.         double det = 1;
  166.         final double[] diag = getDiagReference();
  167.         final int n         = diag.length;
  168.         for (double d: diag) {
  169.             det *= d;
  170.         }
  171.         //ADOP: Ambiguity Dilution of Precision
  172.         final double adop = FastMath.pow(det, 1.0 / ((double) 2.0 * n));
  173.         return FastMath.pow(2.0 * phi(1.0 / (2.0 * adop)) - 1.0, n);
  174.     }
  175. }