65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
|
|
#include <eqpalg/distribution/data_mapping.h>
|
||
|
|
#include <eqpalg/distribution/box_cox.h>
|
||
|
|
#include <cmath>
|
||
|
|
#include <functional>
|
||
|
|
#include <log4cplus/LOG.h>
|
||
|
|
namespace distribution {
|
||
|
|
|
||
|
|
double inner_transform_warpper(
|
||
|
|
double input, double coeff,
|
||
|
|
std::function<double(double, double)> transform_func) {
|
||
|
|
bool is_neg = false;
|
||
|
|
if (input < 0) {
|
||
|
|
is_neg = true;
|
||
|
|
input = -input;
|
||
|
|
}
|
||
|
|
double ret = transform_func(input, coeff);
|
||
|
|
if (is_neg == true) {
|
||
|
|
ret = -ret;
|
||
|
|
}
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
dlib::running_stats<double> DataMapping::get_running_stats() {
|
||
|
|
return this->rs_;
|
||
|
|
}
|
||
|
|
|
||
|
|
double DataMapping::reverse_transform(double input) {
|
||
|
|
return box_cox_reverse(input, c_, lambda_);
|
||
|
|
}
|
||
|
|
|
||
|
|
int DataMapping::set_running_stats(dlib::running_stats<double> prev_rs) {
|
||
|
|
this->rs_ = prev_rs;
|
||
|
|
if (rs_.skewness() > 0) {
|
||
|
|
is_positive_skewed_ = true;
|
||
|
|
}
|
||
|
|
if (rs_.skewness() < 0) {
|
||
|
|
is_positive_skewed_ = false;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<double> DataMapping::transform(
|
||
|
|
const std::vector<double>& input) {
|
||
|
|
if (rs_.min() < 0) {
|
||
|
|
c_ = (rs_.min()) * (-2);
|
||
|
|
} else {
|
||
|
|
c_ = 0;
|
||
|
|
}
|
||
|
|
std::vector<double> input_cp;
|
||
|
|
size_t loop_count = 0;
|
||
|
|
while (loop_count < 1000 && abs(rs_.skewness()) > 0) {
|
||
|
|
input_cp = input;
|
||
|
|
rs_.clear();
|
||
|
|
lambda_ += delta_;
|
||
|
|
for (auto& x : input_cp) {
|
||
|
|
x = box_cox(x, c_, lambda_);
|
||
|
|
rs_.add(x);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return input_cp;
|
||
|
|
}
|
||
|
|
|
||
|
|
double DataMapping::get_lambda() { return this->lambda_; }
|
||
|
|
} // namespace distribution
|