//计算节点的特征向量
private double[] normalize(double[][] matrix)
{
int row = matrix.Length;
int column = matrix[0].Length;
double[] Sum_column = new double[column];
double[] w = new double[row];
if (normalizeType == "和法")
{
for (int i = 0; i < column; i++)
{
Sum_column[i] = 0;
for (int j = 0; j < row; j++)
{
Sum_column[i] += matrix[j][i];
}
}
//进行归一化,计算特征向量W
for (int i = 0; i < row; i++)
{
w[i] = 0;
for (int j = 0; j < column; j++)
{
w[i] += matrix[i][j] / Sum_column[j];
}
w[i] /= row;
}
}
if (normalizeType == "根法")
{
for (int i = 0; i < column; i++)
{
Sum_column[i] = 0;
for (int j = 0; j < row; j++)
{
Sum_column[i] += matrix[j][i];
}
}
//进行归一化,计算特征向量W
double sum = 0;
for (int i = 0; i < row; i++)
{
w[i] = 1;
for (int j = 0; j < column; j++)
{
w[i] *= matrix[i][j] / Sum_column[j];
}
w[i]=Math.Pow(w[i],1.0/row);
sum += w[i];
}
for (int i = 0; i < row; i++)
{
w[i] /= sum;
}
}
if (normalizeType == "幂法")
{
double[] w0 = new double[row];
for (int i = 0; i < row; i++)
{
w0[i] = 1.0/row;
}
//一般向量W(k+1)
double[] w1 = new double[row];
//W(k+1)的归一化向量
double sum = 1.0;
double d = 1.0;
double delt = 0.00001;
while (d > delt)
{
d=0.0;
sum = 0;
//获取向量
for (int j = 0; j < row; j++)
{
w1[j] = 0;
for (int k = 0; k < row; k++)
{
w1[j] += matrix[j][k] * w0[k];
}
sum += w1[j];
}
//向量归一化
for (int k = 0; k < row; k++)
{
w[k] = w1[k] / sum;
d = Math.Max(Math.Abs(w[k] - w0[k]), d);//最大差值
w0[k] = w[k];//用于下次迭代使用
}
}
}
return w;
}