OutlierFilter.java

  1. /* Copyright 2002-2023 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.modifiers;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.estimation.measurements.EstimatedMeasurement;
  22. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  23. import org.orekit.estimation.measurements.EstimationModifier;
  24. import org.orekit.estimation.measurements.ObservedMeasurement;
  25. import org.orekit.utils.ParameterDriver;

  26. /** Modifier that sets estimated measurement weight to 0 if residual is too far from expected domain.
  27.  * @param <T> the type of the measurement
  28.  * @author Luc Maisonobe
  29.  * @since 8.0
  30.  */
  31. public class OutlierFilter<T extends ObservedMeasurement<T>> implements EstimationModifier<T> {

  32.     /** Warmup iterations. */
  33.     private final int warmup;

  34.     /** Outlier detection limit. */
  35.     private final double maxSigma;

  36.     /** Simple constructor.
  37.      * @param warmup number of iterations before with filter is not applied
  38.      * @param maxSigma detection limit for outliers.
  39.      */
  40.     public OutlierFilter(final int warmup, final double maxSigma) {
  41.         this.warmup   = warmup;
  42.         this.maxSigma = maxSigma;
  43.     }

  44.     /** Get the value of warmup iterations.
  45.      * @return the value of warmup iterations
  46.      */
  47.     protected int getWarmup() {
  48.         return warmup;
  49.     }

  50.     /** Get the value of the outlier detection limit.
  51.      *  @return the value of the outlier detection limit
  52.      */
  53.     protected double getMaxSigma() {
  54.         return maxSigma;
  55.     }
  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public List<ParameterDriver> getParametersDrivers() {
  59.         return Collections.emptyList();
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated) {

  64.         if (estimated.getIteration() > warmup) {

  65.             // check if observed value is far to estimation
  66.             final double[] observed    = estimated.getObservedMeasurement().getObservedValue();
  67.             final double[] theoretical = estimated.getEstimatedValue();
  68.             final double[] sigma       = estimated.getObservedMeasurement().getTheoreticalStandardDeviation();
  69.             for (int i = 0; i < observed.length; ++i) {
  70.                 if (FastMath.abs(observed[i] - theoretical[i]) > maxSigma * sigma[i]) {
  71.                     // observed value is too far, reject measurement
  72.                     estimated.setStatus(EstimatedMeasurement.Status.REJECTED);
  73.                 }
  74.             }
  75.         }

  76.     }

  77. }