归一化list里面的数据

java中,归一化list里面的数据

 

/**
 * 归一化
 * @param listInt
 * @return
 */
public static List<Double> normalListInteger(List<Integer> listInt){
    List<Double> list_d = new ArrayList<Double>();
    int maxValue = listInt.get(0);
    int minValue = listInt.get(0);
    for(int k = 0;k<listInt.size();k++) {
        int indexValue = listInt.get(k);
        
        if(indexValue<minValue) {
            minValue = indexValue;
        }
        
        if(indexValue>maxValue) {
            maxValue = indexValue;
        }
    }
    
    for(int k = 0;k<listInt.size();k++) {
        int indexValue = listInt.get(k);
        
        //x = (x - Min) / (Max - Min);
        
        double indexDValue = (double)(indexValue-minValue)/(double)(maxValue-minValue);
        list_d.add(indexDValue);
    }
    
    
    return list_d;
}

 

 

########################

posted @ 2022-02-22 18:01  西北逍遥  阅读(316)  评论(0编辑  收藏  举报