Ginan
Loading...
Searching...
No Matches
KFState Struct Reference

Wrapper to simplify copying with default copy but overriding slightly. More...

Detailed Description

Wrapper to simplify copying with default copy but overriding slightly.

Inheritance diagram for KFState:
Collaboration diagram for KFState:

Public Member Functions

 KFState (const KFState &kfState)
 
 KFState ()
 
KFStateoperator= (const KFState &kfState)
 
template<class ARCHIVE >
void serialize (ARCHIVE &ar, const unsigned int &version)
 
void initFilterEpoch (Trace &trace)
 Clears and initialises the state transition matrix to identity at the beginning of an epoch.
 
int getKFIndex (const KFKey &key) const
 Finds the position in the KF state vector of particular states.
 
E_Source getKFValue (const KFKey &key, double &value, double *variance=nullptr, double *adjustment_ptr=nullptr, bool allowAlternate=true) const
 Returns the value and variance of a state within the kalman filter object.
 
E_Source getPseudoValue (const KFKey &key, double &value, double *variance=nullptr, double *adjustment_ptr=nullptr) const
 Retrieve values from pseudo-states.
 
bool getKFSigma (const KFKey &key, double &sigma)
 Returns the standard deviation of a state within the kalman filter object.
 
bool addKFState (const KFKey &kfKey, const InitialState &initialState={})
 Tries to add a state to the filter object.
 
bool addPseudoState (const KFKey &kfKey, const map< KFKey, double > &coeffMap)
 Create a pseudo state that represents the linear combination of two or more perfectly correlated states.
 
void setExponentialNoise (const KFKey &kfKey, const Exponential exponential)
 
void setAccelerator (const KFKey &element, const KFKey &dotElement, const KFKey &dotDotElement, const double value, const InitialState &initialState={})
 
void setKFTrans (const KFKey &dest, const KFKey &source, const double value, const InitialState &initialState={})
 Adds dynamics to a filter state by inserting off-diagonal, non-time dependent elements to transition matrix.
 
void setKFTransRate (const KFKey &integral, const KFKey &rate, const double value, const InitialState &initialRateState={}, const InitialState &initialIntegralState={})
 Adds dynamics to a filter state by inserting off-diagonal, time dependent elements to transition matrix.
 
void addNoiseElement (const KFKey &obsKey, const double variance)
 
void removeState (const KFKey &kfKey, bool allowDeleteParent=true)
 Remove a state from a kalman filter object.
 
void stateTransition (Trace &trace, GTime newTime, MatrixXd *stm_ptr=nullptr)
 Add process noise and dynamics to filter object according to time gap.
 
void manualStateTransition (Trace &trace, GTime newTime, MatrixXd &stm, MatrixXd &procNoise)
 Add process noise and dynamics to filter object manually.
 
void preFitSigmaCheck (RejectCallbackDetails &callbackDetails, KFStatistics &statistics, int begX, int numX, int begH, int numH)
 Compare variances of measurements and pre-filtered states to detect unreasonable values Ref: Wang et al.
 
void postFitSigmaChecks (RejectCallbackDetails &callbackDetails, VectorXd &dx, KFStatistics &statistics, int begX, int numX, int begH, int numH)
 Compare variances of measurements and filtered states to detect unreasonable values.
 
double stateChiSquare (Trace &trace, MatrixXd &Pp, VectorXd &dx, int begX, int numX, int begH, int numH)
 Compute Chi-square increment based on the change of fitting solution.
 
double measChiSquare (Trace &trace, KFMeas &kfMeas, VectorXd &dx, int begX, int numX, int begH, int numH)
 Compute Chi-square increment based on post-fit residuals.
 
double innovChiSquare (Trace &trace, KFMeas &kfMeas, int begX, int numX, int begH, int numH)
 Compute Chi-square increment based on pre-fit residuals (innovations)
 
bool kFilter (Trace &trace, KFMeas &kfMeas, VectorXd &xp, MatrixXd &Pp, VectorXd &dx, int begX=0, int numX=-1, int begH=0, int numH=-1)
 Kalman filter.
 
bool chiQC (Trace &trace, KFMeas &kfMeas, VectorXd &xp)
 Perform chi squared quality control.
 
void outputStates (Trace &trace, string suffix="", int begX=0, int numX=-1)
 Output keys and states in human readable format.
 
void outputConditionNumber (Trace &trace)
 
void outputCorrelations (Trace &trace)
 
void outputMeasurements (Trace &trace, KFMeas &meas)
 
bool doStateRejectCallbacks (RejectCallbackDetails rejectDetails)
 
bool doMeasRejectCallbacks (RejectCallbackDetails rejectDetails)
 
void filterKalman (Trace &trace, KFMeas &kfMeas, const string &suffix="", bool innovReady=false, map< string, FilterChunk > *filterChunkMap_ptr=nullptr)
 Kalman filter operation.
 
void leastSquareInitStates (Trace &trace, KFMeas &kfMeas, bool initCovars=false, VectorXd *dx=nullptr, bool innovReady=false)
 Least squares estimator for new kalman filter states.
 
VectorXd getSubState (map< KFKey, int > &kfKeyMap, MatrixXd *covarMat_ptr=nullptr, VectorXd *adjustVec_ptr=nullptr) const
 Get a portion of the state vector by passing a list of keys.
 
void getSubState (map< KFKey, int > &kfKeyMap, KFState &kfState) const
 Get a portion of a state by passing in a list of keys.
 
KFState getSubState (vector< KF >) const
 
vector< KFKeydecomposedStateKeys (const KFKey &composedKey) const
 

Data Fields

recursive_mutex kfStateMutex
 
- Data Fields inherited from KFState_
bool lsqRequired = false
 Uninitialised parameters require least squares calculation.
 
GTime time = {}
 
VectorXd x
 State.
 
MatrixXd P
 State Covariance.
 
VectorXd dx
 Last filter update.
 
map< KFKey, intkfIndexMap
 Map from key to indexes of parameters in the state vector.
 
map< KFKey, map< KFKey, map< int, double > > > stateTransitionMap
 
map< KFKey, double > gaussMarkovTauMap
 
map< KFKey, double > gaussMarkovMuMap
 
map< KFKey, double > procNoiseMap
 
map< KFKey, double > initNoiseMap
 
map< KFKey, double > sigmaMaxMap
 
map< KFKey, double > outageLimitMap
 
map< KFKey, ExponentialexponentialNoiseMap
 
map< KFKey, map< KFKey, double > > pseudoStateMap
 Map of pseudo states, and a further map of their coefficients.
 
map< KFKey, KFKeypseudoParentMap
 Map from ordinary states to their combined pseudo state parent.
 
vector< StateRejectCallbackstateRejectCallbacks
 
vector< MeasRejectCallbackmeasRejectCallbacks
 
map< string, FilterChunkfilterChunkMap
 
map< string, string > metaDataMap
 
bool chiQCPass = false
 
double chi = 0
 
int dof = 0
 
string id = "KFState"
 
string rts_basename = ""
 
bool output_residuals = false
 
bool outputMongoMeasurements = false
 
KFStatealternate_ptr = nullptr
 
map< string, intstatisticsMap
 
map< string, intstatisticsMapSum
 
- Data Fields inherited from FilterOptions
bool simulate_filter_only = false
 
bool assume_linearity = false
 
bool advanced_postfits = false
 
bool joseph_stabilisation = false
 
E_Inverter inverter = E_Inverter::LDLT
 
PrefitOptions prefitOpts
 
PostfitOptions postfitOpts
 
ChiSquareOptions chiSquareTest
 
- Data Fields inherited from RtsOptions
string rts_filename = "<RTS_DIRECTORY>/Filter-<RECEIVER>.rts"
 
string rts_directory = "./"
 
int rts_lag = -1
 
int rts_interval = 0
 
string rts_smoothed_suffix = "_smoothed"
 
bool queue_rts_outputs = false
 
E_Inverter rts_inverter = E_Inverter::LDLT
 

Static Public Attributes

