Grey Relational Analysis Model
Last updated on July 28, 2025 am
This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to original Chinese version. I am continuously working to improve the translation.
Some notes I made while studying mathematical modeling algorithms during the summer of 2025.
Grey Systems
A system is black: little information; white: abundant information; grey: somewhere in between
Correlation Analysis
Analyzing the connections between factors
Steps
1. Determine the mother sequence
A data sequence reflecting the behavioral characteristics of the system, similar to the dependent variable $Y$, given by $$ Y=\begin{bmatrix}y_1,y_2,\cdots,y_n\end{bmatrix}^T $$
2. Determine the sub-sequences
Sub-sequences (also called comparison sequences or sub-indicators) Data sequences composed of factors that influence the behavior of the system, similar to the independent variables $X$, denoted as $$X_{nm}=\begin{bmatrix}x_{11}&x_{12}&\cdots&x_{1m}\x_{21}&x_{22}&\cdots&x_{2m}\\vdots&\vdots&\ddots&\vdots\x_{n1}&x_{n2}&\cdots&x_{nm}\end{bmatrix}$$
3. Data preprocessing
Since different factors have different dimensions and data ranges, we need to preprocess them to remove dimensions and unify them into a similar range. First compute the mean of each indicator, then divide each element of the indicator by its mean $$ \widetilde{y_k}=\frac{y_k}{\overline{y}},\overline{y}=\frac{1}{n}\sum_{k=1}^{n}y_k\qquad\widetilde{x_{ki}}=\frac{x_{ki}}{\overline{x_i}},\overline{x_i}=\frac{1}{n}\sum_{k=1}^{n}x_{ki}(i=1,2,\cdots,m) $$
4. Compute the grey relational coefficients
Compute the relational coefficients between each indicator in the sub-sequences and the mother sequence $$ a=\min\limits_{i}\min\limits_{k}|x_{0}(k)-x_{i}(k)|, b=\max\limits_{i}\max\limits_{k}|x_{0}(k)-x_{i}(k)| $$ which are the two-level minimum difference and maximum difference
Construct: $$ \xi_{i}(k)=y(x_{0}(k),x_{i}(k))=\frac{a+\rho b}{|x_{0}(k)-x_{i}(k)|+\rho b} $$ where $\rho$ is the resolution coefficient, usually taken as 0.5
5. Compute the relational degrees
$$ r_i=\frac{1}{n}\sum_{k=1}^{n}\xi_i\left(k\right)=\frac{1}{n}\sum_{k=1}^{n}y\left(x_0\left(k\right),x_i\left(k\right)\right) $$
6. Compute the indicator weights
Normalize the relational degrees $$ w_i=\frac{r_i}{\sum_{k=1}^mr_k}\big(i=1,2,\cdots,m\big) $$
Python Code
代码
import numpy as np
# 请输入初始矩阵 [[55, 24, 10], [65, 38, 22], [75, 40, 18], [100, 50, 20]]
A = np.array(eval(input('请输入初始矩阵='))) # 假设输入的形式是合法的 Python 列表形式
# 求出每一列的均值以供后续的数据预处理
Mean = np.mean(A, axis=0)
# 预处理后的矩阵
A_norm = A / Mean
print('预处理后的矩阵为:')
print(A_norm)
# 母序列
Y = A_norm[:, 0]
# 子序列
X = A_norm[:, 1:]
# 计算|X0-Xi|矩阵 (在这里我们把 X0 定义为了 Y)
absX0_Xi = np.abs(X - np.tile(Y.reshape(-1, 1), (1, X.shape[1])))
# 计算两级最小差 a
a = np.min(absX0_Xi)
# 计算两级最大差 b
b = np.max(absX0_Xi)
# 分辨系数取 0.5
rho = 0.5
# 计算子序列中各个指标与母序列的关联系数
gamma = (a + rho * b) / (absX0_Xi + rho * b)
print('子序列中各个指标的灰色关联度分别为:')
print(np.mean(gamma, axis=0))