コード例 #1
0
def sort_tgts(ranking_list, judge_weights):
    """ Use the ranking list to build a total ordering
    of the ranked translations (indicated by Ranking.sys{1,2}_id

    Args:
    Returns:
    Raises:
    """
    # Aggregate ranking counts
    di_edges = Counter()
    eq_edges = Counter()
    edge_counts = Counter()
    vertices = set()
    for ranking in ranking_list:
#        print str(ranking)
        vertices.add(ranking.sysA)
        vertices.add(ranking.sysB)
        edge = (ranking.sysA,ranking.sysB)
        edge_counts[edge] += 1
        if ranking.rank == 0:
            eq_edges[edge] += 1
        else:
            di_edges[edge] += 1

    # SPECIAL CASE: Equality
    # TODO(spenceg): A. Lopez discarded this data as a pre-processing
    # step. That is clearly bad.
    # Do naive approach and assert equality if that ranking is in
    # the majority
    for (a,b),n_eq in eq_edges.iteritems():
        n_eq += eq_edges[(b,a)]
        total = edge_counts[(a,b)] + edge_counts[(b,a)]
        perc_eq = float(n_eq) / float(total)
        if perc_eq >= 0.5:
            di_edges[(a,b)] = 0
            di_edges[(b,a)] = 0

    # Filter edges by only allowing one directed edge between
    # vertices. Edge weights are non-negative, and indicate
    # victories.
    tournament = Counter()
    for (a,b) in di_edges.keys():
        ab_cost = di_edges[(a,b)]
        if (b,a) in di_edges:
            ba_cost = di_edges[(b,a)]
            cost_diff = ab_cost - ba_cost
            if cost_diff > 0:
                tournament[(a,b)] = cost_diff
            elif cost_diff < 0:
                tournament[(b,a)] = -1 * cost_diff
        elif ab_cost > 0:
            tournament[(a,b)] = ab_cost
            
    # Generate the ranking
    vertices = list(vertices)
    #vertices = run_lopez_mfas_solver(tournament, vertices)
    ranking = mfas_solver.lopez_solver(tournament, vertices)

    # Sanity check
    assert len(ranking) == len(vertices)

    # Return a vector of Booleans identifying if
    # the corresponding vertex is tied with the previous vertex.
    # This is naive (and wrong) since transitivity cannot be asserted
    # from the rankings.
    tie_with_prev = mark_ties(ranking, di_edges)
    
    return make_rows(ranking, tie_with_prev)
コード例 #2
0
def sort_tgts(ranking_list):
    """ Use the ranking list to build a total ordering
    of the ranked translations (indicated by Ranking.sys{1,2}_id

    Args:
    Returns:
    Raises:
    """
    # Aggregate ranking counts
    di_edges = Counter()
    eq_edges = Counter()
    edge_counts = Counter()
    vertices = set()
    for ranking in ranking_list:
