Please post your solutions to the Feb 23 In-Class Exercise to this thread.
Best,
Chris
[u, v] = [0, 1]
D = 1
Score = 0
J = 0
U = -inf < inf:
d < docid(u) #False
score = 1 / (1 - 0 + 1) = 0.5
[u, v] = [5, 6]
d < docid(u) #False
score = 0.5 + 1 / (6 -5 + 1) = 1
[u, v] = [3, 5]
d < docid(u) #True
j = 1
Result[1].docid = 1
Result[1].score = 1
d = 2
score = 0
score = 0 + 1 / (5 - 3 + 1) = 0.3
[u, v] = [7, 8]
d < docid(u) #False
score = 0.3 + 1 / (8 - 7 + 1) = 0.8
[u, v] = [inf, inf]
D < inf #True
j = 2
Result[2].docid = 2
Result[2].score = 0.8
#answer:
Result = [
{
docid = 1
score = 1
},
{
docid = 1
score = 0.8
}
]
(Edited: 2022-02-23) d1 = “All the king's horses and all the king's men"
d2 = "Which is correct: all of the people, all the people, or all people?"
rankProximity(“all”, “the”, 2)
For document 1:
[u,v] = [0,1], [1,5], [5,6]
For document 2:
[u,v] = [3,5], [5,7], [7,8], [8,11]
j = 0, d = 1, score = 0
1st score = 0 + 0.5 = 0.5
2nd score = 0.5 + 0.2 = 0.7
3rd score = 0.7 + 0.5 = 1.2
result[1].docid = 1
result[1].score = 1.2
j = 1, d = 2, score = 0
1st score = 0 + 0.33 = 0.33
2nd score = 0.33 + 0.33 = 0.66
3rd score = 0.66 + 0.5 = 1.166
4th score = 1.166 + 0.25 = 1.416
result[2].docid = 2
result[2].score = 1.416
result = [{score = 1.416, doc_id=2},{score = 1.2, doc_id= 1}]
(Edited: 2022-02-23)The return result is doc 2, doc 1 with 1.42, 1.2 scores respectively. The detailed step-by-step analysis is shown below in images.
d1="All the king's horses and all the king's men"
d2 = "Which is correct: all of the people, all the people, or all people?"
rankProximity processing:
'''Initially:'''
u = -infinity
nextCover("all", "the", -infinity) would give us [0:0,0:1]
Thus, [u, v] = [0, 1]
d = 0
score = 0
j = 0
'''Iterating through while loop:'''
1.
docid(u) = 0, d = 0
score += 1/(1-0+1) = 1/2
nextCover("all", "the", 0) would give us [0:1,0:5]
Thus, [u, v] = [1, 5]
2.
docid(u) = 0, d = 0
score += 1/(5-1+1) = 1/2 + 1/5 = 7/10
nextCover("all", "the", 1) would give us [0:5,0:6]
Thus, [u, v] = [3, 5]
3.
docid(u) = 0, d = 0
score += 1/(6-5+1) = 7/10 + 1/2 = 6/5 = 1.2
nextCover("all", "the", 5) would give us [1:3,1:5]
Thus, [u, v] = [3, 5]
4.
docid(u) = 1, d = 0
From if condition (d<docid(u)):
j = 1
Result[1].docid = 0
Result[1].score = 1.16
d = 1
score = 0
score += 1/(5-3+1) = 1/3
nextCover("all", "the", 3) would give us [1:5,1:7]
Thus, [u, v] = [5, 7]
5.
docid(u) = 1, d = 1
score += 1/(7-5+1) = 1/3 + 1/3 = 2/3
nextCover("all", "the", 7) would give us [1:7,1:8]
Thus, [u, v] = [7, 8]
6.
docid(u) = 1, d = 1
score += 1/(8-7+1) = 2/3 + 1/2 = 7/6
nextCover("all", "the", 7) would give us [1:8,1:11]
Thus, [u, v] = [8, 11]
7.
docid(u) = 1, d = 1
score += 1/(11-8+1) = 7/6 + 1/4 = 17/12
nextCover("all", "the", 8) would give us [infinity, infinity]
Thus, [u, v] = [infinity, infinity]
Exiting the while loop and checking the if condition (d<infinity),
j = 2
Result[2].docid = 1
Result[2].score = 17/12 = 1.46
Sorting Result by score and returning top 2 documents:
1. {docid: 1, score: 1.46}
2. {docid: 0, score: 1.2}
''rankProximity(“all”, “the”, 2)
Doc1: [u,v] = [0,1], [1,5], [5,6]
Doc2: [u,v] = [3,5], [5,7], [7,8], [8,11]
j = 0 d = 1 score = 0
Score = score + 1/ (v-u + 1)
Score 1 = 0 + 1 / (1 - 0 + 1) = 0.5 ,
Score 2 = 0.5 + 1 / (5 - 1 + 1) = 0.7,
Score 3 = 0.7 +1 / ( 6 - 5 + 1) = 1.2
result[1].docid = 1 , result[1].score = 1.2
j = 1 d = 2 score = 0
Score 1 = 0 + 1 / (5 - 3 + 1) = 0.3,
Score 2 = 0.3 + 1 / (7 - 5 + 1) = 0.6,
Score 3 = 0.6 + 1 / (8 - 7 + 1) = 1.1,
Score 4 = 1.1+ 1 / (11 - 8 + 1) = 1.35
result[2].docid = 2 , result[2].score = 1.35
After sorting result by score: result = score = 1.35, doc_id =2] , [score = 1.2, doc_id = 1''
(Edited: 2022-02-23)rankProximity(t[1],.., t[n], k) // t[] term vector = all, the // k = 2
{
u := - infty;
[u,v] := nextCover(t[1],.., t[n], u); // for d1 for the first round [0,1]
d := docid(u);
score := 0;
j := 0;
while( u < infty) do
if(d < docid(u) ) then
// if docid changes record info about last docid
j := j + 1; // j = 1
Result[j].docid := d;
Result[j].score := score;
d := docid(u);
score := 0;
score := score + 1/(v - u + 1); // 0+1/(1-0+1 ) = 0.5
[u, v] := nextCover(t[1],.., t[n], u); // next cover [1,5]
//… j = 2
//0+1/(5-1+1) = 0.2
//next cover [5,6]
//j= 3
//0.3 +1/(6-5+1) = 0.5
//end of document
//now second document //[3,5] //j =1 //0+1/(5-3+1)=0.33 //next cover [5,7] //j=2 //0+1/(7-5+1)=0.33 //next cover [7,8] //j=3 //0+1/(8-7+1)=0.5 //next cover[8,11] //j=4 //0+1/(11-8+1)= 0.25 //end of document
if(d < infty) then
// record last score if not recorded
j := j + 1; //1
Result[j].docid := d;//docid = 1
Result[j].score := score; //score: 1.2
// second result : docid = 2, score = 1.41
sort Result[1..j] by score; return Result[1..k];
Results: 1. Docid:1, score: 1.2
2. Docid:2 score 1.41(Edited: 2022-02-23)