CorsortGain
- class corsort.CorsortGain(compute_history=False, record_leq=False, final_scorer=<function scorer_rho>)[source]
Corsort based on a gain function.
- apply_i_lt_j(i, j)
Assuming perm[i] < perm[j], update the poset accordingly.
Examples
>>> corsort = Corsort() >>> corsort.n_ = 4
Assume that we know perm[0] < perm[1], and perm[2] < perm[3]:
>>> corsort.leq_ = np.array([ ... [ 1, 1, 0, 0], ... [-1, 1, 0, 0], ... [ 0, 0, 1, 1], ... [ 0, 0, -1, 1], ... ])
Assume we learn that perm[1] < perm[2]:
>>> corsort.apply_i_lt_j(1, 2) >>> corsort.leq_ array([[ 1, 1, 1, 1], [-1, 1, 1, 1], [-1, -1, 1, 1], [-1, -1, -1, 1]])
Now we know the full order by transitivity.
- compare_and_update_poset(i, j)
Perform a comparison between perm[i] and perm[j], and update the poset accordingly.
- distance_to_sorted_array()
Distance to sorted array.
- Returns:
Distance between the current estimation and the sorted array.
- Return type:
- gain(i, j)[source]
Gain to be expected when comparing perm[i] and perm[j].
Notes
The gain function must be minimal for all pairs (i, j) whose comparison is already known, including pairs of the form (i, i).
- property history_comparisons_values_
History of the pairwise comparisons, in terms of compared values. Tuple (x, y) means that items of values x and y were compared, and that x < y.
- next_compare()[source]
Iterator of pairwise comparisons to make.
- Returns:
An iterator of pairwise comparisons to make.
- Return type:
iterable
- test_i_lt_j(i, j)
Test whether perm[i] < perm[j].
- Parameters:
- Returns:
True if item of index i is lower than item of index j.
- Return type:
Notes
The history of distance is computed just before the comparison. Hence it should be computed a last time at the end of the algorithm.
- update_position_estimates()
Update position estimate of each item.
Examples
>>> corsort = Corsort(final_scorer=scorer_delta) >>> corsort.n_ = 4 >>> corsort.leq_ = np.array([ ... [ 1, 1, 1, 1], ... [-1, 1, -1, -1], ... [-1, 1, 1, 0], ... [-1, 1, 0, 1], ... ]) >>> corsort.update_position_estimates() >>> corsort.position_estimates_ array([-3, 3, 0, 0])