Coverage for src/gncpy/filters/bayes_filter.py: 85%

26 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-19 05:48 +0000

1import abc 

2 

3 

4class BayesFilter(metaclass=abc.ABCMeta): 

5 """Generic base class for Bayesian Filters such as a Kalman Filter. 

6 

7 This defines the required functions and provides their recommended function 

8 signature for inherited classes. 

9 

10 Attributes 

11 ---------- 

12 use_cholesky_inverse : bool 

13 Flag indicating if a cholesky decomposition should be performed before 

14 taking the inverse. This can improve numerical stability but may also 

15 increase runtime. The default is True. 

16 """ 

17 

18 def __init__(self, use_cholesky_inverse=True, **kwargs): 

19 self.use_cholesky_inverse = use_cholesky_inverse 

20 self._cpp_needs_init = 0 

21 

22 super().__init__() 

23 

24 @abc.abstractmethod 

25 def predict(self, timestep, *args, **kwargs): 

26 """Generic method for the filters prediction step. 

27 

28 This must be overridden in the inherited class. It is recommended to 

29 keep the same structure/order for the arguments to allow for 

30 standardized implementation of wrapper code. 

31 """ 

32 pass 

33 

34 @abc.abstractmethod 

35 def correct(self, timestep, meas, *args, **kwargs): 

36 """Generic method for the filters correction step. 

37 

38 This must be overridden in the inherited class. It is recommended to 

39 keep the same structure/order for the arguments to allow for 

40 standardized implementation of wrapper code. 

41 """ 

42 pass 

43 

44 @abc.abstractmethod 

45 def set_state_model(self, **kwargs): 

46 """Generic method for tsetting the state model. 

47 

48 This must be overridden in the inherited class. The signature for this 

49 is arbitrary. 

50 """ 

51 pass 

52 

53 @abc.abstractmethod 

54 def set_measurement_model(self, **kwargs): 

55 """Generic method for setting the measurement model. 

56 

57 This must be overridden in the inherited class. The signature for this 

58 is arbitrary. 

59 """ 

60 pass 

61 

62 @abc.abstractmethod 

63 def save_filter_state(self): 

64 """Generic method for saving key filter variables. 

65 

66 This must be overridden in the inherited class. It is recommended to keep 

67 the signature the same to allow for standardized implemenation of 

68 wrapper classes. This should return a single variable that can be passed 

69 to the loading function to setup a filter to the same internal state 

70 as the current instance when this function was called. 

71 """ 

72 filt_state = {} 

73 filt_state["use_cholesky_inverse"] = self.use_cholesky_inverse 

74 

75 return filt_state 

76 

77 @abc.abstractmethod 

78 def load_filter_state(self, filt_state): 

79 """Generic method for saving key filter variables. 

80 

81 This must be overridden in the inherited class. It is recommended to keep 

82 the signature the same to allow for standardized implemenation of 

83 wrapper classes. This initialize all internal variables saved by the 

84 filter save function such that a new instance would generate the same 

85 output as the original instance that called the save function. 

86 """ 

87 self.use_cholesky_inverse = filt_state["use_cholesky_inverse"]