AD Teaching Wiki
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

FrontPage

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 16 as of 2016-02-23 15:20:18
AD Teaching Wiki:
  • InformationRetrievalWS1516
  • ExamSolutions

TASK 1 (Ranking and evaluation)

bla   1  1  2  2  3
bli   1  0  1  2  2
blu   0  1  1  0  1

1.1 AP for query "bla bli"

The vector for "bla blu" is simply (1, 0, 1)
Dot product similarities for D1, ..., D5: 1, 2, 3, 2, 4
Documents ordered by these similarities: D5, D3, D2 and D4, D1  (D2 and D4 have the same score)
Bit array of relevances: 1, 0, 0, 0, 1
Precisions: P@1 = 100%, P@5 = 40%  (the others are not needed to compute the AP)
Average precision (AP): 70%

1.2 Function compute_ap

def compute_ap(relevances):
    prec_sum = 0
    num_rel = 0
    for i in range(len(relevances)):
        if relevances[i] == 1:
            num_rel += 1
            prec = num_rel / (i + 1)
            prec_sum += prec
    return prec_sum / num_rel

1.3 Prove that AP = 100% if and only if all 1s at the front

If all 1s at the front, then each prec in the code above is 100%, and so will be the average.

If AP = 100%, then the last prec must be 100%, which can only happen if there is no 0 before the last 1.

1.4 Write A as product of 3 x 2 and 2 x 5 ... what does this say about rank(A)

1  1  2  2  3       1  1
1  0  1  2  2   =   1  0  *  1  0  1  2  2 
0  1  1  0  1       0  1     0  1  1  0  1

This shows that each column of A can be written as a linear combination of the two columns of the 3 x 2 matrix on the right hand side. This proves that rank(A) <= 2.

TASK 2 (Encodings)

c(1) = 1, c(2) = 01, c(3) = 001, c(4) = 0001, ...

2.1 Decode 110000100111001 + why prefix-free

Integer sequence encoded: 1, 1, 5, 3, 1, 1, 3

All valid codes end in 1. Any non-empty prefix of any of the codes ends with a zero. Therefore, no prefix of any of the code is a valid code.

2.2 Function decode

def decode(bits):
    x = 0
    result = []
    for bit in bits:
        x += 1
        if bit == 1:
            result.append(x) 
            x = 0
    return result if x == 0 else []

2.3 Random code, 0 or 1 with probability 1/2 each until 1

The code for x has exactly x bits. The probability of generating exactly those x bits with the process described is 1/2 * ... * 1/2 (x times), that is, 2 to the -x.

2.4 Entropy-optimality for this probability distribution

Let L_i be the length of the code for integer i. Then L_i = i.

The probability p_i of generating that code is 2^-i (according to Task 2.3).

For entropy-optimality, we need L_i <= log_2 (1/p_i) + 1 = i + 1. This is true.

TASK 3 ()

$(document).ready(function() {
  $("#query").keyup(function() {
    var query = $("#query").val();
    $.get("http://www.gugel.de:8888/?q="+ query, function(result) {
      $("#result").html(result);
    })
  })
})

3.1 Simple HTML that makes sense for this JavaScript (without head part)

<html>
  <body>
    <input id="query"/>
    <div id="result"></div>
  </body>
</html>

3.2 First fifteen characters of GET requests when typing "hey" + to which machine

GET /?q=h HTTP/
GET /?q=he HTTP
GET /?q=hey HTT

The requests are sent to the machine with the address www.gugel.de

3.3 Number of valid UTF-8 sequences of length 2

Valid UTF-8 sequences of length 2 look like this

110xxxxx 10yyyyyy

where the 11-bit codepoint xxxxxyyyyyy encodes an integer that must be > 127 (otherwise a one-byte UTF-8 must be used).

The number of such codepoints is 2048 - 128 = 1920.

3.4 UTF-8 code and URL-escaped code of ΓΌ

ISO-8859-1 code in binary: 11111100
With padding, so that 11 bits: 00011111100
As UTF-8 code: 11000011 10111100 (Byte 1: 110 + first five bits of codepoint, Byte 2: 10 + last five bits)
In decimal: 195 188
In hexadecimal: C3 BC
URL-escaped: %C3%BC

TASK 4 (Perceptrons)

Training set: {1, 2, 3, 4} (negative), {5, 6, 7, 8} (positive)

4.1 First round of Perceptron algorithm

x = 1: w * x - b =  0  -->  update: w = 0 - 1 = -1, b = 0 + 1 = 1
x = 2: w * x - b = -3  -->  no update
x = 3: w * x - b = -4  -->  no update
x = 4: w * x - b = -5  -->  no update
x = 5: w * x - b = -6  -->  update: w = -1 + 5 = 4, b = 1 - 1 = 0
x = 6: w * x - b = 24  -->  no update
x = 7: w * x - b = 28  -->  no update
x = 8: w * x - b = 32  -->  no update

4.2 Function perceptron

def perceptron():
    (w, b) = (0, 0)
    for round in range(50):
        for x in [1, 2, 3, 4, 5, 6, 7, 8]:
            if x <= 4 and w * x - b >= 0:
                (w, b) = (w - x, b + 1)
            if x >= 5 and w * x - b <= 0:
                (w, b) = (w + x, b - 1)
    return (w, b)

4.3 Prove ww* = - w* and bb* = -b when training labels swapped

Let wi, bi and wwi, bbi as in the hint. Then we can prove by induction that wwi = -wi and bbi = -bi:

In the beginning, all values are zero, so correct.

Assume that wwi = -wi and bbi = -bi after iteration i and look at what happens in iteration i+1. There are four cases:

1. x negative in original, no update --> x positive in variant, no update 2. x positive in original, no update --> x negative in variant, no update 3. x negative in original, update (wi+1, bi+1) = (wi - x, bi + 1) --> x positive in variant, update (wwi+1, bbi+1) = (wwi + x, bbi - 1) 4. x positive in original, update (wi+1, bi+1) = (wi + x, bi - 1) --> x negative in variant, update (wwi+1, bbi+1) = (wwi - x, bbi + 1)

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01