Algorithm og:沿每个维度的FFT可沿每行和每列独立执行。因此,一组将采用O(nmlogm),另一组将采用O(mnlogn),总共为O(nm(logn+logm))=O(nmlog(nm))@AndrewTomazos-Fathomling——是的,而且更常见的是用
og:沿每个维度的FFT可沿每行和每列独立执行。因此,一组将采用Algorithm og:沿每个维度的FFT可沿每行和每列独立执行。因此,一组将采用O(nmlogm),另一组将采用O(mnlogn),总共为O(nm(logn+logm))=O(nmlog(nm))@AndrewTomazos-Fathomling——是的,而且更常见的是用,algorithm,math,optimization,Algorithm,Math,Optimization,og:沿每个维度的FFT可沿每行和每列独立执行。因此,一组将采用O(nmlogm),另一组将采用O(mnlogn),总共为O(nm(logn+logm))=O(nmlog(nm))@AndrewTomazos-Fathomling——是的,而且更常见的是用星号写的:[F*W](x)=integral[y](F(x-y)W(y)) int best_x, best_y, best_dist; for x0 = 1:1000, for y0 = 1:1000, int t
O(nmlogm)
,另一组将采用O(mnlogn)
,总共为O(nm(logn+logm))=O(nmlog(nm))
@AndrewTomazos-Fathomling——是的,而且更常见的是用星号写的:[F*W](x)=integral[y](F(x-y)W(y))
int best_x, best_y, best_dist;
for x0 = 1:1000,
for y0 = 1:1000,
int total_dist = 0;
for x1 = 1:1000,
for y1 = 1:1000,
total_dist += W[x1,y1] * sqrt((x0-x1)^2 + (y0-y1)^2);
if (total_dist < best_dist)
best_x = x0;
best_y = y0;
best_dist = total_dist;
F(i,j) = sqrt((n-i)^2 + (m-j)^2)
R = F o W
m=100;
n=100;
W0=abs(randn(m,n))+.001;
tic;
%The following padding is not necessary in the matlab code because
%matlab implements it in the imfilter function, from the imfilter
%documentation:
% - Boundary options
%
% X Input array values outside the bounds of the array
% are implicitly assumed to have the value X. When no
% boundary option is specified, imfilter uses X = 0.
%W=padarray(W0,[m n]);
W=W0;
F=zeros(2*m+1,2*n+1);
for i=1:size(F,1)
for j=1:size(F,2)
%This is matlab where indices start from 1, hence the need
%for m-1 and n-1 in the equations
F(i,j)=sqrt((i-m-1)^2 + (j-n-1)^2);
end
end
R=imfilter(W,F);
[mr mc] = ind2sub(size(R),find(R == min(R(:))));
[mr, mc]
toc;
tic;
T=zeros([m n]);
best_x=-1;
best_y=-1;
best_val=inf;
for y0=1:m
for x0=1:n
total_dist = 0;
for y1=1:m
for x1=1:n
total_dist = total_dist + W0(y1,x1) * sqrt((x0-x1)^2 + (y0-y1)^2);
end
end
T(y0,x0) = total_dist;
if ( total_dist < best_val )
best_x = x0;
best_y = y0;
best_val = total_dist;
end
end
end
[best_y best_x]
toc;
diff=abs(T-R);
max_diff=max(diff(:));
fprintf('The max difference between the two computations: %g\n', max_diff);