Group pairwise comparison¶
Group pairwise object and calculations. See pyanp.priority
for
all methods of calculating priorities from a pairwise comparison matrix
in addition to inconsistency calculations.
-
class
pyanp.pairwise.
Pairwise
(alts=None, users=None, demographic_cols=None)[source]¶ Creates a new group pairwise comparison object.
Parameters: - alts – The list alternatives (things you are comparing) to start with. Should be a list-like object of strings.
- users – The users to start the group pairwise comparison object with. It should be a list-like object of strings.
- demographic_cols – The names of the demographic columns to start the group pairwise comparison object with. It should be a list-like object of strings.
-
add_alt
(alt_name: str, ignore_existing=False) → None[source]¶ Adds an alternative (thing you are pairwise comparing) to this group pairwise comparison object.
Parameters: alt_name – The name of the alternative to add. Returns: Nothing Raises: ValueError – If the alternative already esisted.
-
add_user
(user_name: str) → None[source]¶ Adds a user to this group pairwise comparison object.
Parameters: user_name – The name of the user to add Returns: Nothing Raises: ValueError – If the user already existed.
-
alt_index
(alt_name_or_index) → int[source]¶ Find the index (integer location) of the given alternative in the pairwise comparison matrices.
Parameters: alt_name_or_index – If this is an integer, we simply return that integer. Otherwise we look up the index of the alternative name in the list of alternatives in this object. Returns: The index that alternative has in the pairwise comparison matrices.
-
incon_std
(user_name=None) → float[source]¶ Calculates the standard Saaty pairwise comparison inconsistency for a user or group of users.
Parameters: user_name – The name/names of the users to get the inconsistency of. If None, we get the inconsistency of the group average matrix. If it is a string, we get the inconsistency of that user. If it is a list of users, we get the inconsistency of the group average for that list of users. Returns: The Saaty inconsistency score.
-
is_alt
(alt_name: str) → bool[source]¶ Checks if an alternative (a thing you are pairwise comparing) exists in this group pairwise comparison object.
Parameters: alt_name – The name of the alternative to check for. Returns: True/False
-
is_user
(user_name: str) → bool[source]¶ Checks if a user exists in this group pairwise comparison object.
Parameters: user_name – The name of the user to look for Returns: True/False
-
matrix
(user_name=None, createUnknownUser: bool = True, as_df=False) → numpy.ndarray[source]¶ Gets the pairwise comparison for a user or group of users.
Parameters: - user_name – The name/names of the user/users to get the comparisons of. If None, that means to get the group average for all users. If it is a string, that means get the pairwise comparison matrix of that user. If it is a list-like of strings, we get the group average matrix for all of those users.
- createUnknownUser – If True and the user_name did not exist, we should create that user. Otherwise throw an error if we request for a non-existant user.
- as_df – If True return as pandas.DataFrame with index/column names as the alt names, otherwise return numpy.ndarray
Returns: The numpy array of the pairwise comparisons, or DataFrame if as_df is True
Raises: ValueError – If createUnknownUser=False and we request for a single non-existant user.
-
nalts
() → int[source]¶ Returns: The number of alternatives (things you are pairwise comparing) in this group pairwise comparison object.
-
priority
(username=None, ptype: pyanp.prioritizer.PriorityType = None)[source]¶ Calculates the resulting priority for the given user / users.
Parameters: - user_name – The name/names of the users to calculate the priority of. If None, we get the priority of the group average matrix. If it is a string, we get the priority of that user. If it is a list of users, we get the priority of the group average for that list of users.
- ptype – How should we normalize the resulting priorities (if at all).
Returns: A pandas.Series whose indices are the alternative names and whose values are the priorities of those alternatives.
-
unvote
(user_name: str, row, col, createUnknownUser: bool = True) → None[source]¶ Unsets a pairwise comparison
Parameters: - user_name – The string name of the user whose pairwise comparison vote you wish to unset.
- row – The integer or string name of the row to compare at.
- col – The integer or string name of the column to compare at.
- createUnknownUser – If True and user_name does not exist in this object, we will create it first, then do the unset operation. Otherwise it throws an exception for unknown users.
Returns: Nothing
Raises: ValueError – If the user does not exist and createUnknownUsers is False.
-
vote
(user_name: str, row, col, val: float = 0, createUnknownUser: bool = True) → None[source]¶ Changes a single pairwise value for a single user.
Parameters: - user_name – The string name of the user whose pairwise comparison vote you wish to change.
- row – The integer or string name of the row to compare at.
- col – The integer or string name of the column to compare at.
- val – The new pairwise comparison value
- createUnknownUser – If True and user_name does not exist in this object, we will create it first, then do the comparison. Otherwise it throws an exception for unknown users.
Returns: Nothing
Raises: ValueError – If the user does not exist and createUnknownUsers is False.
-
vote_matrix
(user_name: str, val=<class 'numpy.ndarray'>, createUnknownUser: bool = True)[source]¶ Sets the vote matrix for a user
Parameters: - user_name –
- val –
Returns:
-
vote_series
(votes: pandas.core.series.Series, row, col, createUnknownUser: bool = True) → None[source]¶ Changes a single pairwise value for a series of users.
Parameters: - votes – Series whose index is usernames and values are their votes.
- row – The integer or string name of the row to compare at.
- col – The integer or string name of the column to compare at.
- createUnknownUser – If True and a username does not exist in this object, we will create it first, then do the comparison. Otherwise it throws an exception for unknown users.
Returns: Nothing
Raises: ValueError – If the user does not exist and createUnknownUsers is False.