Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
sophisticated_chunking::WaveletChunking< T > Class Template Reference

Wavelet-based chunking strategy using signal processing principles. More...

#include <sophisticated_chunking.hpp>

+ Collaboration diagram for sophisticated_chunking::WaveletChunking< T >:

Public Member Functions

 WaveletChunking (size_t window_size=8, double threshold=0.5)
 Constructor for wavelet-based chunking.
 
std::vector< std::vector< T > > chunk (const std::vector< T > &data) const
 Chunk data based on wavelet transform analysis.
 
double get_threshold () const
 Get the coefficient threshold for chunk boundaries.
 
std::string get_wavelet_type () const
 Get the current wavelet type.
 
size_t get_window_size () const
 Get the size of the sliding window.
 
void set_threshold (double threshold)
 Set the coefficient threshold for chunk boundaries.
 
void set_wavelet_type (const std::string &type)
 Set the wavelet type.
 
void set_window_size (size_t size)
 Set the size of the sliding window.
 

Private Member Functions

std::vector< double > computeWaveletCoefficients (const std::vector< T > &data) const
 Compute discrete wavelet transform coefficients.
 

Private Attributes

double threshold_
 
std::string wavelet_type_
 
size_t window_size_
 

Detailed Description

template<typename T>
class sophisticated_chunking::WaveletChunking< T >

Wavelet-based chunking strategy using signal processing principles.

Template Parameters
TThe type of elements to be chunked

Definition at line 22 of file sophisticated_chunking.hpp.

Constructor & Destructor Documentation

◆ WaveletChunking()

template<typename T >
sophisticated_chunking::WaveletChunking< T >::WaveletChunking ( size_t  window_size = 8,
double  threshold = 0.5 
)
inline

Constructor for wavelet-based chunking.

Parameters
window_sizeSize of the sliding window
thresholdCoefficient threshold for chunk boundaries

Definition at line 79 of file sophisticated_chunking.hpp.

Member Function Documentation

◆ chunk()

template<typename T >
std::vector< std::vector< T > > sophisticated_chunking::WaveletChunking< T >::chunk ( const std::vector< T > &  data) const
inline

Chunk data based on wavelet transform analysis.

Parameters
dataInput data to be chunked
Returns
Vector of chunks

Definition at line 87 of file sophisticated_chunking.hpp.

87 {
88 if (data.empty()) {
89 return {};
90 }
91
92 auto coefficients = computeWaveletCoefficients(data);
93 std::vector<std::vector<T>> chunks;
94 std::vector<T> current_chunk;
95
96 size_t i = 0;
97 for (const T& value : data) {
98 current_chunk.push_back(value);
99
100 if (i < coefficients.size() && coefficients[i] > threshold_) {
101 if (!current_chunk.empty()) {
102 chunks.push_back(current_chunk);
103 current_chunk.clear();
104 }
105 }
106 ++i;
107 }
108
109 if (!current_chunk.empty()) {
110 chunks.push_back(current_chunk);
111 }
112
113 return chunks;
114 }
std::vector< double > computeWaveletCoefficients(const std::vector< T > &data) const
Compute discrete wavelet transform coefficients.

References sophisticated_chunking::WaveletChunking< T >::computeWaveletCoefficients(), and sophisticated_chunking::WaveletChunking< T >::threshold_.

Referenced by demonstrate_wavelet_chunking(), TEST_F(), and TEST_F().

◆ computeWaveletCoefficients()

template<typename T >
std::vector< double > sophisticated_chunking::WaveletChunking< T >::computeWaveletCoefficients ( const std::vector< T > &  data) const
inlineprivate

Compute discrete wavelet transform coefficients.

Parameters
dataInput data sequence
Returns
Vector of wavelet coefficients

Definition at line 33 of file sophisticated_chunking.hpp.

