一、代码问题
运行test_segimage.m时,存在如下错误:
Building affinity matrix took 0.092672 second
Error using dist2aff
Function "mxGetIr_700" is obsolete.
(64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option. See the
R2006b release notes for more details.)
解决方法: mex -O -largeArrayDims dist2aff.cpp
但是存在如下错误:
dist2aff.cpp
dist2aff.cpp(90) : error C2440: “初始化”: 无法从“const mwSize *”转换为“const int *”
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
dist2aff.cpp(101) : error C2440: “初始化”: 无法从“mwIndex *”转换为“int *”
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
dist2aff.cpp(102) : error C2440: “初始化”: 无法从“mwIndex *”转换为“int *”
与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
dist2aff.cpp(104) : warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据
打开文件dist2aff.cpp,把line 90 "const int *"替换为“ const mwSize",等等,根据错误提示进行修改即可。
再次运行test_segimage.m,scale_dist.cpp仍存在类似错误,根据错误提示修改, mex -O -largeArrayDims dist2aff.cpp scale_dist.cpp再次编译即可通过。
二、代码理解
1、function [clusts,bestD]=kmeans2(V,nClusts)
V是laplacian矩阵的前若干个特征向量
不理解的是:为何拿特征向量来用于聚类
——谱聚类的思想:参考http://blog.csdn.net/pi9nc/article/details/12251247
第一步:数据准备,生成图的邻接矩阵;
第二步:归一化普拉斯矩阵;
第三步:生成最小的k个特征值和对应的特征向量;
第四步:将特征向量kmeans聚类(少量的特征向量);