static const KFKey oneKey = {.type = KF::ONE}
 KFStates generally contain a ONE state as the first element, used for converting matrix additions to matrix multiplications.
 

Constructor & Destructor Documentation

◆ KFState() [1/2]

KFState::KFState ( const KFState & kfState)
inline

◆ KFState() [2/2]

KFState::KFState ( )
inline
Here is the call graph for this function:

Member Function Documentation

◆ addKFState()

bool KFState::addKFState ( const KFKey & kfKey,
const InitialState & initialState = {} )

Tries to add a state to the filter object.

If it does not exist, it adds it to a list of states to be added. Call consolidateKFState() to apply the list to the filter object

Parameters
kfKeyThe key to add to the state
initialStateThe initial conditions to add to the state
Here is the caller graph for this function:

◆ addNoiseElement()

void KFState::addNoiseElement ( const KFKey & obsKey,
const double variance )

◆ addPseudoState()

bool KFState::addPseudoState ( const KFKey & kfKey,
const map< KFKey, double > & coeffMap )

Create a pseudo state that represents the linear combination of two or more perfectly correlated states.

The configuration of the states that are combined are added according to the coefficients of correlation, which may not be appropriate for things like process noise or max sigmas, and should be configured accordingly.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chiQC()

bool KFState::chiQC ( Trace & trace,
KFMeas & kfMeas,
VectorXd & xp )

Perform chi squared quality control.

Parameters
traceTrace to output to
kfMeasMeasurements, noise, and design matrix
xpPost filtered state vector
Here is the caller graph for this function:

◆ decomposedStateKeys()

vector< KFKey > KFState::decomposedStateKeys ( const KFKey & composedKey) const
Here is the caller graph for this function:

◆ doMeasRejectCallbacks()

bool KFState::doMeasRejectCallbacks ( RejectCallbackDetails rejectDetails)
Here is the caller graph for this function:

◆ doStateRejectCallbacks()

bool KFState::doStateRejectCallbacks ( RejectCallbackDetails rejectDetails)
Here is the caller graph for this function:

◆ filterKalman()

void KFState::filterKalman ( Trace & trace,
KFMeas & kfMeas,
const string & suffix = "",
bool innovReady = false,
map< string, FilterChunk > * filterChunkMap_ptr = nullptr )

Kalman filter operation.

Parameters
traceTrace file for output
kfMeasMeasurement object
suffixSuffix to append to residuals block
innovReadyInnovation already constructed
filterChunkMap_ptrOptional map of chunks for parallel processing of sub filters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getKFIndex()

int KFState::getKFIndex ( const KFKey & key) const

Finds the position in the KF state vector of particular states.

Parameters
keyKey to search for in state
Here is the caller graph for this function:

◆ getKFSigma()

bool KFState::getKFSigma ( const KFKey & key,
double & sigma )

Returns the standard deviation of a state within the kalman filter object.

Parameters
keyKey to search for in state
sigmaOutput value
Here is the caller graph for this function:

◆ getKFValue()

E_Source KFState::getKFValue ( const KFKey & key,
double & value,
double * variance_ptr = nullptr,
double * adjustment_ptr = nullptr,
bool allowAlternate = true ) const

Returns the value and variance of a state within the kalman filter object.

Parameters
keyKey to search for in state
valueOutput value
variance_ptrOptional variance output
adjustment_ptrOptional adjustment output
allowAlternateOptional flag to disable alternate filter
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPseudoValue()

E_Source KFState::getPseudoValue ( const KFKey & key,
double & value,
double * variance_ptr = nullptr,
double * adjustment_ptr = nullptr ) const

Retrieve values from pseudo-states.

Pseudo states are linear combinations of correlated states, and this function returns the value of the states assuming that the correlations from the point of creation are still valid. It returns the entirety of the state component for the primary state, with others returning 0. Later linear combinations of these should return the correct value for the combined state.

Parameters
keyKey to search for in state
valueOutput value
variance_ptrOptional variance output
adjustment_ptrOptional adjustment output
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubState() [1/3]

