-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_test_database.m
More file actions
81 lines (73 loc) · 1.35 KB
/
generate_test_database.m
File metadata and controls
81 lines (73 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%% Data generation
n=10^3;
L=1024;
db=false(n,L);
for i=1:n/1000
a=rand(1000,1024);
for j=1:1000
db((i-1)*1000+j,:)=a(j,:)>median(a(j,:));
end
end
%% test validity
k=0;
min_dist_in_db=1;
for i=1:n
for j=i+1:n
temp=sum(xor(db(i,:),db(j,:)));
if temp<=256
k=k+1;
disp([i,j]);
elseif temp<(min_dist_in_db*L)
min_dist_in_db=(temp/L);
end
end
end
%% Data generation 2
%% half of DB
n=10^7;
L=1024;
th=0.4;
db_temp=false(ceil(sqrt(n)),L/2);
j=1;
a=rand(1,L/2);
db_temp(1,:)=a<median(a);
for i=1:n
if j>=sqrt(n);
break;
end
a=rand(1,L/2);
temp=a<median(a);
add=true;
for k=1:j
if sum(xor(temp,db_temp(k,:)))<(th*L/2);
add=false;
break;
end
end
if add
j=j+1;
db_temp(j,:)=temp;
end
end
%% test
min_dist_in_db=L/2;
a=true;
for i=1:j
for k=i+1:j
temp=sum(xor(db_temp(i,:),db_temp(j,:)));
if temp<=(th*L/2)
a=false;
break;
end
if temp<=min_dist_in_db
min_dist_in_db=temp;
end
end
end
%% full DB
db=false(j^2,L);
for i=1:j
for k=1:j
db((i-1)*j+k,:)=[db_temp(i,:),db_temp(k,:)];
end
end