import json import numpy as np # 精确一致的互反矩阵,元素 A[i,j] 表示指标 i 相对于 j 的重要性。 matrix = np.array([[1, 2, 4], [.5, 1, 2], [.25, .5, 1]]) normalized = matrix / matrix.sum(axis=0) weights = normalized.mean(axis=1) # 一致矩阵满足 A·w = n·w;取对应分量比率估计主特征值。 lambda_max = float((matrix @ weights / weights).mean()) ci = (lambda_max - len(weights)) / (len(weights) - 1) assert np.allclose(weights, np.array([4, 2, 1]) / 7) and abs(ci) < 1e-12 result = {"weights": weights.tolist(), "lambda_max": lambda_max, "consistency_index": ci} print("LAB_RESULT " + json.dumps(result, ensure_ascii=False))