#        print str(ranking)
        vertices.add(ranking.sysA)
        vertices.add(ranking.sysB)
        edge = (ranking.sysA,ranking.sysB)
        edge_counts[edge] += 1
        if ranking.rank == 0:
            eq_edges[edge] += 1
        else:
            di_edges[edge] += 1

    # SPECIAL CASE: Equality
    # TA. Lopez discarded this data as a pre-processing
    # step. That is clearly bad since a single pairwise ranked judgment could
    # subsume all equality judgments.
    # Assert equality if equality is the majority pairwise judgment
    # TODO(spenceg): The Lopez implementation returns different
    # results if 0-weight edges are included in the tournament. Weird?
    for (a,b),n_eq in eq_edges.iteritems():
        n_eq += eq_edges[(b,a)]
        total = edge_counts[(a,b)] + edge_counts[(b,a)]
        perc_eq = float(n_eq) / float(total)
        if perc_eq >= 0.5:
            del di_edges[(a,b)]
            del di_edges[(b,a)]
        #if not (a,b) in di_edges:
        #    di_edges[(a,b)] = 0
        #if not (b,a) in di_edges:
        #    di_edges[(a,b)] = 0

    # Filter edges by only allowing one directed edge between
    # vertices. Edge weights are non-negative, and indicate
    # victories.
    tournament = Counter()
    for (a,b) in di_edges.keys():
        ab_cost = di_edges[(a,b)]
        assert ab_cost >= 0
        if (b,a) in di_edges:
            ba_cost = di_edges[(b,a)]
            cost_diff = ab_cost - ba_cost
            if cost_diff > 0:
                tournament[(a,b)] = cost_diff
            elif cost_diff < 0:
                tournament[(b,a)] = -1 * cost_diff
        else:
            tournament[(a,b)] = ab_cost
            
    # Generate the ranking
    vertices = list(vertices)
    # Call the reference Lopez implementation
    ranking = mfas_solver.lopez_solver(tournament, vertices)

    # Sanity check
    assert len(ranking) == len(vertices)

    # TODO(spenceg): Use the equality rankings as a post-processing
    # step to declare ties? Lopez didn't do this.
    #tie_with_prev = mark_ties(ranking, di_edges)
    tie_with_prev=None
    
    return make_rows(ranking, tie_with_prev)
コード例 #3
0
def sort_tgts(ranking_list):
    """ Use the ranking list to build a total ordering
    of the ranked translations (indicated by Ranking.sys{1,2}_id

    Args:
    Returns:
    Raises:
    """
    # Aggregate ranking counts
    di_edges = Counter()
    eq_edges = Counter()
    edge_counts = Counter()
    vertices = set()
    for ranking in ranking_list:
        #        print str(ranking)
        vertices.add(ranking.sysA)
        vertices.add(ranking.sysB)
        edge = (ranking.sysA, ranking.sysB)
        edge_counts[edge] += 1
        if ranking.rank == 0:
            eq_edges[edge] += 1
        else:
            di_edges[edge] += 1

    # SPECIAL CASE: Equality
    # TA. Lopez discarded this data as a pre-processing
    # step. That is clearly bad since a single pairwise ranked judgment could
    # subsume all equality judgments.
    # Assert equality if equality is the majority pairwise judgment
    # TODO(spenceg): The Lopez implementation returns different
    # results if 0-weight edges are included in the tournament. Weird?
    for (a, b), n_eq in eq_edges.iteritems():
        n_eq += eq_edges[(b, a)]
        total = edge_counts[(a, b)] + edge_counts[(b, a)]
        perc_eq = float(n_eq) / float(total)
        if perc_eq >= 0.5:
            del di_edges[(a, b)]
            del di_edges[(b, a)]
        #if not (a,b) in di_edges:
        #    di_edges[(a,b)] = 0
        #if not (b,a) in di_edges:
        #    di_edges[(a,b)] = 0

    # Filter edges by only allowing one directed edge between
    # vertices. Edge weights are non-negative, and indicate
    # victories.
    tournament = Counter()
    for (a, b) in di_edges.keys():
        ab_cost = di_edges[(a, b)]
        assert ab_cost >= 0
        if (b, a) in di_edges:
            ba_cost = di_edges[(b, a)]
            cost_diff = ab_cost - ba_cost
            if cost_diff > 0:
                tournament[(a, b)] = cost_diff
            elif cost_diff < 0:
                tournament[(b, a)] = -1 * cost_diff
        else:
            tournament[(a, b)] = ab_cost

    # Generate the ranking
    vertices = list(vertices)
    # Call the reference Lopez implementation
    ranking = mfas_solver.lopez_solver(tournament, vertices)

    # Sanity check
    assert len(ranking) == len(vertices)

    # TODO(spenceg): Use the equality rankings as a post-processing
    # step to declare ties? Lopez didn't do this.
    #tie_with_prev = mark_ties(ranking, di_edges)
    tie_with_prev = None

    return make_rows(ranking, tie_with_prev)