A base class for implementing Kalman filter using SRIFilter. Define a class with this class as base, implement some or all the virtual functions to define problem.
The derived class MUST overload: virtual int defineInitial() to define initial time and apriori state and cov. virtual int defineMeasurements() to define Partials, Data and MCov. virtual void defineTimestep() to define Phi, G, Rw and Control
The derived class MAY overload this function, which is called between updates, virtual int defineInterim() to output, change the state or anything else. This routine is called at four times: before the measurement update (MU), between the MU and the time update (TU), after the TU, between smoother updates (SU). If it returns >0 output() is called.
The derived class may want to overload the output() routine. The Update routines may be overloaded if necessary (but it shouldn't be).
Note that a "time" is used by the Kalman to index the data and determine how to time update (TU); this need not be a real time, however; it is ONLY required that 0. defineInitial(T0 ...) defines the starting value of T (NB also timeReverse)
How to use the derived class:
Several switches may be used to control the filter. For each there is also a 'set' routine.
Definition at line 136 of file KalmanFilter.hpp.
#include <KalmanFilter.hpp>
Classes | |
struct | Smoother_storage_record |
Storage for smoothing algorithm; stored by forward filter, used by SU. More... | |
Public Types | |
typedef enum gnsstk::KalmanFilter::FilterStageEnum | FilterStage |
enum | FilterStageEnum { Unknown = 0, Init, IB1, IB2, IB3, TU, MU, SU, StageCount } |
enum | KalmanMUReturnValuesEnum { Process = 0, ProcessThenQuit, SkipThisEpoch, SkipThenQuit, QuitImmediately, ReturnCount } |
typedef enum gnsstk::KalmanFilter::KalmanMUReturnValuesEnum | KalmanReturn |
Public Member Functions | |
void | BackwardFilter (double M) |
virtual void | BackwardFilter (int M) |
virtual int | defineInitial (double &T0, gnsstk::Vector< double > &X, gnsstk::Matrix< double > &Cov)=0 |
virtual int | defineInterim (int which, double Time) |
virtual KalmanReturn | defineMeasurements (double &T, const gnsstk::Vector< double > &X, const gnsstk::Matrix< double > &C, bool useFlag)=0 |
virtual void | defineTimestep (double T, double DT, const gnsstk::Vector< double > &State, const gnsstk::Matrix< double > &Cov, bool useFlag)=0 |
virtual void | ForwardFilter (double finalT, double DT) |
gnsstk::Matrix< double > | getCovariance () |
get the covariance (must be non-singular) More... | |
bool | getDoInvert () |
if doInversions, SRIF is inverted at each step, defining State and Cov More... | |
bool | getDoOutput () |
if doOutput, output() is called at each step More... | |
gnsstk::Namelist | getNames () |
get the state namelist More... | |
int | getNMU () |
get number of measurements processed More... | |
gnsstk::SRI | getSRI () |
gnsstk::Vector< double > | getState () |
get the state (must be non-singular) More... | |
std::string | getTag () |
KF tag is a user-defined string output on each line. More... | |
virtual void | initializeFilter () |
bool | isDryRun () |
bool | isExtended () |
if extended, use an extended Kalman (not implemented) More... | |
bool | isSingular () |
true when filter is singular More... | |
bool | isSmoother () |
bool | isSRISU () |
bool | isTimeReversed () |
KalmanFilter () | |
KalmanFilter (const gnsstk::Namelist &NL) | |
virtual int | KalmanInterim (int which, double Time) |
virtual KalmanReturn | KalmanMeasurementUpdate (double &T) |
virtual void | KalmanSmootherUpdate () |
virtual void | KalmanTimeUpdate (double T, double DT) |
virtual void | output (int N) |
void | Reset (const gnsstk::Namelist &NL) |
void | setDoInvert (bool on) |
void | setDoOutput (bool on) |
void | setDryRun (bool t=true) |
if dryRun, do not operate the filter, just print More... | |
void | setExtended (bool ext) |
void | setSmoother (bool ext) |
if smoother, save info during forward filter for use by backward filter More... | |
void | setSRI (gnsstk::SRI &sri) |
get the filter SRI More... | |
void | setSRISU (bool ext) |
if doSRISU use SRIF form of smoother, else DM smoother More... | |
void | setTag (std::string tag) |
void | setTimeReverse (bool tr=true) |
if timeReversed, time T decreases during the forward filter More... | |
virtual | ~KalmanFilter () |
destructor More... | |
Protected Types | |
typedef struct gnsstk::KalmanFilter::Smoother_storage_record | SmootherStoreRec |
Storage for smoothing algorithm; stored by forward filter, used by SU. More... | |
Protected Attributes | |
double | big |
gnsstk::Vector< double > | Control |
SRIF vector used internally. More... | |
gnsstk::Matrix< double > | Cov |
filter covariance More... | |
gnsstk::Vector< double > | Data |
vector defined by defineM() and used in MU More... | |
bool | doInversions |
bool | doOutput |
if true, output at each stage using output() routine. NB used inside output() More... | |
bool | doSRISU |
bool | dryRun |
bool | extended |
gnsstk::Matrix< double > | G |
SRIF matrix used internally - noise. More... | |
bool | inverted |
if true then the SRI has been inverted and State and Cov are valid More... | |
std::string | KFtag |
optional tag to put in output (2nd field) More... | |
gnsstk::Matrix< double > | MCov |
measurement covariance (defineM() for MU) More... | |
int | NMU |
count of measurement updates More... | |
int | Nnoise |
Nnoise is there only for the user. More... | |
double | nominalDT |
change in time for one TU seconds More... | |
int | Nstate |
number of state elements More... | |
int | NSU |
count of smoother updates More... | |
int | NTU |
count of time updates: ++ in TU, – in SU More... | |
gnsstk::Matrix< double > | Partials |
matrix defined by defineM() and used in MU More... | |
gnsstk::Vector< double > | PFResid |
post-fit residuals - valid after MU More... | |
gnsstk::Matrix< double > | PhiInv |
SRIF matrix used internally - inv state trans. More... | |
gnsstk::Matrix< double > | Rw |
SRIF matrix used internally. More... | |
bool | singular |
double | small |
condition number at last inversion = b/s More... | |
bool | smoother |
std::map< int, SmootherStoreRec > | SmootherStore |
gnsstk::Vector< double > | SMResid |
post-smoother residuals - value after SU More... | |
gnsstk::SRIFilter | srif |
SRIF. More... | |
FilterStage | stage |
current stage of the filter - see enum More... | |
gnsstk::Vector< double > | State |
filter state More... | |
double | time |
seconds since start More... | |
bool | timeReversed |
if true then independent variable "time" decreases More... | |
gnsstk::Vector< double > | Zw |
SRIF vector used internally. More... | |
Private Member Functions | |
void | initialize (const gnsstk::Namelist &NL) |
void | Invert (const std::string &msg=std::string()) |
|
protected |
Storage for smoothing algorithm; stored by forward filter, used by SU.
Enumerator | |
---|---|
Unknown | |
Init | |
IB1 | |
IB2 | |
IB3 | |
TU | |
MU | |
SU | |
StageCount |
Definition at line 140 of file KalmanFilter.hpp.
Enumerator | |
---|---|
Process | |
ProcessThenQuit | |
SkipThisEpoch | |
SkipThenQuit | |
QuitImmediately | |
ReturnCount |
Definition at line 154 of file KalmanFilter.hpp.
|
inline |
Definition at line 336 of file KalmanFilter.hpp.
|
inline |
Constructor given an initial Namelist for the filter state
NL | Namelist of the filter states (determines Nstate) |
Definition at line 348 of file KalmanFilter.hpp.
|
inlinevirtual |
destructor
Definition at line 357 of file KalmanFilter.hpp.
|
inline |
Backward filter (smoother) with double argument - this is a trick to prevent the user from calling BackwardFilter(time).
Definition at line 563 of file KalmanFilter.hpp.
|
inlinevirtual |
Backward filter or smoother. Smooth down to NTU==M. Decrements time and NTU Calls defineInterim(4,time) after each smoother update
M | value of NTU at which to stop the smoother (usually 0) |
Definition at line 575 of file KalmanFilter.hpp.
|
pure virtual |
Pure virtual function, to be overloaded and provided by the caller, providing complete apriori information, including initial time T0, and either {state vector X, and covariance Cov} (return 1) or the inverse {inverse covariance*state X, and inverse covariance Cov} (return -1) or no (zero) information (return 0). If non-0 is returned, the matrix must be non-singular. Note that the SRIF was zero-ed by either the constructor or Reset() just before this call, so if no information is added, doInversions should be false.
T0 | initial time |
X | initial state/inv(cov)*state/ignored as return 1/-1/0 |
Cov | initial covariance/inv(cov)/ignored as return 1/-1/0 |
Implemented in gnsstk::WNJfilter.
|
inlinevirtual |
Pure virtual function, to be overloaded and provided by the caller, providing This routine is called three times within the ForwardFilter loop: before MU, between MU and TU, and after TU, and once during the BackwardFilter between SUs.
which | = 1(before MU), 2(between MU and TU), 3(after TU), 4(after SU) |
Definition at line 328 of file KalmanFilter.hpp.
|
pure virtual |
Pure virtual function, to be overloaded and provided by the caller, providing members Partials, Data and MCov (M. Covariance) at next data epoch time T. The current time T is passed into this routine; it should redefine T to be the time of the next data epoch. Generally, if T(next) > T(curr) + nominalDT, this routine should return Skip(2) (data will not be used) and save the data until T(next) ~<= T(curr) + DT. if useFlag=false, State and Cov should NOT be used as they may be singular.
[in] | T | current time, on output time of NEXT set of data |
[in] | X | current state |
[in] | C | current covariance |
[in] | useFlag | if false, State and Cov are singular - do not use |
Implemented in gnsstk::WNJfilter.
|
pure virtual |
Pure virtual function, to be overloaded and provided by the caller, providing members PhiInv,G,Rw,Control, given T,DT,X,Cov at each timestep. if useFlag=false, State and Cov should NOT be used ... may be singular
[in] | T | current time |
[in] | DT | current timestep |
[in] | State | current state |
[in] | Cov | current covariance |
[in] | useFlag | if false, State and Cov are singular - do not use |
Implemented in gnsstk::WNJfilter.
|
inlinevirtual |
finalT | time at which to stop the filter |
DT | nominal timestep |
Definition at line 433 of file KalmanFilter.hpp.
|
inline |
get the covariance (must be non-singular)
Definition at line 952 of file KalmanFilter.hpp.
|
inline |
if doInversions, SRIF is inverted at each step, defining State and Cov
Definition at line 906 of file KalmanFilter.hpp.
|
inline |
if doOutput, output() is called at each step
Definition at line 910 of file KalmanFilter.hpp.
|
inline |
get the state namelist
Definition at line 948 of file KalmanFilter.hpp.
|
inline |
get number of measurements processed
Definition at line 955 of file KalmanFilter.hpp.
|
inline |
Definition at line 945 of file KalmanFilter.hpp.
|
inline |
get the state (must be non-singular)
Definition at line 950 of file KalmanFilter.hpp.
|
inline |
KF tag is a user-defined string output on each line.
Definition at line 937 of file KalmanFilter.hpp.
|
inlineprivate |
for internal use in constructors and by Reset. Create SRIF and initialize counters and stores
Definition at line 963 of file KalmanFilter.hpp.
|
inlinevirtual |
Definition at line 363 of file KalmanFilter.hpp.
|
inlineprivate |
For internal use to invert the SRIF to get State and Covariance
Definition at line 983 of file KalmanFilter.hpp.
|
inline |
Definition at line 934 of file KalmanFilter.hpp.
|
inline |
if extended, use an extended Kalman (not implemented)
Definition at line 914 of file KalmanFilter.hpp.
|
inline |
true when filter is singular
Definition at line 926 of file KalmanFilter.hpp.
|
inline |
Definition at line 919 of file KalmanFilter.hpp.
|
inline |
Definition at line 923 of file KalmanFilter.hpp.
|
inline |
Definition at line 930 of file KalmanFilter.hpp.
|
inlinevirtual |
Interim processing.
Definition at line 712 of file KalmanFilter.hpp.
|
inlinevirtual |
Perform the measurement update;
[in,out] | T | current time(input), time of NEXT data(output) |
Definition at line 739 of file KalmanFilter.hpp.
|
inlinevirtual |
the smoother update
Definition at line 846 of file KalmanFilter.hpp.
|
inlinevirtual |
the Kalman time update
[in] | T | current time |
[in] | DT | current timestep |
Definition at line 783 of file KalmanFilter.hpp.
|
inlinevirtual |
Output at each stage ... the user may override if singular is true, State and Cov may or may not be good
N | user-defined counter that is included on each line after the tag. |
Reimplemented in gnsstk::WNJfilter.
Definition at line 632 of file KalmanFilter.hpp.
|
inline |
Reset or recreate filter - use this after the empty constructor
NL | Namelist of the filter states (determines Nstate) |
Definition at line 354 of file KalmanFilter.hpp.
|
inline |
Definition at line 907 of file KalmanFilter.hpp.
|
inline |
Definition at line 911 of file KalmanFilter.hpp.
|
inline |
if dryRun, do not operate the filter, just print
Definition at line 933 of file KalmanFilter.hpp.
|
inline |
Definition at line 915 of file KalmanFilter.hpp.
|
inline |
if smoother, save info during forward filter for use by backward filter
Definition at line 918 of file KalmanFilter.hpp.
|
inline |
get the filter SRI
Definition at line 941 of file KalmanFilter.hpp.
|
inline |
if doSRISU use SRIF form of smoother, else DM smoother
Definition at line 922 of file KalmanFilter.hpp.
|
inline |
Definition at line 938 of file KalmanFilter.hpp.
|
inline |
if timeReversed, time T decreases during the forward filter
Definition at line 929 of file KalmanFilter.hpp.
|
protected |
Definition at line 217 of file KalmanFilter.hpp.
|
protected |
SRIF vector used internally.
Definition at line 232 of file KalmanFilter.hpp.
|
protected |
filter covariance
Definition at line 221 of file KalmanFilter.hpp.
|
protected |
vector defined by defineM() and used in MU
Definition at line 228 of file KalmanFilter.hpp.
|
protected |
if true, invert the SRIF to get State and Covariance whenever SRIF changes. In general it is wise to set this false, then reset to true only when the State is to be used. For example if you need the State Vector in the MU, then set doInversions=true in defineIntermin(1), then set to false in defineM. Inversions are called between all the define...() calls.
Definition at line 177 of file KalmanFilter.hpp.
|
protected |
if true, output at each stage using output() routine. NB used inside output()
Definition at line 168 of file KalmanFilter.hpp.
|
protected |
if true use the SRIF form of the smoother update in the backward filter
Definition at line 187 of file KalmanFilter.hpp.
|
protected |
if true, do a "dry run" calling all user-defined func, but none of the SRIF
Definition at line 206 of file KalmanFilter.hpp.
|
protected |
if true the filter is considered extended; this will zero the state before MU
Definition at line 192 of file KalmanFilter.hpp.
|
protected |
SRIF matrix used internally - noise.
Definition at line 235 of file KalmanFilter.hpp.
|
protected |
if true then the SRI has been inverted and State and Cov are valid
Definition at line 199 of file KalmanFilter.hpp.
|
protected |
optional tag to put in output (2nd field)
Definition at line 218 of file KalmanFilter.hpp.
|
protected |
measurement covariance (defineM() for MU)
Definition at line 229 of file KalmanFilter.hpp.
|
protected |
count of measurement updates
Definition at line 209 of file KalmanFilter.hpp.
|
protected |
Nnoise is there only for the user.
Definition at line 212 of file KalmanFilter.hpp.
|
protected |
change in time for one TU seconds
Definition at line 216 of file KalmanFilter.hpp.
|
protected |
number of state elements
Definition at line 211 of file KalmanFilter.hpp.
|
protected |
count of smoother updates
Definition at line 210 of file KalmanFilter.hpp.
|
protected |
count of time updates: ++ in TU, – in SU
Definition at line 208 of file KalmanFilter.hpp.
|
protected |
matrix defined by defineM() and used in MU
Definition at line 226 of file KalmanFilter.hpp.
|
protected |
post-fit residuals - valid after MU
Definition at line 224 of file KalmanFilter.hpp.
|
protected |
SRIF matrix used internally - inv state trans.
Definition at line 234 of file KalmanFilter.hpp.
|
protected |
SRIF matrix used internally.
Definition at line 236 of file KalmanFilter.hpp.
|
protected |
if true then the SRIF is currently singular (not a problem unless doInversions)
Definition at line 182 of file KalmanFilter.hpp.
|
protected |
condition number at last inversion = b/s
Definition at line 217 of file KalmanFilter.hpp.
|
protected |
if true the forward filter will save the data needed by the backward filter
Definition at line 197 of file KalmanFilter.hpp.
|
protected |
Definition at line 252 of file KalmanFilter.hpp.
|
protected |
post-smoother residuals - value after SU
Definition at line 239 of file KalmanFilter.hpp.
|
protected |
SRIF.
Definition at line 222 of file KalmanFilter.hpp.
|
protected |
current stage of the filter - see enum
Definition at line 214 of file KalmanFilter.hpp.
|
protected |
filter state
Definition at line 220 of file KalmanFilter.hpp.
|
protected |
seconds since start
Definition at line 215 of file KalmanFilter.hpp.
|
protected |
if true then independent variable "time" decreases
Definition at line 201 of file KalmanFilter.hpp.
|
protected |
SRIF vector used internally.
Definition at line 231 of file KalmanFilter.hpp.