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

Wrapper to protect main KFState_ structure from multithreading issues. More...

Detailed Description

Wrapper to protect main KFState_ structure from multithreading issues.

The main purpose of this structure is to allow the use of the const attribute, signifying whether the object is safe to be modified without multithreading locks.

When a KFState is passed to multithreading code, it should be passed as a const reference, preventing ordinary modification of its members, which are likely to collide during parallel calculations.

Wrapper functions cast the object so it is as-if it were const and then call the ordinary functions after obtaining the object's mutex

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 ()
 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.
 
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.
 
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)
 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 (Trace &trace, KFMeas &kfMeas, KFKey &badStateKey, int &badMeasIndex, 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 (Trace &trace, KFMeas &kfMeas, VectorXd &dx, int iteration, KFKey &badStateKey, int &badMeasIndex, 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 (Trace &trace, KFMeas &kfMeas, KFKey &badKey, bool postFit)
 
bool doMeasRejectCallbacks (Trace &trace, KFMeas &kfMeas, int badIndex, bool postFit)
 
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
 
void removeState (const KFKey &kfKey) const
 
void setExponentialNoise (const KFKey &kfKey, const Exponential exponential) const
 
bool addKFState (const KFKey &kfKey, const InitialState &initialState={}) const
 
void setKFTrans (const KFKey &dest, const KFKey &source, const double value, const InitialState &initialState={}) const
 
void setKFTransRate (const KFKey &integral, const KFKey &rate, const double value, const InitialState &initialRateState={}, const InitialState &initialIntegralState={}) const
 

Data Fields

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, ExponentialexponentialNoiseMap
 
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 = "Filter-<CONFIG>-<RECEIVER>.rts"
 
string rts_directory = "<OUTPUTS_ROOT>"
 
int rts_lag = -1
 
int rts_interval = 0
 
string rts_smoothed_suffix = "_smoothed"
 
bool output_intermediate_rts = false
 
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() [1/2]

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:

◆ addKFState() [2/2]

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

◆ addNoiseElement()

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

◆ 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:

◆ doMeasRejectCallbacks()

bool KFState::doMeasRejectCallbacks ( Trace & trace,
KFMeas & kfMeas,
int badIndex,
bool postFit )
Parameters
traceTrace file for output
kfMeasMeasurements that were passed to the filter
badIndexIndex in measurement list that was unsatisfactory
postFitRejection occured during post-filtering checks
Here is the caller graph for this function:

◆ doStateRejectCallbacks()

bool KFState::doStateRejectCallbacks ( Trace & trace,
KFMeas & kfMeas,
KFKey & badKey,
bool postFit )
Parameters
traceTrace file for output
kfMeasMeasurements that were passed to the filter
badKeyKey in state that was unsatisfactory
postFitRejection occured during post-filtering checks
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:

◆ 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 ( )

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 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:
Here is the caller 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 ( Trace & trace,
KFMeas & kfMeas,
VectorXd & dx,
int iteration,
KFKey & badStateKey,
int & badMeasIndex,
KFStatistics & statistics,
int begX,
int numX,
int begH,
int numH )

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

Parameters
traceTrace file to output to
kfMeasMeasurements, noise, and design matrix
dxThe innovations from filtering to recalculate the deltas.
iterationNumber of iterations prior to this check
badStateKeyKey to the state that has worst ratio (only if worse than badMeasIndex)
badMeasIndexIndex of the measurement that has the worst ratio
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 ( Trace & trace,
KFMeas & kfMeas,
KFKey & badStateKey,
int & badMeasIndex,
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
traceTrace to output to
kfMeasMeasurements, noise, and design matrix
badStateKeyKey to the state that has worst ratio (only if worse than badMeasIndex)
badMeasIndexIndex of the measurement that has the worst ratio
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() [1/2]

void KFState::removeState ( const KFKey & kfKey)

Remove a state from a kalman filter object.

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

◆ removeState() [2/2]

void KFState::removeState ( const KFKey & kfKey) const
inline

◆ 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() [1/2]

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

◆ setExponentialNoise() [2/2]

void KFState::setExponentialNoise ( const KFKey & kfKey,
const Exponential exponential ) const
inline

◆ setKFTrans() [1/2]

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:

◆ setKFTrans() [2/2]

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

◆ setKFTransRate() [1/2]

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:

◆ setKFTransRate() [2/2]

void KFState::setKFTransRate ( const KFKey & integral,
const KFKey & rate,
const double value,
const InitialState & initialRateState = {},
const InitialState & initialIntegralState = {} ) const
inline

◆ 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

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: