Apply the HITS algorithm to a network with four pages (nodes) A, B, C, and D, arranged in a chain:
A-->B-->C-->D
Compute the hubbiness and authority of each of these pages (scale doesn't matter, because you only have to identify pages with the same hubbiness or the same authority). Which of the following is FALSE.
In [6]:
import numpy as np
A = np.array([[0, 0, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0]])
mat1 = (A.T).dot(A)
print mat1
a = np.array([.25, .25, .25, .25])
for i in xrange(3):
a = mat1.dot(a)
print a
mat2 = (A).dot(A.T)
print mat2
h = np.array([.25, .25, .25, .25])
for i in xrange(3):
h = mat2.dot(h)
print h
In [10]:
A = np.array([[0,1,1,1,1],
[1,0,1,1,1],
[1,1,0,1,1],
[1,1,1,0,1],
[1,1,1,1,0]])
D = np.array([[4,0,0,0,0],
[0,4,0,0,0],
[0,0,4,0,0],
[0,0,0,4,0],
[0,0,0,0,4]])
L = D - A
s = 0
## output the sum of squares in laplacian matrix for G
for row in L:
s += row.dot(row)
print s
Consider the following MapReduce algorithm. The input is a collection of positive integers. Given integer X, the Map function produces a tuple with key Y and value X for each prime divisor Y of X. For example, if X = 20, there are two key-value pairs: (2,20) and (5,20). The Reduce function, given a key K and list L of values, produces a tuple with key K and value sum(L) i.e., the sum of the values in the list.
Suppose we process the input 9, 15, 16, 23, 25, 27, 28, 56, using a Combiner. There are 4 Map tasks and 1 Reduce task. The first Map task processes the first two inputs, the second the next two, and so on. How many input tuples does the Reduce task receive?
Mapper procedure:
So reducer will get 8 pairs
Advertiser Bid Spend A $1 $20 B $2 $40 C $3 $60 D $4 $80
In [12]:
import math
def phi(bid, spent, budget):
frac = 1 - float(spent) / budget
return bid * (1 - math.exp( - frac) )
print "A's phi value = {}".format(phi(1, 20, 100))
print "B's phi value = {}".format(phi(2, 40, 100))
print "C's phi value = {}".format(phi(3, 60, 100))
print "D's phi value = {}".format(phi(4, 80, 100))
* r1 - 2r2
* 2r1 - r2 √
* r2 - r1
* r1 - r2
In [ ]: