-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectorApproximationFile.m
121 lines (86 loc) · 2.13 KB
/
VectorApproximationFile.m
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%Creating Vector Approximation file
%p1task1;
b = input('Enter the value of b: ');
word_file = csvread('wordfiles/epidemic_word_file.csv');
VperFile = 0;
file_index = 1;
for i = 1:length(word_file)
if file_index == word_file(i)
VperFile = VperFile + 1;
else break;
end
end
VperState = 0;
for i = 1:VperFile
if word_file(i,2) == 1
VperState = VperState + 1;
else
break
end
end
num_states = word_file(VperFile,2);
file_count = length(word_file)/VperFile;
s = size(word_file);
data = word_file(:,4:end);
vector_approximations = [];
for f = 1:file_count
file_approximation = [];
for i = 1:num_states
word_sum = 0;
for j = ((f-1)*VperFile+(i-1)*VperState+1):((f-1)*VperFile+i*VperState)
for k = 1:(s(2)-3)
word_sum = word_sum + data(j,k);
end
end
word_sum = word_sum/(VperState*(s(2)-3));
file_approximation = [file_approximation;word_sum];
end
vector_approximations = [vector_approximations,file_approximation];
end
d = num_states;
%B = zeros(d,1);
for j = 1:d
if j<=mod(b,d)
B(j) = floor(b/d)+1;
else
B(j) = floor(b/d);
end
end
partition_points = {};
for i = 1:d
%partition_points{i} = linspace(0,1,B(i)+2);
partition_points{i} = linspace(0,1,2^B(i)+1);
end
VA_data = [];
for i = 1:file_count
VA_file = [];
for j = 1:d
for k = 1:length(partition_points{j})
if vector_approximations(j,i)<=partition_points{j}(k)
VA_file = [VA_file,k-2];
break;
end
end
end
VA_data = [VA_data;VA_file];
end
VA = {};
for i = 1:file_count
VA1 = [];
for j = 1:d
VA1 = [VA1,dec2bin(VA_data(i,j))];
end
%VA{i} = dec2bin(str2num(VA1));
VA{i} = VA1;
end
for i = 1:length(VA)
VA_length(i) = length(VA{i});
end
num_bytes = whos('VA');
% for i = 1:length(VA)
%
% disp(VA{i});
%
% end
save VA;
disp(strcat('Size of the index structure is ',20,num2str(num_bytes.bytes),' Bytes'));