matrix.
Matrix
__init__
Add any choices, criteria, and their weights from the constructor into the matrix.
*choices (str) – Competiting items to choose from.
**kwargs (tuple[Union[str, float]]) – If choices given, then add those choices. If both criteria and weights are given, then add those criteria with their weights. Choices should be in a tuple of str, criteria should be in a tuple of str, and weights should be in a tuple of float.
str
float
df
The pandas DataFrame of the decision matrix.
pd.DataFrame
criteria
Yields the names of the criteria that are not added as continuous.
Generator[str, None, None]
continuous_criteria
The names of the criteria that are added as continuous.
list[str]
value_score_df
The pandas DataFrame storing the continuous criterion values to scores mapping. The columns are each continuous criteria and their score. The rows represent one value-score pair.
data_df
The pandas DataFrame storing the raw data that is used to calculate the score for continuous criteria.
ValueError – If any given weight value is zero.
ValueError
Examples
>>> import matrix >>> m = matrix.Matrix('apple', 'orange') >>> m |:-------| | Weight | | apple | | orange |
>>> m = matrix.Matrix( ... choices=('apple', 'orange'), ... criteria=('price', 'size'), ... weights=(4, 8) ... ) >>> m | | price | size | |:-------|:--------|:-------| | Weight | 4 | 8 | | apple | | | | orange | | |
Warning
If the length of the criteria tuple and the weight tuple is not the same, then the ‘extra’ values of the longer tuple will be ignored silently, like zip.
zip
Methods
__init__(*choices, **kwargs)
add_choices(*choices)
add_choices
Add items to choose from into the matrix.
add_continuous_criteria(*criteria, weights)
add_continuous_criteria
Add multiple continuous criteria into the matrix to evaluate each choice against.
add_continuous_criterion(criterion, *, weight)
add_continuous_criterion
Add a continuous criterion into the matrix to evaluate each choice against.
add_criteria(*criteria, weights, …)
add_criteria
Add multiple criteria into the matrix to evaluate each choice against.
add_criterion(criterion, *, weight, …)
add_criterion
Add a criterion into the matrix to evaluate each choice against.
add_data(choice, values_dict, float] = None, …)
add_data
Adds criterion data for the given choice, which is used to calculate their score.
batch_add_data(choices_and_values, dict[str, …)
batch_add_data
For multiple choices, add criterion data.
criteria_values_to_scores(criteria_names, …)
criteria_values_to_scores
For multiple continuous criteria, declare what score should a choice receive given values for that criterion.
criterion_value_to_score(criterion_name, …)
criterion_value_to_score
Declare what score should a choice receive for a continuous criterion, given the values for that criterion.
if_(**criterion_to_value)
if_
The first method in the if-then chain syntatic sugar for declaring what score should a choice receive given the values for the criterion.
plot()
plot
Visualise the percentages of all choices.
plot_interpolator(criterion_name[, start, end])
plot_interpolator
Visualize the interpolator function used.
rate_choice(choice, **criteria_to_ratings)
rate_choice
Given a choice, assign ratings (dictionary values) to given criteria (dictionary keys).
rate_choices(…)
rate_choices
Given some choices, assign ratings (dictionary values) to given criteria (dictionary keys).
rate_criterion(criterion, **choices_to_ratings)
rate_criterion
Given a criterion, assign ratings (dictionary values) to given choices (dictionary keys).
remove_criterion_value_to_score(row)
remove_criterion_value_to_score
Remove a criterion value-score pair by row/index number.
rename_choices(choice, name, **old_to_new_names)
rename_choices
Update the name of a given choice
rename_criteria(criterion, name, …)
rename_criteria
Update the name of a given criterion
then(*, score)
then
The last method in the if-then chain syntatic sugar for declaring what score should a choice receive given the values for the criterion.
update_criterion_value_to_score(…)
update_criterion_value_to_score
Update the value and/or score pair of a given continuous criterion
update_rating(choice, criterion, rating)
update_rating
Update the rating given to the choice in the criterion
update_weight(criterion, weight)
update_weight
Update the weight of a given criterion
values_to_score_from_record(dictionary, …)
values_to_score_from_record
Attributes
all_choices
Returns a view of the current choices in the matrix
all_criteria
Returns a view of the current criteria in the matrix
The names of the criteria that are not added as continuous.