带有 kmeans return 0 的 Matlab cputime
Matlab cputime with kmeans return 0
我正在使用 cputime 功能测量 kmeans 算法每次迭代所占用的 cputime。但是,一些迭代 return cputime = 0。这是我的实现:
load fisheriris;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Display', 'off');
results=[];
for i = 1:15
t=cputime;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Start',C, 'Display', 'off');
elapsedCPUTime=cputime-t;
results=[results;elapsedCPUTime];
end
这是我迭代 15 次得到的结果:0, 0, 0.046875, 0, 0, 0, 0, 0, 0.03125, 0, 0, 0, 0, 0 ,0.03125。我的第一个想法是计算时间太快,因此为 0 秒。是真的吗?如果是这样,我们如何才能获得更精确的cputime?
非常感谢。
To measure performance, it is recommended that you use the timeit or
tic and toc functions. For more information, see Using tic and toc Versus the cputime Function.
接下来 link:
Time a significant enough portion of code. Ideally, the code you are timing should take more than 1/10 second to run.
循环尝试 运行 kmeans
。
load fisheriris;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Display', 'off');
results=[];
for ii = 1:15
t=cputime;
for k = 1:100
[~,Ctemp] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Start',C, 'Display', 'off');
end
elapsedCPUTime=(cputime-t)/100;
C = Ctemp;
results=[results;elapsedCPUTime];
end
使用 i
作为循环变量可能会产生 unexpected results,这就是我将其更改为 ii
.
的原因
我正在使用 cputime 功能测量 kmeans 算法每次迭代所占用的 cputime。但是,一些迭代 return cputime = 0。这是我的实现:
load fisheriris;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Display', 'off');
results=[];
for i = 1:15
t=cputime;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Start',C, 'Display', 'off');
elapsedCPUTime=cputime-t;
results=[results;elapsedCPUTime];
end
这是我迭代 15 次得到的结果:0, 0, 0.046875, 0, 0, 0, 0, 0, 0.03125, 0, 0, 0, 0, 0 ,0.03125。我的第一个想法是计算时间太快,因此为 0 秒。是真的吗?如果是这样,我们如何才能获得更精确的cputime?
非常感谢。
To measure performance, it is recommended that you use the timeit or tic and toc functions. For more information, see Using tic and toc Versus the cputime Function.
接下来 link:
Time a significant enough portion of code. Ideally, the code you are timing should take more than 1/10 second to run.
循环尝试 运行 kmeans
。
load fisheriris;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Display', 'off');
results=[];
for ii = 1:15
t=cputime;
for k = 1:100
[~,Ctemp] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Start',C, 'Display', 'off');
end
elapsedCPUTime=(cputime-t)/100;
C = Ctemp;
results=[results;elapsedCPUTime];
end
使用 i
作为循环变量可能会产生 unexpected results,这就是我将其更改为 ii
.