【专家打分归一化,指标权重】

/**
 * 专家打分
 */
public double[][] addScore(double[][] score) {
    ExpertScore expertScore = new ExpertScore();
    int rows = score.length;//行
    int cols = score[0].length;//列
    // 计算每列的元素和
    double[] colSums = new double[cols];
    for (int j = 0; j < cols; j++) {
        double sum = 0;
        for (int i = 0; i < rows; i++) {
            sum += score[i][j] /10;
        }
        colSums[j] = sum;
    }
    // 对矩阵进行列归一化操作
    for (int j = 0; j < cols; j++) {
        for (int i = 0; i < rows; i++) {
            score[i][j] = (score[i][j]/10) /colSums[j];

        }
    }

    return score;

}
/** * 指标权重配置 */
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject create(JSONObject json) throws JsonProcessingException {

    WeightResult weightResult = new WeightResult();
    // 创建 ObjectMapper 对象
    ObjectMapper objectMapper = new ObjectMapper();

    // 将 JSON 字符串解析为一个 JsonNode 对象
    JsonNode jsonNode = objectMapper.readTree(String.valueOf(json));

    // 通过 JsonNode 对象获取 score 数组和 weight 数组
    JsonNode scoreNode = jsonNode.get("score");
    JsonNode weightNode = jsonNode.get("weight");

    // 将 score 数组和 weight 数组转换为 Java 数组
    double[][] score = objectMapper.convertValue(scoreNode, double[][].class);
    double[][] weight = objectMapper.convertValue(weightNode, double[][].class);

    IndicatorWeight indicatorWeight = new IndicatorWeight();
    double[][] matrix = weight;
    double[][] scores = score;
    int rows = matrix.length;//行
    int cols = matrix[0].length;//列
    // 计算每列的元素和
    double[] colSums = new double[cols];
    for (int j = 0; j < cols; j++) {
        double sum = 0;
        for (int i = 0; i < rows; i++) {
            sum += matrix[i][j];
        }
        colSums[j] = sum;
    }
    // 对矩阵进行列归一化操作
    for (int j = 0; j < cols; j++) {
        for (int i = 0; i < rows; i++) {
            matrix[i][j] /= colSums[j];
        }
    }
    // 输出归一化后的矩阵
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            System.out.print(matrix[i][j] + " ");
        }
        System.out.println();
    }
    //将归一化后的列相加
    double[] we = new double[cols];
    for (int j = 0; j < cols; j++) {
        for (int i = 0; i < rows; i++) {
            we[j] += matrix[i][j];
        }
        we[j] /= 6;
        //return we;
        System.out.println("we:" + we[j]);
    }
    indicatorWeightRepository.save(indicatorWeight);
    
  // 计算结果数组
    double[] result = new double[scores.length];
    for (int j = 0; j < scores.length; j++) {
        double sum = 0.0;
        for (int i = 0; i < scores[0].length; i++) {
            sum += (score[j][i] /10) * we[i];
        }
        result[j] = sum;
        System.out.println("result:"+ result[j]);
       /* weightResult.setWDisPhen(result[j]);
        weightResult.setWMechanismProposed(result[j]);
        weightResult.setWVerifyTechnologies(result[j]);
        weightResult.setWSolveScientificProblems(result[j]);
        weightResult.setWOriginality(result[j]);
        weightResult.setWUrgency(result[j]);
        weightResultRepository.save(weightResult);*/
    }

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("weight", we);
    jsonObject.put("score",result);

    return jsonObject;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值