在MATLAB中查找中位数需要很长时间。

huangapple go评论57阅读模式
英文:

Finding median in MATLAB taking a lot of time

问题

我有一个名为X的行向量,我想找到它的中位数。我正在使用MATLAB的函数median()来找到中位数,但它正在成为我的代码瓶颈。

是否有其他语言中用于查找中位数的更快实现?

英文:

I have a row vector X for which I want to find the median.
I am using MATLAB's function median() to find the same but it is proving to be the bottleneck in my code.

Is there a faster implementation available for finding median in any other language?

答案1

得分: 2

我成功地通过数个数量级提高了计算速度,但没有采用不同的实现方式。相反,我只是将向量转换为gpuArray,然后传递给median()函数。对于较大的向量,这减少了计算时间数个数量级。但对于较短的数组,这会减慢速度,我认为这是因为时间花在了将向量传输到GPU内存上。我发现向量的过渡长度约为450。对于长度小于450的向量,直接将向量传递给median()函数更好,而对于更长的向量,将其转换为gpuArray,然后传递给median()函数更快。

英文:

I was able to improve the speed of calculation by several orders of magnitude but not by a different implementation.
Rather, I just converted the vector into a gpuArray and then fed into the median() function. For large vectors this reduced the time of calculation by several orders of magnitude. But slowed things down for shorter arrays, I believe this is because time was being used up in transferring the vector to memory in gpu.
I found the transition length of the vector to be ~450. That is for vectors shorter than 450 directly feeding the vector into the median() function is better and for longer ones converting to gpuArray and then feeding into the median() function is faster.

huangapple
  • 本文由 发表于 2023年5月24日 17:46:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定