【发布时间】:2012-02-04 13:34:51
【问题描述】:
我一直在研究马尔可夫聚类算法细节的以下示例:
http://www.cs.ucsb.edu/~xyan/classes/CS595D-2009winter/MCL_Presentation2.pdf
我觉得我已经准确地表示了算法,但我得到的结果与本指南至少在该输入中得到的结果不同。
当前代码位于: http://jsfiddle.net/methodin/CtGJ9/
我不确定我是否只是错过了一个小事实,或者只是需要在某个地方进行一些小调整,但我尝试了一些变化,包括:
- 交换通货膨胀/扩张
- 基于精度检查相等性
- 删除归一化(因为原始指南没有要求,尽管官方 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);
};
最后是主要的 passthru 函数
// 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;
};
【问题讨论】:
-
jsfiddle 链接似乎已损坏,您的实现在某处是否仍然可用?谢谢!
-
奇怪。我想知道它去哪儿了?这是代码的要点:gist.github.com/methodin/1573728
标签: javascript cluster-analysis markov