稀疏矩阵乘法,如 C++ 中的 (maxmin);使用 Octave 库
我正在实现一个 maxmin 函数,它的工作原理类似于矩阵乘法,但它不是对乘积求和,而是逐点获取两个数字之间的最小值的最大值。简单实现的一个例子是
double mx = 0;
double mn = 0;
for (i = 0; i < rowsC;i++)
{
for(j = 0; j < colsC;j++)
{
mx = 0;
for(k = 0; k < colsA; k++)
{
if (a(i, k) < b(k, j))
mn = a(i,k);
else
mn = b(k,j);
if (mn > mx)
mx = mn;
}
c(i, j) = mx;
}
}
我将其编码为 Octave oct 文件,因此我必须使用 oct.h 数据结构。问题是我想实现一个稀疏版本,但通常您需要引用行或列中的下一个非零元素,如本示例所示(请参阅4.3算法): http://www.eecs.harvard.edu/ ~ellard/Q-97/HTML/root/node20.html
执行 row_p->next 给出了该行的下一个非零元素(对于列也是如此)。有没有办法对 Octave SparseMatrix 类执行相同的操作?或者是否有另一种方法可以采用我的 maxmin 函数来实现稀疏矩阵乘法?
I'm implementing a maxmin function, it works like matrix multiplication but instead of summing products it gets max of min between two numbers pointwise. An example of naive implementation is
double mx = 0;
double mn = 0;
for (i = 0; i < rowsC;i++)
{
for(j = 0; j < colsC;j++)
{
mx = 0;
for(k = 0; k < colsA; k++)
{
if (a(i, k) < b(k, j))
mn = a(i,k);
else
mn = b(k,j);
if (mn > mx)
mx = mn;
}
c(i, j) = mx;
}
}
I'm coding it as an Octave oct-file so i have to use oct.h data structure. The problem is that i want to implement a sparse version, but usually you need a reference to the next non zero element in a row or in a column like in this example (see 4.3 algorithm):
http://www.eecs.harvard.edu/~ellard/Q-97/HTML/root/node20.html
There doing row_p->next gave the next nonzero element of the row (the same for the column). Is there a way to do the same with the octave SparseMatrix class? Or is there another way of implementing the sparse matrix multiplication i can adopt for my maxmin function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道是否有人会感兴趣,但我设法找到了解决方案。
该解决方案的代码是Octave模糊逻辑核心包fl-core1.0的一部分,并在LGPL许可下发布。
(该代码依赖于一些八度函数)
I don't know if anyoe would ever be interested, but i managed to find a solution.
The code of the solution is part of fl-core1.0 a fuzzy logic core package for Octave and it is released under LGPL license.
(The code relies on some octave functions)