void KFState::getSubState ( map< KFKey, int > & kfKeyMap,
KFState & subState ) const

Get a portion of a state by passing in a list of keys.

Only gets some aspects, as most aren't required

Parameters
kfKeyMapList of keys to return within substate
subStateOutput state
Here is the call graph for this function:

◆ getSubState() [2/3]

VectorXd KFState::getSubState ( map< KFKey, int > & kfKeyMap,
MatrixXd * covarMat_ptr = nullptr,
VectorXd * adjustVec_ptr = nullptr ) const

Get a portion of the state vector by passing a list of keys.

Parameters
kfKeyMapList of keys to return within substate
covarMat_ptrOptional pointer to a matrix for output of covariance submatrix
adjustVec_ptrOptional pointer to a vector for output of last adjustments
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubState() [3/3]

KFState KFState::getSubState ( vector< KF > types) const

◆ initFilterEpoch()

void KFState::initFilterEpoch ( Trace & trace)

Clears and initialises the state transition matrix to identity at the beginning of an epoch.

Also clears any noise that was being added for the initialisation of a new state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ innovChiSquare()

double KFState::innovChiSquare ( Trace & trace,
KFMeas & kfMeas,
int begX,
int numX,
int begH,
int numH )

Compute Chi-square increment based on pre-fit residuals (innovations)

Parameters
traceTrace to output to
kfMeasMeasurements, noise, and design matrix
begXIndex of first state element to process
numXNumber of states elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ kFilter()

bool KFState::kFilter ( Trace & trace,
KFMeas & kfMeas,
VectorXd & xp,
MatrixXd & Pp,
VectorXd & dx,
int begX = 0,
int numX = -1,
int begH = 0,
int numH = -1 )

Kalman filter.

Parameters
traceTrace to output to
kfMeasMeasurements, noise, and design matrices
xpPost-update state vector
PpPost-update covariance of states
dxPost-update state innovation
begXIndex of first state element to process
numXNumber of state elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ leastSquareInitStates()

void KFState::leastSquareInitStates ( Trace & trace,
KFMeas & kfMeas,
bool initCovars = false,
VectorXd * dx = nullptr,
bool innovReady = false )

Least squares estimator for new kalman filter states.

If new states have been added that do not contain variance values, the filter will assume that these states values and covariances should be estimated using least squares.

This function will extract the minimum required states from the existing state vector, and the minimum required measurements in order to perform least squares for the uninitialised states.

Parameters
traceTrace file for output
kfMeasMeasurement object
initCovarsOption to also initialise off-diagonal covariance values
dxOptional output of state deltas
innovReadyPerform conversion between V & Y
Here is the call graph for this function:
Here is the caller graph for this function:

◆ manualStateTransition()

void KFState::manualStateTransition ( Trace & trace,
GTime newTime,
MatrixXd & F,
MatrixXd & Q0 )

Add process noise and dynamics to filter object manually.

BEWARE! Not recommended for ordinary use, likely to break things. Dont touch unless you really know what you're doing. Hint - you dont really know what you're doing

Here is the call graph for this function:

◆ measChiSquare()

double KFState::measChiSquare ( Trace & trace,
KFMeas & kfMeas,
VectorXd & dx,
int begX,
int numX,
int begH,
int numH )

Compute Chi-square increment based on post-fit residuals.

Parameters
traceTrace file to output to
kfMeasMeasurements, noise, and design matrix
dxThe innovations from filtering to recalculate the deltas.
begXIndex of first state element to process
numXNumber of states elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ operator=()

KFState & KFState::operator= ( const KFState & kfState)
inline

◆ outputConditionNumber()

void KFState::outputConditionNumber ( Trace & trace)

◆ outputCorrelations()

void KFState::outputCorrelations ( Trace & trace)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ outputMeasurements()

void KFState::outputMeasurements ( Trace & trace,
KFMeas & meas )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ outputStates()

void KFState::outputStates ( Trace & output,
string suffix = "",
int begX = 0,
int numX = -1 )

Output keys and states in human readable format.

