Bias.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.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  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. import org.orekit.utils.TimeSpanMap.Span;

  27. /** Class modeling a measurement bias.
  28.  * @param <T> the type of the measurement
  29.  * @author Luc Maisonobe
  30.  * @since 8.0
  31.  */
  32. public class Bias<T extends ObservedMeasurement<T>> implements EstimationModifier<T> {

  33.     /** Parameters holding the bias value components. */
  34.     private final List<ParameterDriver> drivers;

  35.     /** Partial derivatives. */
  36.     private final double[][] derivatives;

  37.     /** Simple constructor.
  38.      * @param name name of the bias
  39.      * @param bias reference value of the bias
  40.      * @param scale scale of the bias, for normalization
  41.      * @param min minimum value of the bias
  42.      * @param max maximum value of the bias
  43.      */
  44.     public Bias(final String[] name, final double[] bias, final double[] scale,
  45.                 final double[] min, final double[] max) {

  46.         drivers = new ArrayList<>(bias.length);
  47.         for (int i = 0; i < bias.length; ++i) {
  48.             drivers.add(new ParameterDriver(name[i], bias[i], scale[i], min[i], max[i]));
  49.         }

  50.         derivatives = new double[bias.length][bias.length];
  51.         for (int i = 0; i < bias.length; ++i) {
  52.             // derivatives are computed with respect to the physical parameters,
  53.             // not with respect to the normalized parameters (normalization is
  54.             // performed later on), so the derivative is really 1.0 and not scale[i]
  55.             derivatives[i][i] = 1.0;
  56.         }

  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public String getEffectName() {
  61.         return drivers.get(0).getName();
  62.     }

  63.     /** {@inheritDoc}
  64.      * <p>
  65.      * For a bias, there are {@link ObservedMeasurement#getDimension()} parameter drivers,
  66.      * sorted in components order.
  67.      * </p>
  68.      */
  69.     @Override
  70.     public List<ParameterDriver> getParametersDrivers() {
  71.         return Collections.unmodifiableList(drivers);
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated) {

  76.         // apply the bias to the measurement value
  77.         final double[] value = estimated.getEstimatedValue();
  78.         int nb = 0;
  79.         for (final ParameterDriver driver : drivers) {
  80.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan();
  81.                  span != null; span = span.next()) {
  82.                 value[nb++] += driver.getValue(span.getStart());
  83.             }
  84.         }
  85.         estimated.modifyEstimatedValue(this, value);

  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public void modify(final EstimatedMeasurement<T> estimated) {

  90.         // apply the bias to the measurement value
  91.         int nb = 0;
  92.         for (final ParameterDriver driver : drivers) {
  93.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan();
  94.                  span != null; span = span.next()) {
  95.                 if (driver.isSelected()) {
  96.                     // add the partial derivatives
  97.                     estimated.setParameterDerivatives(driver, span.getStart(),
  98.                                                       derivatives[nb++]);
  99.                 }
  100.             }
  101.         }

  102.         modifyWithoutDerivatives(estimated);

  103.     }

  104. }