OutlierFilter.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.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.     /** {@inheritDoc} */
  45.     @Override
  46.     public String getEffectName() {
  47.         return "outlier";
  48.     }

  49.     /** Get the value of warmup iterations.
  50.      * @return the value of warmup iterations
  51.      */
  52.     protected int getWarmup() {
  53.         return warmup;
  54.     }

  55.     /** Get the value of the outlier detection limit.
  56.      *  @return the value of the outlier detection limit
  57.      */
  58.     protected double getMaxSigma() {
  59.         return maxSigma;
  60.     }
  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public List<ParameterDriver> getParametersDrivers() {
  64.         return Collections.emptyList();
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated) {

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

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

  81.     }

  82. }