• 归一化 [a] 到 [b] 区间


    #include <algorithm>
    //https://en.wikipedia.org/wiki/Feature_scaling
    std::vector<double> rescaling_normalization(const std::vector<double> &in,double left_interval/*左区间*/, double right_interval/*右区间*/) {
    	const auto min_max = std::minmax_element(in.begin(), in.end());
    	double &a = left_interval;
    	double &b = right_interval;
    	double min = *min_max.first;
    	double max = *min_max.second;
    
    	std::vector<double> nor;
    	for (const double &x : in) {
    		nor.push_back(a + ((x - min)*(b - a)) / (max - min));
    	}
    	return nor;
    }
    

    使用

    std::vector<double> in = { 0.0,15.0,30.0,66.0,72.0,98.0 };
    in = rescaling_normalization(in, -1, 1);
    for (auto &&v : in) {
      std::cout << v << std::endl;
    }
    
    转载请注明出处并保持作品的完整性,谢谢
  • 相关阅读:
    。。
    6-4 静态内部类
    SQL把一个表里的数据赋值到另外一个表里去
    jquery 设置 disabled属性
    6-4 内部类
    DWR 整合之Struts2.3.16
    DWR整合之JSF
    DWR整合之Servlet
    dwr.xml 配置
    认识DWR
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/14478570.html
Copyright © 2020-2023  润新知