|
@ -1,26 +1,29 @@ |
|
|
package com.epmet.stats.test.normalizing; |
|
|
package com.epmet.stats.test.normalizing; |
|
|
|
|
|
|
|
|
import com.epmet.support.normalizing.Correlation; |
|
|
import com.epmet.support.normalizing.*; |
|
|
import com.epmet.support.normalizing.DoubleScoreCalculator; |
|
|
import com.epmet.support.normalizing.batch.BatchScoreCalculator; |
|
|
import com.epmet.support.normalizing.IntegerScoreCalculator; |
|
|
import com.epmet.support.normalizing.batch.IndexInputVO; |
|
|
import com.epmet.support.normalizing.ScoreCalculator; |
|
|
import com.epmet.support.normalizing.batch.IndexOutputVO; |
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
public class DemoScoreCal { |
|
|
public class DemoScoreCal { |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
//demoInteger();
|
|
|
//demoInteger();
|
|
|
demoIntegerPartical(); |
|
|
//demoIntegerPartical();
|
|
|
//demoDouble();
|
|
|
//demoDouble();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 整数类型,完整源数据列表的归一算法 |
|
|
* 整数类型,完整源数据列表的归一算法 |
|
|
*/ |
|
|
*/ |
|
|
public static void demoInteger() { |
|
|
@Test |
|
|
Integer[] iArray = {4,8,1,3,2}; |
|
|
public void demoInteger() { |
|
|
|
|
|
Integer[] iArray = {4, 8, 1, 3, 2}; |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
|
|
|
|
|
@ -32,12 +35,13 @@ public class DemoScoreCal { |
|
|
/** |
|
|
/** |
|
|
* 整数类型,基于边界值的部分列表的的归一算法 |
|
|
* 整数类型,基于边界值的部分列表的的归一算法 |
|
|
*/ |
|
|
*/ |
|
|
public static void demoIntegerPartical() { |
|
|
@Test |
|
|
Integer[] iArray = {4,1,2}; |
|
|
public void demoIntegerPartical() { |
|
|
|
|
|
Integer[] iArray = {4, 1, 8}; |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
|
|
|
|
|
|
ScoreCalculator sc = new IntegerScoreCalculator(1, 8 ,minScore, maxScore, Correlation.NEGATIVE); |
|
|
ScoreCalculator sc = new IntegerScoreCalculator(1, 8, minScore, maxScore, Correlation.NEGATIVE); |
|
|
BigDecimal[] scores = sc.normalize(iArray);// 此处也可以直接使用list参数的重载方法,计算阶段没有任何区别,区别在于new IntegerScoreCalculator()阶段
|
|
|
BigDecimal[] scores = sc.normalize(iArray);// 此处也可以直接使用list参数的重载方法,计算阶段没有任何区别,区别在于new IntegerScoreCalculator()阶段
|
|
|
Arrays.stream(scores).forEach(s -> System.out.println(s)); |
|
|
Arrays.stream(scores).forEach(s -> System.out.println(s)); |
|
|
} |
|
|
} |
|
@ -46,7 +50,7 @@ public class DemoScoreCal { |
|
|
* double类型归一算法 |
|
|
* double类型归一算法 |
|
|
*/ |
|
|
*/ |
|
|
public static void demoDouble() { |
|
|
public static void demoDouble() { |
|
|
Double[] iArray = {1.9,8.9,1.0,3.0,2.0}; |
|
|
Double[] iArray = {1.9, 8.9, 1.0, 3.0, 2.0}; |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal minScore = new BigDecimal(5); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
BigDecimal maxScore = new BigDecimal(10); |
|
|
|
|
|
|
|
@ -61,6 +65,31 @@ public class DemoScoreCal { |
|
|
System.out.println(normalize2); |
|
|
System.out.println(normalize2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 批量计算demo |
|
|
|
|
|
*/ |
|
|
|
|
|
@Test |
|
|
|
|
|
public void testBatchCalculate() throws InterruptedException { |
|
|
|
|
|
//{4,8,1,3,2}
|
|
|
|
|
|
|
|
|
|
|
|
// 每个指标需要单独的分支计算器,因为每个指标的最大最小值是不同的
|
|
|
|
|
|
ScoreCalculator<Integer> sc1 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); |
|
|
|
|
|
ScoreCalculator<Integer> sc2 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); |
|
|
|
|
|
|
|
|
|
|
|
// 每个指标的信息,包括样本列表,权重,指标标记
|
|
|
|
|
|
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", Arrays.asList(4, 1, 8), new BigDecimal(1), sc1); |
|
|
|
|
|
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", Arrays.asList(1, 8, 3), new BigDecimal(1), sc2); |
|
|
|
|
|
|
|
|
|
|
|
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO); |
|
|
|
|
|
|
|
|
|
|
|
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); |
|
|
|
|
|
List<IndexOutputVO> result = batchScoreCalculator.exec(indexInputVOS); |
|
|
|
|
|
|
|
|
|
|
|
System.err.println("--------------------------------"); |
|
|
|
|
|
result.stream().forEach(r -> System.out.println(r)); |
|
|
|
|
|
Thread.sleep(10); |
|
|
|
|
|
System.err.println("--------------------------------"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|