00001 #pragma ident "$Id: SolverWMS.cpp 1325 2008-07-29 14:33:43Z architest $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "SolverBase.hpp"
00032 #include "SolverWMS.hpp"
00033 #include "MatrixFunctors.hpp"
00034
00035
00036 namespace gpstk
00037 {
00038
00039
00040 int SolverWMS::classIndex = 9100000;
00041
00042
00043
00044 int SolverWMS::getIndex() const
00045 { return index; }
00046
00047
00048
00049 std::string SolverWMS::getClassName() const
00050 { return "SolverWMS"; }
00051
00052
00053
00054
00055
00056
00057
00058 SolverWMS::SolverWMS()
00059 {
00060
00061
00062 TypeIDSet tempSet;
00063 tempSet.insert(TypeID::dx);
00064 tempSet.insert(TypeID::dy);
00065 tempSet.insert(TypeID::dz);
00066 tempSet.insert(TypeID::cdt);
00067
00068
00069
00070 defaultEqDef.header = TypeID::prefitC;
00071 defaultEqDef.body = tempSet;
00072 setIndex();
00073
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 SolverWMS::SolverWMS(const gnssEquationDefinition& eqDef)
00084 {
00085
00086 setDefaultEqDefinition(eqDef);
00087
00088 setIndex();
00089
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 int SolverWMS::Compute( const Vector<double>& prefitResiduals,
00107 const Matrix<double>& designMatrix,
00108 const Vector<double>& weightVector )
00109 throw(InvalidSolver)
00110 {
00111
00112
00113 valid = false;
00114
00115
00116 int wSize = static_cast<int>(weightVector.size());
00117 int pSize = static_cast<int>(prefitResiduals.size());
00118 if (!(wSize==pSize))
00119 {
00120 InvalidSolver e("prefitResiduals size does not match dimension \
00121 of weightVector");
00122 GPSTK_THROW(e);
00123 }
00124
00125 Matrix<double> wMatrix(wSize,wSize,0.0);
00126
00127
00128
00129 for (int i=0; i<wSize; i++)
00130 {
00131 wMatrix(i,i) = weightVector(i);
00132 }
00133
00134
00135 return SolverWMS::Compute(prefitResiduals, designMatrix, wMatrix);
00136
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 int SolverWMS::Compute( const Vector<double>& prefitResiduals,
00153 const Matrix<double>& designMatrix,
00154 const Matrix<double>& weightMatrix )
00155 throw(InvalidSolver)
00156 {
00157
00158
00159 valid = false;
00160
00161 if (!(weightMatrix.isSquare()))
00162 {
00163 InvalidSolver e("Weight matrix is not square");
00164 GPSTK_THROW(e);
00165 }
00166
00167 int wRow = static_cast<int>(weightMatrix.rows());
00168 int pRow = static_cast<int>(prefitResiduals.size());
00169 if (!(wRow==pRow))
00170 {
00171 InvalidSolver e("prefitResiduals size does not match dimension of \
00172 weightMatrix");
00173 GPSTK_THROW(e);
00174 }
00175
00176 int gCol = static_cast<int>(designMatrix.cols());
00177
00178 int gRow = static_cast<int>(designMatrix.rows());
00179 if (!(gRow==pRow))
00180 {
00181 InvalidSolver e("prefitResiduals size does not match dimension \
00182 of designMatrix");
00183 GPSTK_THROW(e);
00184 }
00185
00186 Matrix<double> AT = transpose(designMatrix);
00187 covMatrix.resize(gCol, gCol);
00188 covMatrixNoWeight.resize(gCol, gCol);
00189 solution.resize(gCol);
00190
00191
00192 covMatrix = AT * weightMatrix * designMatrix;
00193
00194
00195 try {
00196 covMatrix = inverseChol( covMatrix );
00197 }
00198 catch(...)
00199 {
00200 InvalidSolver e("Unable to invert matrix covMatrix");
00201 GPSTK_THROW(e);
00202 }
00203
00204
00205 covMatrixNoWeight = AT * designMatrix;
00206
00207
00208 try {
00209 covMatrixNoWeight = inverseChol( covMatrixNoWeight );
00210 }
00211 catch(...)
00212 {
00213 InvalidSolver e("Unable to invert matrix covMatrixNoWeight");
00214 GPSTK_THROW(e);
00215 }
00216
00217
00218 solution = covMatrix * AT * weightMatrix * prefitResiduals;
00219
00220
00221 postfitResiduals = prefitResiduals - designMatrix * solution;
00222
00223
00224 valid = true;
00225
00226 return 0;
00227
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237 satTypeValueMap& SolverWMS::Process(satTypeValueMap& gData)
00238 throw(ProcessingException)
00239 {
00240
00241 try
00242 {
00243
00244
00245 Vector<double> prefit(gData.getVectorOfTypeID(defaultEqDef.header));
00246
00247
00248 Matrix<double> dMatrix(gData.getMatrixOfTypes(defaultEqDef.body));
00249
00250
00251 Vector<double> weightsVector(gData.getVectorOfTypeID(TypeID::weight));
00252
00253
00254
00255
00256 Compute(prefit, dMatrix, weightsVector);
00257
00258
00259 if ( defaultEqDef.header == TypeID::prefitC )
00260 {
00261 gData.insertTypeIDVector(TypeID::postfitC, postfitResiduals);
00262 }
00263
00264 if ( defaultEqDef.header == TypeID::prefitL )
00265 {
00266 gData.insertTypeIDVector(TypeID::postfitL, postfitResiduals);
00267 }
00268
00269 return gData;
00270
00271 }
00272 catch(Exception& u)
00273 {
00274
00275 ProcessingException e( getClassName() + ":"
00276 + StringUtils::asString( getIndex() ) + ":"
00277 + u.what() );
00278
00279 GPSTK_THROW(e);
00280
00281 }
00282
00283 }
00284
00285
00286
00287 }