Skip to content
Snippets Groups Projects
NormalizationStrategy.cpp 966 B
Newer Older
  • Learn to ignore specific revisions
  • #include <cmath>
    #include <stdexcept>
    #include <boost/serialization/export.hpp>
    
    
    #include "NormalizationStrategySerialization.h"
    
    BOOST_CLASS_EXPORT_IMPLEMENT(NormalizationStrategy);
    BOOST_CLASS_EXPORT_IMPLEMENT(DoubleUnitStrategy);
    
    double NormalizationStrategy::get_max_value() {
        return this->max_value;
    }
    
    double NormalizationStrategy::get_min_value() {
        return this->min_value;
    }
    
    
    DoubleUnitStrategy::DoubleUnitStrategy() {}
    
    double DoubleUnitStrategy::normalize(double n, double max, double min) {
    
        this->max_value = max;
        this->min_value = min;
    
    
    double DoubleUnitStrategy::de_normalize(double n) {
        if(std::isnan(this->max_value)) {
            throw std::runtime_error("Data were not normalized, so de-normalization cannot progress!");
        }
    
        return 0.5 * (1 + (this->max_value - this->min_value) * n) + this->min_value;