JayBeams  0.1
Another project to have fun coding.
tde_result.hpp
Go to the documentation of this file.
1 #ifndef jb_fftw_tde_result_hpp
2 #define jb_fftw_tde_result_hpp
3 
6 
7 namespace jb {
8 namespace fftw {
9 
10 /**
11  * A time-delay estimator (TDE) is an algorithm to compare
12  * two families of timeseries and return the estimated delay
13  * of the first family vs. the second family.
14  * When the families of timeseries are represented by an array
15  * of dimension K, the last dimension is interpreted as time,
16  * and the remaining K-1 dimensions are interpreted as the
17  * family parameters.
18  * In that case, the output of a TDE is an array of one dimension
19  * less than the inputs to the TDE algorithm.
20  *
21  * In contrast, when the input into the TDE algorithm is a simple
22  * vector, or a one dimensional array then the output is a simple value.
23  *
24  * This template class, and its specializations, compute the representation for
25  * the TDE result given the input type. Because the TDE algorithms usually have
26  * two outputs (the time delay estimate, usually represented by an integer,
27  * and the confidence, usually a floating point type), the class is parametric
28  * on the output type. This parametrization allows us to use this type in other
29  * timeseries computations that return a (1) value out of operating on the last
30  * dimension (e.g. sum sqr, average).
31  *
32  * @tparam container_t the representation for a timeseries, expected to be
33  * a one-dimensional container such as std::vector<> or std::deque<>
34  * @tparam value_t type to store the result of the timeseries operation
35  */
36 template <typename container_t, typename value_t>
37 class tde_result {
38 public:
39  using value_type = value_t;
41  explicit tde_result(container_t const& a)
42  : value_{0} {
43  }
44 
45  /// tde_result holds only one value, we overload the subscription operator
46  /// to allow generic usage of the type.
47  value_type& operator[](std::size_t pos) {
48  return value_;
49  }
50 
51  /// tde_result value held by a const object.
52  /// tde_result holds only one value, we overload the subscription operator
53  /// to allow generic usage of the type.
54  value_type const& operator[](std::size_t pos) const {
55  return value_;
56  }
57 
58  /// size of tde_result record_type, holds only one value
59  std::size_t size() const {
60  return 1;
61  }
62 
63 private:
65 };
66 
67 /**
68  * Handles TDE result for a multi array type timeseries.
69  *
70  * @tparam T type of the value stored on the timeseries
71  * @tparam K timeseries dimensionality
72  * @tparam A an Allocator type for type T allocator storage
73  * @tparam value_t type to store the result of the timeseries computation
74  */
75 template <typename T, std::size_t K, typename A, typename value_t>
76 class tde_result<boost::multi_array<T, K, A>, value_t> {
77 public:
78  using value_type = value_t;
79  using array_type = boost::multi_array<T, K, A>;
80  // multi array to store the result of the timeseries computation
82 
83  /// constructor based on a multi_array of dimensionality K
84  /// the last dimension is ignored
85  /// size is reduced by the elements of the last dimension (nsamples)
86  explicit tde_result(array_type const& a)
87  : record_{jb::detail::array_shape(a)} {
88  }
89 
90  /// tde_result holds a multi array, we overload the subscription operator
91  /// to allow generic usage of the type.
92  value_type& operator[](std::size_t pos) {
93  return record_.data()[pos];
94  }
95 
96  /// tde_result value held by a const object.
97  /// tde_result holds a multi array, we overload the subscription operator
98  /// to allow generic usage of the type.
99  value_type const& operator[](std::size_t pos) const {
100  return record_.data()[pos];
101  }
102 
103  /// size is number of elements stored on the multi array record_
104  std::size_t size() const {
105  return jb::detail::element_count(record_);
106  }
107 
108 private:
110 };
111 
112 /**
113  * Handles TDE result for a multi array type timeseries with
114  * dimensionality 1.
115  *
116  * @tparam T type of the value stored on the timeseries
117  * @tparam A an Allocator type for type T allocator storage
118  * @tparam value_t type to store the result of the timeseries operation
119  */
120 template <typename T, typename A, typename value_t>
121 class tde_result<boost::multi_array<T, 1, A>, value_t> {
122 public:
123  using value_type = value_t;
125  // result of the operation is one (1) value
127 
128  /// constructor based on a array_type of dimensionaltity 1
129  explicit tde_result(array_type const& a)
130  : value_{0} {
131  }
132 
133  /// tde_result holds only one value, we overload the subscription operator
134  /// to allow generic usage of the type.
135  value_type& operator[](std::size_t pos) {
136  return value_;
137  }
138 
139  /// tde_result value held by a const object.
140  /// tde_result holds only one value, we overload the subscription operator
141  /// to allow generic usage of the type.
142  value_type const& operator[](std::size_t pos) const {
143  return value_;
144  }
145 
146  /// size of tde_result record_type, holds only one value
147  std::size_t size() const {
148  return 1;
149  }
150 
151 private:
153 };
154 
155 } // namespace fftw
156 } // namespace jb
157 
158 #endif // jb_fftw_tde_result_hpp
record_type value_
Definition: tde_result.hpp:64
std::size_t size() const
size of tde_result record_type, holds only one value
Definition: tde_result.hpp:59
value_type & operator[](std::size_t pos)
tde_result holds only one value, we overload the subscription operator to allow generic usage of the ...
Definition: tde_result.hpp:135
value_type const & operator[](std::size_t pos) const
tde_result value held by a const object.
Definition: tde_result.hpp:142
tde_result(container_t const &a)
Definition: tde_result.hpp:41
value_type const & operator[](std::size_t pos) const
tde_result value held by a const object.
Definition: tde_result.hpp:99
value_type & operator[](std::size_t pos)
tde_result holds a multi array, we overload the subscription operator to allow generic usage of the t...
Definition: tde_result.hpp:92
tde_result(array_type const &a)
constructor based on a array_type of dimensionaltity 1
Definition: tde_result.hpp:129
value_type & operator[](std::size_t pos)
tde_result holds only one value, we overload the subscription operator to allow generic usage of the ...
Definition: tde_result.hpp:47
std::size_t size() const
size of tde_result record_type, holds only one value
Definition: tde_result.hpp:147
A time-delay estimator (TDE) is an algorithm to compare two families of timeseries and return the est...
Definition: tde_result.hpp:37
boost::multi_array< value_type, num_dims, jb::fftw::allocator< value_type > > aligned_multi_array
Alias boost::multi_array with properly allocated storage for FFTW3.
std::size_t array_shape(container_type const &a)
Return the shape of the container in a form suitable for construction of a vector-like container...
value_type const & operator[](std::size_t pos) const
tde_result value held by a const object.
Definition: tde_result.hpp:54
jb::fftw::aligned_multi_array< value_type, K - 1 > record_type
Definition: tde_result.hpp:81
std::size_t size() const
size is number of elements stored on the multi array record_
Definition: tde_result.hpp:104
std::size_t element_count(container_type const &a)
Count the number of elements for a vector-like container.
tde_result(array_type const &a)
constructor based on a multi_array of dimensionality K the last dimension is ignored size is reduced ...
Definition: tde_result.hpp:86
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7
value_type record_type
Definition: tde_result.hpp:40