我一直在研究马尔可夫聚类算法的细节,参考了以下示例:http://www.cs.ucsb.edu/~xyan/classes/CS595D-2009winter/MCL_Presentation2.pdf。我觉得我已经准确地表示了该算法,但是我并没有得到与该指南相同的结果。我目前的代码链接在这里:http://jsfiddle.net/methodin/CtGJ9/。
我不确定我是否错过了某些小问题或者只需要对某些内容进行微调,因为我尝试了几个变化包括:
1. 交换膨胀/扩张 2. 根据精度检查相等性 3. 删除归一化(因为原始指南不需要它,尽管官方MCL文档声明要在每次通过时正常化矩阵)
所有这些都返回了相同的结果——节点仅影响自身。
我甚至找到了一个类似的VB算法实现,链接在这里:http://mcl.codeplex.com/SourceControl/changeset/changes/17748#MCL%2fMCL%2fMatrix.vb,我的代码似乎与其匹配,除了它们的编号(例如600-距离)。
这是扩张函数。
我不确定我是否错过了某些小问题或者只需要对某些内容进行微调,因为我尝试了几个变化包括:
1. 交换膨胀/扩张 2. 根据精度检查相等性 3. 删除归一化(因为原始指南不需要它,尽管官方MCL文档声明要在每次通过时正常化矩阵)
所有这些都返回了相同的结果——节点仅影响自身。
我甚至找到了一个类似的VB算法实现,链接在这里:http://mcl.codeplex.com/SourceControl/changeset/changes/17748#MCL%2fMCL%2fMatrix.vb,我的代码似乎与其匹配,除了它们的编号(例如600-距离)。
这是扩张函数。
// Take the (power)th power of the matrix effectively multiplying it with
// itself pow times
this.matrixExpand = function(matrix, pow) {
var resultMatrix = [];
for(var row=0;row<matrix.length;row++) {
resultMatrix[row] = [];
for(var col=0;col<matrix.length;col++) {
var result = 0;
for(var c=0;c<matrix.length;c++)
result += matrix[row][c] * matrix[c][col];
resultMatrix[row][col] = result;
}
}
return resultMatrix;
};
这是通胀函数
// Applies a power of X to each item in the matrix
this.matrixInflate = function(matrix, pow) {
for(var row=0;row<matrix.length;row++)
for(var col=0;col<matrix.length;col++)
matrix[row][col] = Math.pow(matrix[row][col], pow);
};
最后是主要的传递函数
// Girvan–Newman algorithm
this.getMarkovCluster = function(power, inflation) {
var lastMatrix = [];
var currentMatrix = this.getAssociatedMatrix();
this.print(currentMatrix);
this.normalize(currentMatrix);
currentMatrix = this.matrixExpand(currentMatrix, power);
this.matrixInflate(currentMatrix, inflation);
this.normalize(currentMatrix);
while(!this.equals(currentMatrix,lastMatrix)) {
lastMatrix = currentMatrix.slice(0);
currentMatrix = this.matrixExpand(currentMatrix, power);
this.matrixInflate(currentMatrix, inflation);
this.normalize(currentMatrix);
}
return currentMatrix;
};