-
Notifications
You must be signed in to change notification settings - Fork 2
/
compute_dayweek.m
67 lines (64 loc) · 2.35 KB
/
compute_dayweek.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
% compute the similarity in day of week
dayweek=zeros(Ncrimes,Ncrimes);
% if both are weekday or weekends, 1, if one of them is early week, 1, if one of them is late week, 0.8
% if the weekday/weekend type is unknown, this feature is not included in the summation
weekday={'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday','Weekend','Weekend Unknown','Early Week','Late Week'};
% the above categories are from the training data
for i=1:Ncrimes
d1=zeros(1,2);
if isempty(strmatch(dayweek_data(i),weekday,'exact'))
dayweek(i,:)=zeros(1,h);
else
index1=strmatch(dayweek_data(i),weekday,'exact');
if index1<6
d1(1)=1;% 1 indicates weekday
if index1<4
d1(2)=1;% 1 indicates early week
else d1(2)=2;
end
elseif index1>5 & index1<10
d1(1)=2;% 2 indicates Weekend
d1(2)=2;% 2 indicates Late Week
elseif index1==10
d1(2)=1;%Early Week
elseif index1==11
d1(2)=2;%Late Week
else error('error i');
end
for j=(i+1):Ncrimes
if isempty(strmatch(dayweek_data(j),weekday,'exact'))
dayweek(i,j)=0;
else
index2=strmatch(dayweek_data(j),weekday,'exact');
if index2<6
d2(1)=1;% 1 indicates weekday
if index2<4
d2(2)=1;% 1 indicates early week
else d2(2)=2;
end
elseif index2>5 & index2<10
d2(1)=2;% 2 indicates Weekend
d2(2)=2;% 2 indicates Late Week
elseif index2==10
d2(2)=1;
elseif index2==11
d2(2)=2;
else index2
error('error j');
end
% compare the weekday weekend type
if d1(1)==d2(1) & d1(1)*d2(1)
dayweek(i,j)=1;
elseif d1(1)*d2(1)==0 & d1(2)==d2(2)
if d1(2)==1
dayweek(i,j)=1;
elseif d1(2)==2
dayweek(i,j)=0.8;
else error('error compare');
end
else dayweek(i,j)=0;
end
end
end
end
end