Bias.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  22. import org.orekit.estimation.measurements.EstimatedMeasurement;
  23. import org.orekit.estimation.measurements.EstimationModifier;
  24. import org.orekit.estimation.measurements.ObservedMeasurement;
  25. import org.orekit.utils.ParameterDriver;

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

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

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

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

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

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

  58.     }

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

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public void modify(final EstimatedMeasurement<T> estimated) {

  72.         // apply the bias to the measurement value
  73.         final double[] value = estimated.getEstimatedValue();
  74.         for (int i = 0; i < drivers.size(); ++i) {
  75.             final ParameterDriver driver = drivers.get(i);
  76.             value[i] += driver.getValue();
  77.             if (driver.isSelected()) {
  78.                 // add the partial derivatives
  79.                 estimated.setParameterDerivatives(driver, derivatives[i]);
  80.             }
  81.         }
  82.         estimated.setEstimatedValue(value);


  83.     }

  84. }