package com.rongyi.platform.game.web.data;

import java.util.ArrayList;
import java.util.List;

public class MinMaxScaler {
private double min;
private double max;

private List<Double> data;

public MinMaxScaler(List<Double> data) {
this.min = Double.POSITIVE_INFINITY;
this.max = Double.NEGATIVE_INFINITY;
this.data = data;

for (double datum : data) {
this.min = Math.min(this.min, datum);
this.max = Math.max(this.max, datum);
}
}

public List<Double> scale() {
List<Double> scaledData = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
if (max == min) {
scaledData.add(0.0);
} else {
scaledData.add((data.get(i) - min) / (max - min));
}
}
return scaledData;
}
}
posted on 2024-10-23 18:34  毛会懂  阅读(6)  评论(0编辑  收藏  举报