|
|
@ -6,6 +6,7 @@ import java.util.Arrays; |
|
|
|
|
|
|
|
/** |
|
|
|
* 所有数据类型计算器的父类,实现算法骨架,数据类型转换方法则由子类实现 |
|
|
|
* ☆☆☆ 如果需要保持传入的数组元素顺序不变,请在实现类的构造方法中将传入数组进行克隆 ☆☆☆ |
|
|
|
* @param <T> 数据类型泛型 |
|
|
|
*/ |
|
|
|
public abstract class ScoreCalculator<T> { |
|
|
@ -38,7 +39,7 @@ public abstract class ScoreCalculator<T> { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 归一算法 |
|
|
|
* 单值归一算法 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public BigDecimal normalize(T sourceValue) { |
|
|
@ -66,6 +67,49 @@ public abstract class ScoreCalculator<T> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 单值归一算法,带权重 |
|
|
|
* @param sourceValue |
|
|
|
* @param weight |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public BigDecimal normalize(T sourceValue, BigDecimal weight) { |
|
|
|
return normalize(sourceValue).multiply(weight); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量归一算法 |
|
|
|
* @param sourceValues |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public BigDecimal[] normalize(T[] sourceValues) { |
|
|
|
|
|
|
|
BigDecimal[] scores = new BigDecimal[sourceValues.length]; |
|
|
|
|
|
|
|
for (int i=0;i<sourceValues.length;i++) { |
|
|
|
BigDecimal score = normalize(sourceValues[i]); |
|
|
|
scores[i] = score; |
|
|
|
} |
|
|
|
return scores; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量归一算法,带权重 |
|
|
|
* @param sourceValues |
|
|
|
* @param weight |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public BigDecimal[] normalize(T[] sourceValues, BigDecimal weight) { |
|
|
|
|
|
|
|
BigDecimal[] scores = new BigDecimal[sourceValues.length]; |
|
|
|
|
|
|
|
for (int i=0;i<sourceValues.length;i++) { |
|
|
|
BigDecimal score = normalize(sourceValues[i]); |
|
|
|
scores[i] = score.multiply(weight); |
|
|
|
} |
|
|
|
return scores; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验数组 |
|
|
|
* @param sourceArray |
|
|
|