def __init__(self, *args, points_scheme: list = None, points_fill: Union[Number, None] = 0, points_unordered: Union[Number, None] = 0, points_absent: Union[Number, None] = None, **kwargs): self.points_scheme = [convert_number(x) for x in points_scheme] self.points_fill = convert_number(points_fill) self.points_unordered = convert_number(points_unordered) self.points_absent = convert_number(points_absent) super().__init__(*args, **kwargs)
def __init__(self, *args, converter: ConverterBallot = None, matrix_weighted_majority: Matrix = None, greater: Number = 1, lower: Number = 0, equal: Number = Fraction(1, 2), diagonal: Number = Fraction(1, 2), **kwargs): if converter is None: converter = ConverterBallotToOrder() if matrix_weighted_majority is None: matrix_weighted_majority = MatrixWeightedMajority() self.matrix_weighted_majority = matrix_weighted_majority self.greater = convert_number(greater) self.lower = convert_number(lower) self.equal = convert_number(equal) self.diagonal = convert_number(diagonal) super().__init__(*args, converter=converter, **kwargs)
def __mul__(self, other: Number) -> 'Profile': """ Multiply the weights. :param other: a number. :return: this profile, with weights multiplied by the number. >>> profile = Profile(['a > b', 'b > a']) >>> print(profile * 3) (3): a > b (3): b > a """ other = convert_number(other) return Profile( ballots=self.ballots, weights=[convert_number(w * other) for w in self.weights], voters=self.voters)
def scores_(self) -> NiceDict: matrix = self.matrix_weighted_majority_ return NiceDict({ c: convert_number( sum([ v for (i, j), v in matrix.as_dict_.items() if i == c and j != c and v < 0 ])) for c in matrix.candidates_ })
def _parse(self, b: dict) -> None: """ For this subclass, the internal representation is of the form {'a': 10, 'b': 7, 'c': 3}, meaning that a has evaluation 10; b, 7; and c, 3. :param b: a dictionary. """ self._internal_representation = NiceDict( {c: convert_number(v) for c, v in b.items()})
def __init__(self, ballots: Union[list, 'Profile'], weights: list = None, voters: list = None): converter = ConverterBallotGeneral() self._ballots = [converter(b) for b in ballots] if weights is None: if isinstance(ballots, Profile): weights = ballots.weights else: weights = [1] * len(ballots) else: weights = [convert_number(w) for w in weights] self._weights = weights if voters is None: if isinstance(ballots, Profile): self._voters = ballots.voters else: self._voters = [None] * len(ballots) else: self._voters = voters
def append(self, ballot: object, weight: Number = 1, voter: object = None) -> None: """ Append a ballot to the profile. :param ballot: a ballot or, more generally, an input that can be interpreted by :class:`ConverterBallotGeneral`. :param weight: the weight of the ballot. :param voter: the voter. >>> profile = Profile(['a > b']) >>> profile.append('b > a') >>> print(profile) a > b b > a """ self._ballots.append(ConverterBallotGeneral()(ballot)) self._weights.append(convert_number(weight)) self._voters.append(voter) self.delete_cache()
def __init__(self, low: Number = 0, high: Number = 1): self._low = convert_number(low) self._high = convert_number(high)
def __init__(self, *args, converter: ConverterBallot = None, higher_vs_lower: Union[Number, None] = 1, lower_vs_higher: Union[Number, None] = 0, indifference: Union[Number, None] = Fraction(1, 2), ordered_vs_unordered: Union[Number, None] = 1, unordered_vs_ordered: Union[Number, None] = 0, unordered_vs_unordered: Union[Number, None] = Fraction(1, 2), ordered_vs_absent: Union[Number, None] = None, absent_vs_ordered: Union[Number, None] = None, unordered_vs_absent: Union[Number, None] = None, absent_vs_unordered: Union[Number, None] = None, absent_vs_absent: Union[Number, None] = None, diagonal_score: Number = 0, default_score: Number = 0, antisymmetric: bool = False, **kwargs): if converter is None: converter = ConverterBallotToOrder() self.higher_vs_lower = convert_number(higher_vs_lower) self.lower_vs_higher = convert_number(lower_vs_higher) self.indifference = convert_number(indifference) self.ordered_vs_unordered = convert_number(ordered_vs_unordered) self.unordered_vs_ordered = convert_number(unordered_vs_ordered) self.unordered_vs_unordered = convert_number(unordered_vs_unordered) self.ordered_vs_absent = convert_number(ordered_vs_absent) self.absent_vs_ordered = convert_number(absent_vs_ordered) self.unordered_vs_absent = convert_number(unordered_vs_absent) self.absent_vs_unordered = convert_number(absent_vs_unordered) self.absent_vs_absent = convert_number(absent_vs_absent) self.diagonal_score = convert_number(diagonal_score) self.default_score = convert_number(default_score) self.antisymmetric = antisymmetric super().__init__(*args, converter=converter, **kwargs)