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
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.EstimatedMeasurementBase;
25 import org.orekit.estimation.measurements.EstimationModifier;
26 import org.orekit.estimation.measurements.ObservedMeasurement;
27 import org.orekit.utils.ParameterDriver;
28 import org.orekit.utils.TimeSpanMap.Span;
29
30 /** Class modeling a measurement bias.
31 * @param <T> the type of the measurement
32 * @author Luc Maisonobe
33 * @since 8.0
34 */
35 public class Bias<T extends ObservedMeasurement<T>> implements EstimationModifier<T> {
36
37 /** Parameters holding the bias value components. */
38 private final List<ParameterDriver> drivers;
39
40 /** Partial derivatives. */
41 private final double[][] derivatives;
42
43 /** Simple constructor.
44 * @param name name of the bias
45 * @param bias reference value of the bias
46 * @param scale scale of the bias, for normalization
47 * @param min minimum value of the bias
48 * @param max maximum value of the bias
49 */
50 public Bias(final String[] name, final double[] bias, final double[] scale,
51 final double[] min, final double[] max) {
52
53 drivers = new ArrayList<>(bias.length);
54 for (int i = 0; i < bias.length; ++i) {
55 drivers.add(new ParameterDriver(name[i], bias[i], scale[i], min[i], max[i]));
56 }
57
58 derivatives = new double[bias.length][bias.length];
59 for (int i = 0; i < bias.length; ++i) {
60 // derivatives are computed with respect to the physical parameters,
61 // not with respect to the normalized parameters (normalization is
62 // performed later on), so the derivative is really 1.0 and not scale[i]
63 derivatives[i][i] = 1.0;
64 }
65
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public String getEffectName() {
71 return drivers.get(0).getName();
72 }
73
74 /** {@inheritDoc}
75 * <p>
76 * For a bias, there are {@link ObservedMeasurement#getDimension()} parameter drivers,
77 * sorted in components order.
78 * </p>
79 */
80 @Override
81 public List<ParameterDriver> getParametersDrivers() {
82 return Collections.unmodifiableList(drivers);
83 }
84
85 /** {@inheritDoc} */
86 @Override
87 public void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated) {
88
89 // apply the bias to the measurement value
90 final double[] value = estimated.getEstimatedValue();
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 value[nb++] += driver.getValue(span.getStart());
96 }
97 }
98 estimated.modifyEstimatedValue(this, value);
99
100 }
101
102 /** {@inheritDoc} */
103 @Override
104 public void modify(final EstimatedMeasurement<T> estimated) {
105
106 // apply the bias to the measurement value
107 int nb = 0;
108 for (final ParameterDriver driver : drivers) {
109 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan();
110 span != null; span = span.next()) {
111 if (driver.isSelected()) {
112 // add the partial derivatives
113 estimated.setParameterDerivatives(driver, span.getStart(),
114 derivatives[nb++]);
115 }
116 }
117 }
118
119 modifyWithoutDerivatives(estimated);
120
121 }
122
123 }