1 | // Copyright (C) 2009-2013 Conrad Sanderson |
---|
2 | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) |
---|
3 | // |
---|
4 | // This Source Code Form is subject to the terms of the Mozilla Public |
---|
5 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
---|
6 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
---|
7 | |
---|
8 | |
---|
9 | //! \addtogroup running_stat_vec |
---|
10 | //! @{ |
---|
11 | |
---|
12 | |
---|
13 | template<typename obj_type, bool> struct rsv_get_elem_type { }; |
---|
14 | template<typename obj_type> struct rsv_get_elem_type<obj_type, false> { typedef obj_type elem_type; }; |
---|
15 | template<typename obj_type> struct rsv_get_elem_type<obj_type, true> { typedef typename obj_type::elem_type elem_type; }; |
---|
16 | |
---|
17 | |
---|
18 | //! Class for keeping statistics of a continuously sampled process / signal. |
---|
19 | //! Useful if the storage of individual samples is not necessary or desired. |
---|
20 | //! Also useful if the number of samples is not known beforehand or exceeds |
---|
21 | //! available memory. |
---|
22 | template<typename obj_type> |
---|
23 | class running_stat_vec |
---|
24 | { |
---|
25 | public: |
---|
26 | |
---|
27 | // voodoo for compatibility with old user code |
---|
28 | typedef typename rsv_get_elem_type<obj_type, is_Mat<obj_type>::value>::elem_type eT; |
---|
29 | |
---|
30 | typedef typename get_pod_type<eT>::result T; |
---|
31 | |
---|
32 | inline ~running_stat_vec(); |
---|
33 | inline running_stat_vec(const bool in_calc_cov = false); // TODO: investigate char* overload, eg. "calc_cov", "no_calc_cov" |
---|
34 | |
---|
35 | inline running_stat_vec(const running_stat_vec& in_rsv); |
---|
36 | |
---|
37 | inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); |
---|
38 | |
---|
39 | template<typename T1> arma_hot inline void operator() (const Base< T, T1>& X); |
---|
40 | template<typename T1> arma_hot inline void operator() (const Base<std::complex<T>, T1>& X); |
---|
41 | |
---|
42 | inline void reset(); |
---|
43 | |
---|
44 | inline const Mat<eT>& mean() const; |
---|
45 | |
---|
46 | inline const Mat< T>& var (const uword norm_type = 0); |
---|
47 | inline Mat< T> stddev(const uword norm_type = 0) const; |
---|
48 | inline const Mat<eT>& cov (const uword norm_type = 0); |
---|
49 | |
---|
50 | inline const Mat<eT>& min() const; |
---|
51 | inline const Mat<eT>& max() const; |
---|
52 | |
---|
53 | inline T count() const; |
---|
54 | |
---|
55 | // |
---|
56 | // |
---|
57 | |
---|
58 | private: |
---|
59 | |
---|
60 | const bool calc_cov; |
---|
61 | |
---|
62 | arma_aligned arma_counter<T> counter; |
---|
63 | |
---|
64 | arma_aligned Mat<eT> r_mean; |
---|
65 | arma_aligned Mat< T> r_var; |
---|
66 | arma_aligned Mat<eT> r_cov; |
---|
67 | |
---|
68 | arma_aligned Mat<eT> min_val; |
---|
69 | arma_aligned Mat<eT> max_val; |
---|
70 | |
---|
71 | arma_aligned Mat< T> min_val_norm; |
---|
72 | arma_aligned Mat< T> max_val_norm; |
---|
73 | |
---|
74 | arma_aligned Mat< T> r_var_dummy; |
---|
75 | arma_aligned Mat<eT> r_cov_dummy; |
---|
76 | |
---|
77 | arma_aligned Mat<eT> tmp1; |
---|
78 | arma_aligned Mat<eT> tmp2; |
---|
79 | |
---|
80 | friend class running_stat_vec_aux; |
---|
81 | }; |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | class running_stat_vec_aux |
---|
86 | { |
---|
87 | public: |
---|
88 | |
---|
89 | template<typename obj_type> |
---|
90 | inline static void |
---|
91 | update_stats |
---|
92 | ( |
---|
93 | running_stat_vec<obj_type>& x, |
---|
94 | const Mat<typename running_stat_vec<obj_type>::eT>& sample, |
---|
95 | const typename arma_not_cx<typename running_stat_vec<obj_type>::eT>::result* junk = 0 |
---|
96 | ); |
---|
97 | |
---|
98 | template<typename obj_type> |
---|
99 | inline static void |
---|
100 | update_stats |
---|
101 | ( |
---|
102 | running_stat_vec<obj_type>& x, |
---|
103 | const Mat<std::complex< typename running_stat_vec<obj_type>::T > >& sample, |
---|
104 | const typename arma_not_cx<typename running_stat_vec<obj_type>::eT>::result* junk = 0 |
---|
105 | ); |
---|
106 | |
---|
107 | template<typename obj_type> |
---|
108 | inline static void |
---|
109 | update_stats |
---|
110 | ( |
---|
111 | running_stat_vec<obj_type>& x, |
---|
112 | const Mat< typename running_stat_vec<obj_type>::T >& sample, |
---|
113 | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::result* junk = 0 |
---|
114 | ); |
---|
115 | |
---|
116 | template<typename obj_type> |
---|
117 | inline static void |
---|
118 | update_stats |
---|
119 | ( |
---|
120 | running_stat_vec<obj_type>& x, |
---|
121 | const Mat<typename running_stat_vec<obj_type>::eT>& sample, |
---|
122 | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::result* junk = 0 |
---|
123 | ); |
---|
124 | }; |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | //! @} |
---|