week2/pagerank/pagerank.py
def transition_model(corpus, page, damping_factor):
    """
    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    """
    distribution = {}
    links = len(corpus[page])

    if links:            
        for link in corpus:
            distribution[link] = (1 - damping_factor) / len(corpus)

        for link in corpus[page]:
            distribution[link] += damping_factor / links
    else:
        for link in corpus:
            distribution[link] = 1 / len(corpus)
    
    return distribution

    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    
Return a probability distribution over which page to visit next,
given a current page.

With probability `damping_factor`, choose a link at random
linked to by `page`. With probability `1 - damping_factor`, choose
a link at random chosen from all pages in the corpus.
Return a probability distribution over which page to visit next given a current page . With probability ` damping_factor ` choose a link at random linked to by ` page ` . With probability ` 1 - damping_factor ` choose a link at random chosen from all pages in the corpus .
def transition_model(corpus, page, damping_factor):
    distribution = {}
    links = len(corpus[page])
    if links:            
        for link in corpus:
            distribution[link] = (1 - damping_factor) / len(corpus)
        for link in corpus[page]:
            distribution[link] += damping_factor / links
    else:
        for link in corpus:
            distribution[link] = 1 / len(corpus)
    return distribution
def transition_model ( corpus , page , damping_factor ) : distribution = { } links = len ( corpus [ page ] ) if links : for link in corpus : distribution [ link ] = ( 1 - damping_factor ) / len ( corpus ) for link in corpus [ page ] : distribution [ link ] += damping_factor / links else : for link in corpus : distribution [ link ] = 1 / len ( corpus ) return distribution
Return a probability distribution over which page to visit next,
given a current page.
Return a probability distribution over which page to visit next given a current page .
"""
    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    """
corpus
page
damping_factor