def process(path):

    clicked, lines_evaluated, lines_total = 0, 0, 0

    with open(path) as inf:
        for line in inf:
            lines_total += 1

            # Parsing the log line.
            logline = line.strip().split()
            chosen = int(logline.pop(7))
            user_action = int(logline.pop(7))
            time = int(logline[0])
            user_features = [float(x) for x in logline[1:7]]
            articles = [int(x) for x in logline[7:]]

            # Getting the recommended article.
            calculated = policy.reccomend(time, user_features, articles)

            if not calculated in articles:
                raise Exception("Article was not in the list.")

            # Updating the policy.
            if calculated == chosen:
                policy.update(user_action)
                clicked += user_action
                lines_evaluated += 1
            else:
                policy.update(-1)

        print "Evaluated %d/%d lines." % ( lines_evaluated, lines_total)
        print "CTR=%f" % (float(clicked) /  lines_evaluated)
def main(args):

    if (len(args) != 3):
        raise Exception("Usage: ./evaluator.py articles_file log_file")

    with file(args[1]) as inf:
        articles = []
        for line in inf:
            features = line.strip().split(" ")
            article = [int(features[0])]
            article.extend(float(x) for x in features[1:])
            articles.append(article)
        policy.set_articles(articles)
    
    score = 0
    total_evaluated = 0
    n_lines = 0

    with file(args[2]) as inf:
        for line in inf:
            n_lines += 1
            logline = line.strip().split()
            chosen = int(logline.pop(7))
            reward = int(logline.pop(7))
            time = int(logline[0])
            user_features = [float(x) for x in logline[1:7]]
            articles = [int(x) for x in logline[7:]]

            calculated = policy.reccomend(time, user_features, articles)

            if calculated == chosen:
                policy.update(reward)
                score += reward
                total_evaluated += 1
            else:
                policy.update(-1)

        print "Evaluated %d/%d lines." % (total_evaluated, n_lines)
        print "CTR=%f" % (float(score) / total_evaluated)
예제 #3
0
def process(path):

    clicked, lines_evaluated, lines_total = 0, 0, 0

    with file(sys.argv[2]) as inf:
        for line in inf:
            lines_total += 1

            # Parsing the log line.
            logline = line.strip().split()
            chosen = int(logline.pop(7))
            user_action = int(logline.pop(7))
            time = int(logline[0])
            user_features = [float(x) for x in logline[1:7]]
            articles = [int(x) for x in logline[7:]]

            # Getting the recommended article.
            calculated = policy.reccomend(time, user_features, articles)

            if calculated not in articles:
                raise Exception("Article was not in the list.")

            # Updating the policy.
            if calculated == chosen:
                policy.update(user_action)
                clicked += user_action
                lines_evaluated += 1
            else:
                policy.update(-1)

            if lines_total % 1000 == 0:
                print "Evaluated %d/%d lines." % (lines_evaluated, lines_total)
                print "CTR = %f" % (float(clicked) / lines_evaluated)
                print "Number of articles viewed %d" % len(policy.A.keys())

        print "Evaluated %d/%d lines." % (lines_evaluated, lines_total)
        print "CTR = %f" % (float(clicked) / lines_evaluated)
예제 #4
0
    
    score = 0
    total_evaluated = 0
    n_lines = 0

    with file(sys.argv[2]) as inf:
        for line in inf:
            n_lines += 1
            logline = line.strip().split()
            chosen = int(logline.pop(7))
            reward = int(logline.pop(7))
            time = int(logline[0])
            user_features = [float(x) for x in logline[1:7]]
            articles = [int(x) for x in logline[7:]]

            calculated = policy.reccomend(time, user_features, articles)

            if calculated == chosen:
                policy.update(reward)
                score += reward
                total_evaluated += 1
            else:
                policy.update(-1)

        print "Evaluated %d/%d lines." % (total_evaluated, n_lines)
        print "CTR=%f" % (float(score) / total_evaluated)


    pr.disable()
    ps = pstats.Stats(pr, stream=open("profile.txt", "w"))
    ps.sort_stats("cumtime")
예제 #5
0
        values = [items[1:] for items in articles]
        dictionary = dict(zip(keys, values))
        policy.set_articles(dictionary)
    
    score = 0
    total_evaluated = 0
    n_lines = 0

    with file(sys.argv[2]) as inf:
        for line in inf:
            n_lines += 1
            logline = line.strip().split()
            chosen = int(logline.pop(7))
            reward = int(logline.pop(7))
            time = int(logline[0])
            user_features = [float(x) for x in logline[1:7]]
            articles = [int(x) for x in logline[7:]]


            calculated = policy.reccomend(time, user_features, articles)

            if calculated == chosen:
                policy.update(reward)
                score += reward
                total_evaluated += 1
            else:
                policy.update(-1)

        print "Evaluated %d/%d lines." % (total_evaluated, n_lines)
        print "CTR=%f" % (float(score) / total_evaluated)