matrix.Matrix

class matrix.Matrix(*choices, **kwargs)
__init__(*choices, **kwargs)

Add any choices, criteria, and their weights from the constructor into the matrix.

Parameters

*choices (str) – Competiting items to choose from.

Keyword Arguments

**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.

df

The pandas DataFrame of the decision matrix.

Type

pd.DataFrame

criteria

Yields the names of the criteria that are not added as continuous.

Type

Generator[str, None, None]

continuous_criteria

The names of the criteria that are added as continuous.

Type

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.

Type

pd.DataFrame

data_df

The pandas DataFrame storing the raw data that is used to calculate the score for continuous criteria.

Type

pd.DataFrame

Raises

ValueError – If any given weight value is zero.

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.

Methods

__init__(*choices, **kwargs)

Add any choices, criteria, and their weights from the constructor into the matrix.

add_choices(*choices)

Add items to choose from into the matrix.

add_continuous_criteria(*criteria, weights)

Add multiple continuous criteria into the matrix to evaluate each choice against.

add_continuous_criterion(criterion, *, weight)

Add a continuous criterion into the matrix to evaluate each choice against.

add_criteria(*criteria, weights, …)

Add multiple criteria into the matrix to evaluate each choice against.

add_criterion(criterion, *, weight, …)

Add a criterion into the matrix to evaluate each choice against.

add_data(choice, values_dict, float] = None, …)

Adds criterion data for the given choice, which is used to calculate their score.

batch_add_data(choices_and_values, dict[str, …)

For multiple choices, add criterion data.

criteria_values_to_scores(criteria_names, …)

For multiple continuous criteria, declare what score should a choice receive given values for that criterion.

criterion_value_to_score(criterion_name, …)

Declare what score should a choice receive for a continuous criterion, given the values for that criterion.

if_(**criterion_to_value)

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()

Visualise the percentages of all choices.

plot_interpolator(criterion_name[, start, end])

Visualize the interpolator function used.

rate_choice(choice, **criteria_to_ratings)

Given a choice, assign ratings (dictionary values) to given criteria (dictionary keys).

rate_choices(…)

Given some choices, assign ratings (dictionary values) to given criteria (dictionary keys).

rate_criterion(criterion, **choices_to_ratings)

Given a criterion, assign ratings (dictionary values) to given choices (dictionary keys).

remove_criterion_value_to_score(row)

Remove a criterion value-score pair by row/index number.

rename_choices(choice, name, **old_to_new_names)

Update the name of a given choice

rename_criteria(criterion, name, …)

Update the name of a given criterion

then(*, score)

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 the value and/or score pair of a given continuous criterion

update_rating(choice, criterion, rating)

Update the rating given to the choice in the criterion

update_weight(criterion, weight)

Update the weight of a given criterion

values_to_score_from_record(dictionary, …)

For multiple continuous criteria, declare what score should a choice receive given values for that criterion.

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

criteria

The names of the criteria that are not added as continuous.