-1

I am trying to implement the Johnson-Lindenstrauss lemma. I have search for the pseudocode here but could not get any.

I don't know if I have implemented it correctly or not. I just want you guys who understand the lemma to please check my code for me and advice me as to the correct matlab implementation.

n = 2;
d = 4;
k = 2;
G = rand(n,d);
epsilon = sqrt(log(n)/k);

% Projection in dim k << d 
% Defining P (k x d) 
P = randn(k,d); 

% Projecting down to k-dim
proj = P.*G;
u = proj(:,1); 
v = proj(:,2); 
% u = P * G(:,5); 
% v = P * G(:,36); 
norm(G(:,1)-G(:,2))^2 * k * (1-epsilon); 
norm(u - v)^2; 
norm(G(:,1)-G(:,2))^2 * k * (1+epsilon);
Oleg
  • 10,406
  • 3
  • 29
  • 57
elizwet
  • 11
  • 4
  • which lemma are you trying to code. what is the input and output of the code. I checked the page you mentioned but there are lots of lemmas and facts. – NKN Aug 12 '13 at 19:39
  • The first lemma. The lemma which contains this: (1-\epsilon)\|u-v\|^2\le\|f(u)-f(v)\|^2\le(1+\epsilon)\|u-v\|^2. – elizwet Aug 12 '13 at 19:43

3 Answers3

0

for the first part of that to find the epsilon you need to solve a polynomial equation.

n = 2;
k = 2;
pol1 = [-1/3 1/2 0 4*log2(n)/k];
c = roots(pol1)

    1.4654 + 1.4304i
    1.4654 - 1.4304i
   -1.4308 + 0.0000i

Then you need to remove the complex roots and keep the real one:

epsilon = c(imag(c)==0);

% if there are more than one root with imaginary part equal to 0 then you need to select the smaller one.

now you know that the epsilon should be equal or greater that the result.

NKN
  • 6,482
  • 6
  • 36
  • 55
  • why is this epsilon = sqrt(log(n)/k); not correct? How can i know that my implementation of the lemma is correct or not? What i do to see if my implementation of the lemma is correct or not is looking at norm(u - v)^2; if the value lie between norm(G(:,1)-G(:,2))^2 * k * (1-epsilon); and norm(G(:,1)-G(:,2))^2 * k * (1+epsilon); inclusive, then i conclude it is right? I don't know if that is a way of knowing wether the implementation of the lemma is correct or not. Is there anyway one can know correctly if the implementation is right or not? – elizwet Aug 12 '13 at 20:32
0

For any set of m points in R^N and for k = 20*logm/epsilon^2 and epsilon < 1/2:

1/sqrt(k).*randn(k,N)

obtain Pr[success]>=1-2m^(5*epsilon-3)

hoom
  • 41
  • 1
  • 7
0

An R package is available to perform Random projection using Johnson Lindenstrauss Lemma RandPro

Siddhu
  • 1,188
  • 2
  • 14
  • 24