33 {
34 if (data.size() < window_size_) {
35 return std::vector<double>();
36 }
37
38 std::vector<double> coefficients;
39 coefficients.reserve(data.size() - window_size_ + 1);
40
41 // Different wavelet implementations
42 if (wavelet_type_ == "haar" || wavelet_type_ == "db1") {
43 // Haar wavelet transform
44 for (size_t i = 0; i <= data.size() - window_size_; ++i) {
45 double sum = 0.0;
46 for (size_t j = 0; j < window_size_ / 2; ++j) {
47 double diff = static_cast<double>(data[i + j]) -
48 static_cast<double>(data[i + window_size_ - 1 - j]);
49 sum += diff * diff;
50 }
51 coefficients.push_back(std::sqrt(sum / window_size_));
52 }
53 } else if (wavelet_type_ == "sym2") {
54 // Symlet 2 wavelet transform
55 const std::vector<double> h = {-0.1294, 0.2241, 0.8365,
56 0.4830}; // Symlet 2 coefficients
57 for (size_t i = 0; i <= data.size() - window_size_; ++i) {
58 double sum = 0.0;
59 for (size_t j = 0; j < std::min(window_size_, size_t(4)); ++j) {
60 if (i + j < data.size()) {
61 sum += h[j] * static_cast<double>(data[i + j]);
62 }
63 }
64 coefficients.push_back(std::abs(sum));
65 }
66 } else {
67 throw std::invalid_argument("Unsupported wavelet type: " + wavelet_type_);
68 }
69
70 return coefficients;
71 }

References sophisticated_chunking::WaveletChunking< T >::wavelet_type_, and sophisticated_chunking::WaveletChunking< T >::window_size_.

Referenced by sophisticated_chunking::WaveletChunking< T >::chunk().

◆ get_threshold()

template<typename T >
double sophisticated_chunking::WaveletChunking< T >::get_threshold ( ) const
inline

Get the coefficient threshold for chunk boundaries.

Returns
Coefficient threshold for chunk boundaries

Definition at line 128 of file sophisticated_chunking.hpp.

128 {
129 return threshold_;
130 }

References sophisticated_chunking::WaveletChunking< T >::threshold_.

◆ get_wavelet_type()

template<typename T >
std::string sophisticated_chunking::WaveletChunking< T >::get_wavelet_type ( ) const
inline

Get the current wavelet type.

Returns
Current wavelet type

Definition at line 154 of file sophisticated_chunking.hpp.

154 {
155 return wavelet_type_;
156 }

References sophisticated_chunking::WaveletChunking< T >::wavelet_type_.

◆ get_window_size()

template<typename T >
size_t sophisticated_chunking::WaveletChunking< T >::get_window_size ( ) const
inline

Get the size of the sliding window.

Returns
Size of the sliding window

Definition at line 120 of file sophisticated_chunking.hpp.

120 {
121 return window_size_;
122 }

References sophisticated_chunking::WaveletChunking< T >::window_size_.

◆ set_threshold()

template<typename T >
void sophisticated_chunking::WaveletChunking< T >::set_threshold ( double  threshold)
inline

Set the coefficient threshold for chunk boundaries.

Parameters
thresholdCoefficient threshold for chunk boundaries

Definition at line 146 of file sophisticated_chunking.hpp.

146 {
147 threshold_ = threshold;
148 }

References sophisticated_chunking::WaveletChunking< T >::threshold_.

◆ set_wavelet_type()

template<typename T >
void sophisticated_chunking::WaveletChunking< T >::set_wavelet_type ( const std::string &  type)
inline

Set the wavelet type.

Parameters
typeWavelet type ("haar", "db1", or "sym2")

Definition at line 162 of file sophisticated_chunking.hpp.

162 {
163 if (type != "haar" && type != "db1" && type != "sym2") {
164 throw std::invalid_argument("Invalid wavelet type. Supported types: haar, db1, sym2");
165 }
166 wavelet_type_ = type;
167 }

References sophisticated_chunking::WaveletChunking< T >::wavelet_type_.

◆ set_window_size()

template<typename T >
void sophisticated_chunking::WaveletChunking< T >::set_window_size ( size_t  size)
inline

Set the size of the sliding window.

Parameters
sizeSize of the sliding window

Definition at line 136 of file sophisticated_chunking.hpp.

136 {
137 if (size == 0)
138 throw std::invalid_argument("Window size cannot be zero");
139 window_size_ = size;
140 }

References sophisticated_chunking::WaveletChunking< T >::window_size_.

Member Data Documentation

◆ threshold_

◆ wavelet_type_

◆ window_size_


The documentation for this class was generated from the following file: