Newer
Older
Martin Beseda
committed
//
// Created by martin on 21.11.18.
//
#include <cmath>
#include <stdexcept>
#include <boost/serialization/export.hpp>
Martin Beseda
committed
#include "NormalizationStrategy.h"
#include "NormalizationStrategySerialization.h"
BOOST_CLASS_EXPORT_IMPLEMENT(NormalizationStrategy);
BOOST_CLASS_EXPORT_IMPLEMENT(DoubleUnitStrategy);
double NormalizationStrategy::get_max_value() {
Martin Beseda
committed
return this->max_min_inp_val.at(0);
}
double NormalizationStrategy::get_min_value() {
Martin Beseda
committed
return this->max_min_inp_val.at(1);
Martin Beseda
committed
DoubleUnitStrategy::DoubleUnitStrategy() {}
double DoubleUnitStrategy::normalize(double n, double max, double min) {
if(this->max_min_inp_val.empty()) {
this->max_min_inp_val.emplace_back(max);
this->max_min_inp_val.emplace_back(min);
} else {
this->max_min_inp_val.at(0) = max;
this->max_min_inp_val.at(1) = min;
}
Martin Beseda
committed
return 2*(n - min)/(max - min) - 1;
double DoubleUnitStrategy::de_normalize(double n) {
Martin Beseda
committed
if(this->max_min_inp_val.empty()) {
THROW_RUNTIME_ERROR("Data were not normalized, so de-normalization cannot progress!");
Martin Beseda
committed
return 0.5 * (1 + (this->get_max_value() - this->get_min_value()) * n) + this->get_min_value();