EstimatedMeasurement.java

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

  18. import java.util.IdentityHashMap;
  19. import java.util.Map;
  20. import java.util.stream.Stream;

  21. import org.orekit.errors.OrekitIllegalArgumentException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.TimeStamped;
  26. import org.orekit.utils.ParameterDriver;
  27. import org.orekit.utils.TimeStampedPVCoordinates;

  28. /** Class holding an estimated theoretical value associated to an {@link ObservedMeasurement observed measurement}.
  29.  * @param <T> the type of the measurement
  30.  * @author Luc Maisonobe
  31.  * @since 8.0
  32.  */
  33. public class EstimatedMeasurement<T extends ObservedMeasurement<T>> implements TimeStamped {

  34.     /** Associated observed measurement. */
  35.     private final T observedMeasurement;

  36.     /** Iteration number. */
  37.     private final int iteration;

  38.     /** Evaluations counter. */
  39.     private final int count;

  40.     /** States of the spacecrafts. */
  41.     private final SpacecraftState[] states;

  42.     /** Coordinates of the participants in signal travel order. */
  43.     private final TimeStampedPVCoordinates[] participants;

  44.     /** Estimated value. */
  45.     private double[] estimatedValue;

  46.     /** Current weight. */
  47.     private double[] currentWeight;

  48.     /** Partial derivatives with respect to states. */
  49.     private double[][][] stateDerivatives;

  50.     /** Partial derivatives with respect to parameters. */
  51.     private final Map<ParameterDriver, double[]> parametersDerivatives;

  52.     /** Simple constructor.
  53.      * @param observedMeasurement associated observed measurement
  54.      * @param iteration iteration number
  55.      * @param count evaluations counter
  56.      * @param states states of the spacecrafts
  57.      * @param participants coordinates of the participants in signal travel order
  58.      * in inertial frame
  59.      */
  60.     public EstimatedMeasurement(final T observedMeasurement,
  61.                                 final int iteration, final int count,
  62.                                 final SpacecraftState[] states,
  63.                                 final TimeStampedPVCoordinates[] participants) {
  64.         this.observedMeasurement   = observedMeasurement;
  65.         this.iteration             = iteration;
  66.         this.count                 = count;
  67.         this.states                = states.clone();
  68.         this.participants          = participants.clone();
  69.         this.stateDerivatives      = new double[states.length][][];
  70.         this.parametersDerivatives = new IdentityHashMap<ParameterDriver, double[]>();
  71.     }

  72.     /** Get the associated observed measurement.
  73.      * @return associated observed measurement
  74.      */
  75.     public T getObservedMeasurement() {
  76.         return observedMeasurement;
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public AbsoluteDate getDate() {
  81.         return observedMeasurement.getDate();
  82.     }

  83.     /** Get the iteration number.
  84.      * @return iteration number
  85.      */
  86.     public int getIteration() {
  87.         return iteration;
  88.     }

  89.     /** Get the evaluations counter.
  90.      * @return evaluations counter
  91.      */
  92.     public int getCount() {
  93.         return count;
  94.     }

  95.     /** Get the states of the spacecrafts.
  96.      * @return states of the spacecrafts
  97.      */
  98.     public SpacecraftState[] getStates() {
  99.         return states.clone();
  100.     }

  101.     /** Get the coordinates of the measurements participants in signal travel order.
  102.      * <p>
  103.      * First participant (at index 0) emits the signal (it is for example a ground
  104.      * station for two-way range measurement). Last participant receives the signal
  105.      * (it is also the ground station for two-way range measurement, but a few
  106.      * milliseconds later). Intermediate participants relfect the signal (it is the
  107.      * spacecraft for two-way range measurement).
  108.      * </p>
  109.      * @return coordinates of the measurements participants in signal travel order
  110.      * in inertial frame
  111.      */
  112.     public TimeStampedPVCoordinates[] getParticipants() {
  113.         return participants.clone();
  114.     }

  115.     /** Get the time offset from first state date to measurement date.
  116.      * @return time offset from first state date to measurement date
  117.      */
  118.     public double getTimeOffset() {
  119.         return observedMeasurement.getDate().durationFrom(states[0].getDate());
  120.     }

  121.     /** Get the estimated value.
  122.      * @return estimated value
  123.      */
  124.     public double[] getEstimatedValue() {
  125.         return estimatedValue.clone();
  126.     }

  127.     /** Set the estimated value.
  128.      * @param estimatedValue estimated value
  129.      */
  130.     public void setEstimatedValue(final double... estimatedValue) {
  131.         this.estimatedValue = estimatedValue.clone();
  132.     }

  133.     /** Get the current weight.
  134.      * <p>
  135.      * By default, the current weight is measurement {@link
  136.      * ObservedMeasurement#getBaseWeight() base weight}.
  137.      * </p>
  138.      * @return current weight
  139.      */
  140.     public double[] getCurrentWeight() {
  141.         return currentWeight == null ? observedMeasurement.getBaseWeight() : currentWeight.clone();
  142.     }

  143.     /** Set the current weight.
  144.      * @param currentWeight current weight
  145.      */
  146.     public void setCurrentWeight(final double... currentWeight) {
  147.         this.currentWeight = currentWeight.clone();
  148.     }

  149.     /** Get the partial derivatives of the {@link #getEstimatedValue()
  150.      * simulated measurement} with respect to state Cartesian coordinates.
  151.      * @param index index of the state, according to the {@code states}
  152.      * passed at construction
  153.      * @return partial derivatives of the simulated value (array of size
  154.      * {@link ObservedMeasurement#getDimension() dimension} x 6)
  155.      */
  156.     public double[][] getStateDerivatives(final int index) {
  157.         final double[][] sd = new double[observedMeasurement.getDimension()][];
  158.         for (int i = 0; i < observedMeasurement.getDimension(); ++i) {
  159.             sd[i] = stateDerivatives[index][i].clone();
  160.         }
  161.         return sd;
  162.     }

  163.     /** Set the partial derivatives of the {@link #getEstimatedValue()
  164.      * simulated measurement} with respect to state Cartesian coordinates.
  165.      * @param index index of the state, according to the {@code states}
  166.      * passed at construction
  167.      * @param derivatives partial derivatives with respect to state
  168.      */
  169.     public void setStateDerivatives(final int index, final double[]... derivatives) {
  170.         this.stateDerivatives[index] = new double[observedMeasurement.getDimension()][];
  171.         for (int i = 0; i < observedMeasurement.getDimension(); ++i) {
  172.             this.stateDerivatives[index][i] = derivatives[i].clone();
  173.         }
  174.     }

  175.     /** Get all the drivers with set derivatives.
  176.      * @return all the drivers with set derivatives
  177.      * @since 9.0
  178.      */
  179.     public Stream<ParameterDriver> getDerivativesDrivers() {
  180.         return parametersDerivatives.entrySet().stream().map(entry -> entry.getKey());
  181.     }

  182.     /** Get the partial derivatives of the {@link #getEstimatedValue()
  183.      * simulated measurement} with respect to a parameter.
  184.      * @param driver driver for the parameter
  185.      * @return partial derivatives of the simulated value
  186.      * @exception OrekitIllegalArgumentException if parameter is unknown
  187.      */
  188.     public double[] getParameterDerivatives(final ParameterDriver driver)
  189.         throws OrekitIllegalArgumentException {
  190.         final double[] p = parametersDerivatives.get(driver);
  191.         if (p == null) {
  192.             final StringBuilder builder = new StringBuilder();
  193.             for (final Map.Entry<ParameterDriver, double[]> entry : parametersDerivatives.entrySet()) {
  194.                 if (builder.length() > 0) {
  195.                     builder.append(", ");
  196.                 }
  197.                 builder.append(entry.getKey().getName());
  198.             }
  199.             throw new OrekitIllegalArgumentException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME,
  200.                                                      driver.getName(),
  201.                                                      builder.length() > 0 ? builder.toString() : "<none>");
  202.         }
  203.         return p;
  204.     }

  205.     /** Set the partial derivatives of the {@link #getEstimatedValue()
  206.      * simulated measurement} with respect to parameter.
  207.      * @param driver driver for the parameter
  208.      * @param parameterDerivatives partial derivatives with respect to parameter
  209.      */
  210.     public void setParameterDerivatives(final ParameterDriver driver, final double... parameterDerivatives) {
  211.         parametersDerivatives.put(driver, parameterDerivatives);
  212.     }

  213. }