Beispiel #1
0
def pagerank_reducer(node, values):
    """Compute the new PageRank for the node"""
    try:
        # sort because we want the 'infos' value at the end of the list
        values = sorted([v for v in values]) # as values is a generator
        damping = float(prince.get_parameters('damping'))
        infos = values[-1].split()

        pr_previous = float(infos[2])
        nodes_adjacent = [int(n) for n in infos[3:]]
        pageranks = [float(v) for v in values[:-1]]

        nb_nodes = float(prince.get_parameters('nb_nodes'))
        pr_new = (1.0 - damping) / nb_nodes + damping * sum(pageranks)
        yield (node, make_value(pr_previous, pr_new, nodes_adjacent))
    except ValueError:
        pass
Beispiel #2
0
def pagerank_reducer(node, values):
    """Compute the new PageRank for the node"""
    try:
        # sort because we want the 'infos' value at the end of the list
        values = sorted([v for v in values])  # as values is a generator
        damping = float(prince.get_parameters('damping'))
        infos = values[-1].split()

        pr_previous = float(infos[2])
        nodes_adjacent = [int(n) for n in infos[3:]]
        pageranks = [float(v) for v in values[:-1]]

        nb_nodes = float(prince.get_parameters('nb_nodes'))
        pr_new = (1.0 - damping) / nb_nodes + damping * sum(pageranks)
        yield (node, make_value(pr_previous, pr_new, nodes_adjacent))
    except ValueError:
        pass
Beispiel #3
0
def term_reducer(key, pagerank_changes):
    """Check whether the values are converging using the quadratic norm"""
    try:
        precision = float(prince.get_parameters('precision'))
        if sum([float(p) ** 2 for p in pagerank_changes]) > precision ** 2:
            return 0, 0 # let's do another iteration
    except ValueError:
        pass # the algorithm is stopped in case of error
    return 1, 1
Beispiel #4
0
def term_reducer(key, pagerank_changes):
    """Check whether the values are converging using the quadratic norm"""
    try:
        precision = float(prince.get_parameters('precision'))
        if sum([float(p)**2 for p in pagerank_changes]) > precision**2:
            return 0, 0  # let's do another iteration
    except ValueError:
        pass  # the algorithm is stopped in case of error
    return 1, 1
Beispiel #5
0
def frontier_mapper(key, value):
    """Expand the frontier of one hop."""
    (node, d_previous, d_current) = node_info(value)
    if node != None:
        yield node, '%d %d' % (d_current, d_current) # reinject itself
        if d_current != d_previous: # expand only if distance has changed
            graph = read_graph(prince.get_parameters('graph'))
            for node_adjacent in graph[node]:
                yield node_adjacent, '%d %d' % (sys.maxint, d_current + 1)
Beispiel #6
0
def frontier_mapper(key, value):
    """Expand the frontier of one hop."""
    (node, d_previous, d_current) = node_info(value)
    if node != None:
        yield node, '%d %d' % (d_current, d_current)  # reinject itself
        if d_current != d_previous:  # expand only if distance has changed
            graph = read_graph(prince.get_parameters('graph'))
            for node_adjacent in graph[node]:
                yield node_adjacent, '%d %d' % (sys.maxint, d_current + 1)