Getting inf in matrix?

I wrote a code where I’m implementing an algorithm. The code works, but the values in my Z matrix are all inf and I don’t know why. I added a picture so you can see it. r in R^d should a sample drawn uniformly at random from the Fourier transformation of the Gaussian kernel. Gamma is just numbers uniformly at random in (0,2pi). cos(...) is at maximum 1, so I don’t understand why I get inf. Help is appreciated!
n=2000;
d=1000;
s=50;
Gamma=10;
S=randn(n,s);
U=qr(randn(s,d));
F=randn(n,d);
D=zeros(s,s);
for i=1:s
D(i,i)=1-(i-1)/d;
end
X = S*D*U + F/Gamma;
% This is the data matrix
-----------------------------------
function [G_2] = rnca(A,m)
[n,d]=size(A);
G=zeros(n,n);
for k=1:n
for j=1:n
G(k,j)=(1/2*pi)^(d/2)*exp(-norm(A(k,:)-A(j,:))^2/2);
end
end
Z=zeros(n,m);
gamma=0+(2*pi-0)*rand(1,m);
D=fft(G);
r=D(randsample(size(D,1),m),1:d);
for i=1:n
for l=1:m
Z(i,l)=sqrt(2/m)*cos(dot(r(l,:),A(i,:))+gamma(l));
end
end
G_2=Z*Z';
end

7 件のコメント

James Tursa
James Tursa 2020 年 4 月 19 日
We can't run pictures. Please post your code as text.
Walter Roberson
Walter Roberson 2020 年 4 月 19 日
r is not in R^d because the fourier transform is complex valued. You are taking cos of a complex number and the result of that has value that is exponential growth.
Desiree
Desiree 2020 年 4 月 19 日
So how can I fix it?
Walter Roberson
Walter Roberson 2020 年 4 月 19 日
is your expectation that the fft will produce a lot of values that are exactly 0? doesn't happen much due to roundoff even for cases that theory say should be 0.
Desiree
Desiree 2020 年 4 月 19 日
The values of fft(G) are huge... which I guess it isn't supposed to be...
Walter Roberson
Walter Roberson 2020 年 4 月 19 日
what is mean(G)?
Desiree
Desiree 2020 年 4 月 19 日
Now I discovered that I missed () when defining G matrix as I forgot to put () on 2*pi.
Now indeed the fft(G) reproduces lots of 0 values and Z ain't inf anymore. So I guess now it is fine?

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGamma Functions についてさらに検索

タグ

質問済み:

2020 年 4 月 19 日

コメント済み:

2020 年 4 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by