OutlierFilter.java

  1. /* Copyright 2002-2022 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.EstimationModifier;
  23. import org.orekit.estimation.measurements.ObservedMeasurement;
  24. import org.orekit.utils.ParameterDriver;

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

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

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

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

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

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

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public void modify(final EstimatedMeasurement<T> estimated) {

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

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

  75.     }

  76. }