1 /* Copyright 2002-2021 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
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.orekit.estimation.measurements.EstimatedMeasurement;
24 import org.orekit.estimation.measurements.EstimationModifier;
25 import org.orekit.estimation.measurements.ObservedMeasurement;
26 import org.orekit.utils.ParameterDriver;
27
28 /** Class modeling a measurement bias.
29 * @param <T> the type of the measurement
30 * @author Luc Maisonobe
31 * @since 8.0
32 */
33 public class Bias<T extends ObservedMeasurement<T>> implements EstimationModifier<T> {
34
35 /** Parameters holding the bias value components. */
36 private final List<ParameterDriver> drivers;
37
38 /** Partial derivatives. */
39 private final double[][] derivatives;
40
41 /** Simple constructor.
42 * @param name name of the bias
43 * @param bias reference value of the bias
44 * @param scale scale of the bias, for normalization
45 * @param min minimum value of the bias
46 * @param max maximum value of the bias
47 */
48 public Bias(final String[] name, final double[] bias, final double[] scale,
49 final double[] min, final double[] max) {
50
51 drivers = new ArrayList<>(bias.length);
52 for (int i = 0; i < bias.length; ++i) {
53 drivers.add(new ParameterDriver(name[i], bias[i], scale[i], min[i], max[i]));
54 }
55
56 derivatives = new double[bias.length][bias.length];
57 for (int i = 0; i < bias.length; ++i) {
58 // derivatives are computed with respect to the physical parameters,
59 // not with respect to the normalized parameters (normalization is
60 // performed later on), so the derivative is really 1.0 and not scale[i]
61 derivatives[i][i] = 1.0;
62 }
63
64 }
65
66 /** {@inheritDoc}
67 * <p>
68 * For a bias, there are {@link ObservedMeasurement#getDimension()} parameter drivers,
69 * sorted in components order.
70 * </p>
71 */
72 @Override
73 public List<ParameterDriver> getParametersDrivers() {
74 return Collections.unmodifiableList(drivers);
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 public void modify(final EstimatedMeasurement<T> estimated) {
80
81 // apply the bias to the measurement value
82 final double[] value = estimated.getEstimatedValue();
83 for (int i = 0; i < drivers.size(); ++i) {
84 final ParameterDriver driver = drivers.get(i);
85 value[i] += driver.getValue();
86 if (driver.isSelected()) {
87 // add the partial derivatives
88 estimated.setParameterDerivatives(driver, derivatives[i]);
89 }
90 }
91 estimated.setEstimatedValue(value);
92
93
94 }
95
96 }