Matrix¶
-
class
whalrus.Matrix(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, **kwargs)[source]¶ A way to compute a matrix from a profile.
A
Matrixobject is a callable whose inputs are ballots and optionally weights, voters and candidates. When it is called, it loads the profile. The output of the call is theMatrixobject itself. But after the call, you can access to the computed variables (ending with an underscore), such asas_dict_oras_array_.Parameters: - args – If present, these parameters will be passed to
__call__immediately after initialization. - converter (ConverterBallot) – The converter that is used to convert input ballots in order to compute
profile_converted_. Default:ConverterBallotGeneral. - kwargs – If present, these parameters will be passed to
__call__immediately after initialization.
-
profile_original_¶ The profile as it is entered by the user. This uses the constructor of
Profile. Hence indirectly, it usesConverterBallotGeneralto ensure, for example, that strings like'a > b > c'are converted to :class:Ballotobjects.Type: Profile
-
profile_converted_¶ The profile, with ballots that are adequate for the voting rule. For example, in
MatrixWeightedMajority, it will beBallotOrderobjects. This uses the parameterconverterof the object.Type: Profile
Examples
Cf.
MatrixWeightedMajorityfor some examples.-
as_array_¶ The matrix, as a numpy array. Each row and each column corresponds to a candidate (in the order of
candidates_as_list_).Type: Array
-
as_array_of_floats_¶ The matrix, as a numpy array. It is the same as
as_array_, but converted to floats.Type: Array
-
as_dict_¶ The matrix, as a
NiceDict. Keys are pairs of candidates, and values are the coefficients of the matrix.Type: NiceDict
-
candidates_as_list_¶ The list of candidates. Candidates are sorted if possible.
Type: list
-
candidates_indexes_¶ The candidates as a dictionary. To each candidate, it associates its index in
candidates_as_list_.Type: NiceDict
- args – If present, these parameters will be passed to