Parameters
outputTrace to output to
suffixSuffix to append to state block info tag in trace files
begXIndex of first state element to process
numXNumber of state elements to process
Here is the call graph for this function:
Here is the caller graph for this function:

◆ postFitSigmaChecks()

void KFState::postFitSigmaChecks ( RejectCallbackDetails & callbackDetails,
VectorXd & dx,
KFStatistics & statistics,
int begX,
int numX,
int begH,
int numH )

Compare variances of measurements and filtered states to detect unreasonable values.

Parameters
dxThe innovations from filtering to recalculate the deltas.
statisticsTest statistics
begXIndex of first state element to process
numXNumber of state elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ preFitSigmaCheck()

void KFState::preFitSigmaCheck ( RejectCallbackDetails & callbackDetails,
KFStatistics & statistics,
int begX,
int numX,
int begH,
int numH )

Compare variances of measurements and pre-filtered states to detect unreasonable values Ref: Wang et al.

(1997) - On Quality Control in Hydrographic GPS Surveying & Wieser et al. (2004) - Failure Scenarios to be Considered with Kinematic High Precision Relative GNSS Positioning - http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.573.9628&rep=rep1&type=pdf

Parameters
statisticsTest statistics
begXIndex of first state element to process
numXNumber of states elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ removeState()

void KFState::removeState ( const KFKey & kfKey,
bool allowDeleteParent = true )

Remove a state from a kalman filter object.

Parameters
kfKeyKey to search for in state
Here is the caller graph for this function:

◆ serialize()

template<class ARCHIVE >
void KFState::serialize ( ARCHIVE & ar,
const unsigned int & version )
inline

◆ setAccelerator()

void KFState::setAccelerator ( const KFKey & element,
const KFKey & dotElement,
const KFKey & dotDotElement,
const double value,
const InitialState & initialState = {} )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setExponentialNoise()

void KFState::setExponentialNoise ( const KFKey & kfKey,
const Exponential exponential )
Here is the caller graph for this function:

◆ setKFTrans()

void KFState::setKFTrans ( const KFKey & dest,
const KFKey & source,
const double value,
const InitialState & initialState = {} )

Adds dynamics to a filter state by inserting off-diagonal, non-time dependent elements to transition matrix.

Parameters
destKey to search for in state to change in transition
sourceKey to search for in state as source
valueInput value
initialStateInitial state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setKFTransRate()

void KFState::setKFTransRate ( const KFKey & integralKey,
const KFKey & rateKey,
const double value,
const InitialState & initialRateState = {},
const InitialState & initialIntegralState = {} )

Adds dynamics to a filter state by inserting off-diagonal, time dependent elements to transition matrix.

Parameters
integralKeyKey to search for in state to change in transition
rateKeyKey to search for in state as source
valueInput value
initialRateStateInitial state for rate state.
initialIntegralStateInitial state for the thing that is modified by the rate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stateChiSquare()

double KFState::stateChiSquare ( Trace & trace,
MatrixXd & Pp,
VectorXd & dx,
int begX,
int numX,
int begH,
int numH )

Compute Chi-square increment based on the change of fitting solution.

Parameters
traceTrace file to output to
PpPost-update covariance of states
dxThe innovations from filtering to recalculate the deltas.
begXIndex of first state element to process
numXNumber of states elements to process
begHIndex of first measurement to process
numHNumber of measurements to process
Here is the caller graph for this function:

◆ stateTransition()

void KFState::stateTransition ( Trace & trace,
GTime newTime,
MatrixXd * stm_ptr = nullptr )

Add process noise and dynamics to filter object according to time gap.

This will also sort states according to their kfKey as a result of the way the state transition matrix is generated.

Parameters
traceTrace file for output
newTimeTime of update for process noise and dynamics (s)
stm_ptrOptional pointer to output state transition matrix
Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ kfStateMutex

recursive_mutex KFState::kfStateMutex

◆ oneKey

const KFKey KFState::oneKey = {.type = KF::ONE}
static

KFStates generally contain a ONE state as the first element, used for converting matrix additions to matrix multiplications.


The documentation for this struct was generated from the following files: