1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.estimation.measurements;
18
19 import java.util.Arrays;
20
21 import org.hipparchus.linear.MatrixUtils;
22 import org.hipparchus.linear.RealMatrix;
23 import org.hipparchus.util.FastMath;
24 import org.orekit.errors.OrekitException;
25 import org.orekit.errors.OrekitMessages;
26
27
28
29
30
31
32 public class MeasurementQuality {
33
34
35 private final double[][] covarianceMatrix;
36
37
38 private final double[] sigmas;
39
40
41 private final double[] weights;
42
43
44 private final int measurementDimension;
45
46
47
48
49
50 public MeasurementQuality(final double standardDeviation) {
51 this(standardDeviation, 1.);
52 }
53
54
55
56
57
58 public MeasurementQuality(final double[] standardDeviations) {
59 this(standardDeviations, 1.);
60 }
61
62
63
64
65
66
67 public MeasurementQuality(final double[] standardDeviations, final double weight) {
68 this(standardDeviations, buildWeights(weight, standardDeviations.length));
69 }
70
71
72
73
74
75
76 public MeasurementQuality(final double[][] covarianceMatrix, final double weight) {
77 this(covarianceMatrix, buildWeights(weight, covarianceMatrix.length));
78 }
79
80
81
82
83
84
85 public MeasurementQuality(final double standardDeviation, final double weight) {
86 this.measurementDimension = 1;
87 this.weights = new double[] {weight};
88 this.sigmas = new double[] {standardDeviation};
89 this.covarianceMatrix = new double[][] {new double[] {standardDeviation * standardDeviation}};
90 }
91
92
93
94
95
96
97 public MeasurementQuality(final double[][] covarianceMatrix, final double[] weights) {
98 if (covarianceMatrix.length != weights.length) {
99 throw new OrekitException(OrekitMessages.WRONG_MEASUREMENT_COVARIANCE_DIMENSION, covarianceMatrix.length, weights.length);
100 } else if (covarianceMatrix.length != covarianceMatrix[0].length) {
101 throw new OrekitException(OrekitMessages.COVARIANCE_MUST_BE_SQUARE);
102 }
103 this.measurementDimension = covarianceMatrix.length;
104 this.weights = weights.clone();
105 this.covarianceMatrix = new double[measurementDimension][];
106 this.sigmas = new double[measurementDimension];
107 for (int i = 0; i < measurementDimension; i++) {
108 this.covarianceMatrix[i] = covarianceMatrix[i].clone();
109 this.sigmas[i] = FastMath.sqrt(covarianceMatrix[i][i]);
110 }
111 }
112
113
114
115
116
117
118 public MeasurementQuality(final double[] standardDeviations, final double[] weights) {
119 if (standardDeviations.length != weights.length) {
120 throw new OrekitException(OrekitMessages.WRONG_MEASUREMENT_COVARIANCE_DIMENSION, standardDeviations.length,
121 weights.length);
122 }
123 this.measurementDimension = standardDeviations.length;
124 this.weights = weights.clone();
125 this.sigmas = standardDeviations.clone();
126 this.covarianceMatrix = new double[measurementDimension][measurementDimension];
127 for (int i = 0; i < sigmas.length; i++) {
128 covarianceMatrix[i][i] = sigmas[i] * sigmas[i];
129 }
130 }
131
132
133
134
135
136
137
138 private static double[] buildWeights(final double weight, final int dimension) {
139 final double[] weights = new double[dimension];
140 Arrays.fill(weights, weight);
141 return weights;
142 }
143
144
145
146
147
148 public int getDimension() {
149 return measurementDimension;
150 }
151
152
153
154
155
156 public RealMatrix getCovarianceMatrix() {
157 final double[][] coefficients = new double[measurementDimension][measurementDimension];
158 for (int i = 0; i < measurementDimension; i++) {
159 coefficients[i] = covarianceMatrix[i].clone();
160 }
161 return MatrixUtils.createRealMatrix(coefficients);
162 }
163
164
165
166
167
168 public double[] getStandardDeviations() {
169 return sigmas.clone();
170 }
171
172
173
174
175
176
177
178
179
180
181
182 public RealMatrix getCorrelationMatrix() {
183
184 final double[][] corrCoefMatrix = new double[measurementDimension][measurementDimension];
185
186
187 for (int i = 0; i < corrCoefMatrix.length; i++) {
188 for (int j = 0; j < corrCoefMatrix[0].length; j++) {
189 corrCoefMatrix[i][j] = covarianceMatrix[i][j] / (sigmas[i] * sigmas[j]);
190 }
191 }
192 return MatrixUtils.createRealMatrix(corrCoefMatrix);
193 }
194
195
196
197
198
199 public double[] getWeights() {
200 return weights.clone();
201 }
202
203 }