我已经制作了一个在 matlab 中实现的聚类算法的 dll 版本
此外,我下载了输入数据的工作示例(我正在使用玩具问题数据),我正在阅读它并将其转换为 Matlab 已知的数据类型。
但是,在运行算法时出现以下错误:
... MWMCR::EvaluateFunction 错误 ... 连接的矩阵的维度不一致。=> apclusterSparse.m 第 178 行出错。
这是我的代码:(对不起?)
public static double[,] ReadSimilarities()
{
string line;
string[] splittedLine;
System.IO.StreamReader file = new System.IO.StreamReader("C:\\Code\\FCT\\Thesis\\similarities.txt");
List<List<string>> values = new List<List<string>>();
List<string> lineValues;
while ((line = file.ReadLine()) != null)
{
splittedLine = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
lineValues = new List<string>(splittedLine.Count());
for (int i = 0; i < splittedLine.Count(); i++)
{
lineValues.Add(splittedLine[i]);
}
values.Add(lineValues);
}
file.Close();
double[,] result = new double[values.Count, 3];
for (int i = 0; i < values.Count; i++)
{
result[i, 0] = Convert.ToDouble(values.ElementAt(i).ElementAt(0));
result[i, 1] = Convert.ToDouble(values.ElementAt(i).ElementAt(1));
result[i, 2] = Convert.ToDouble(values.ElementAt(i).ElementAt(2));
}
return result;
}
public static double[] ReadPreferences()
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader("C:\\Code\\FCT\\Thesis\\preferences.txt");
List<string> values = new List<string>();
while ((line = file.ReadLine()) != null)
{
values.Add(line);
}
double[] result = new double[values.Count];
for (int i = 0; i < values.Count; i++)
{
result[i] = Convert.ToDouble(values.ElementAt(i));
}
return result;
}
public ActionResult Index()
{
ApClusterSparse apClusterSparse = new ApClusterSparse();
double[,] similarities = ReadSimilarities();
double[] preferences = ReadPreferences();
MWNumericArray matLabSimiliaritiesArray = new MWNumericArray(similarities);
MWNumericArray matLabPreferencesArray = new MWNumericArray(preferences);
MWArray argsOut;
try
{
argsOut = apClusterSparse.apclusterSparse(matLabSimiliaritiesArray, matLabPreferencesArray);
}
catch (Exception e)
{
}
return View();
}
谢谢。