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
Matrix
object 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 theMatrix
object 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 usesConverterBallotGeneral
to ensure, for example, that strings like'a > b > c'
are converted to :class:Ballot
objects.- Type
-
profile_converted_
¶ The profile, with ballots that are adequate for the voting rule. For example, in
MatrixWeightedMajority
, it will beBallotOrder
objects. This uses the parameterconverter
of the object.- Type
Examples
Cf.
MatrixWeightedMajority
for some examples.-
property
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
-
property
as_array_of_floats_
¶ The matrix, as a numpy array. It is the same as
as_array_
, but converted to floats.- Type
Array
-
property
as_dict_
¶ The matrix, as a
NiceDict
. Keys are pairs of candidates, and values are the coefficients of the matrix.- Type
-
property
candidates_as_list_
¶ The list of candidates. Candidates are sorted if possible.
- Type
list
-
property
candidates_indexes_
¶ The candidates as a dictionary. To each candidate, it associates its index in
candidates_as_list_
.- Type