34 : quantizationInterval_(quantizationInterval),
35 quantizationRest_(1, 0.0),
37 quantizationMethod_(method)
49 void noisify(
double& value,
size_t index = 0)
51 if (index >= quantizationRest_.size())
52 quantizationRest_.resize(index, 0);
54 double currentValue = value + quantizationRest_[index];
55 double nQuantsDouble = currentValue / quantizationInterval_;
58 switch (quantizationMethod_)
62 nQuants = std::floor(nQuantsDouble);
67 nQuants = std::round(nQuantsDouble);
72 throw std::runtime_error(
"Unknown quantization method chosen");
76 double outputValue = nQuants * quantizationInterval_;
78 quantizationRest_[index] = currentValue - outputValue;
80 value = outputValue + bias_;
89 template <
size_t size>
90 void noisify(Eigen::Matrix<double, size, 1>& value)
92 for (
size_t i = 0;
i < size;
i++)
102 void reset() { quantizationRest_.clear(); }
104 double quantizationInterval_;
105 std::vector<double> quantizationRest_;
Definition: QuantizationNoise.h:24
void noisify(double &value, size_t index=0)
Applies quantization to a value.
Definition: QuantizationNoise.h:49
Quantization of data.
Definition: QuantizationNoise.h:17
void reset()
Resets the quantization.
Definition: QuantizationNoise.h:102
Definition: QuantizationNoise.h:23
QuantizationMethod
The quanitization method.
Definition: QuantizationNoise.h:21
void noisify(Eigen::Matrix< double, size, 1 > &value)
Applies quantization to a vector.
Definition: QuantizationNoise.h:90
QuantizationNoise(double bias=0.0, double quantizationInterval=1.0, QuantizationMethod method=FLOOR)
Default constructor.
Definition: QuantizationNoise.h:33