Prioritizer class

class pyanp.prioritizer.Prioritizer[source]

This class is the abstract representation of anything that prioritizes a list of items. Examples include pyanp.pairwise.Pairwise for doing group pairwise comparisons and pyanp.ahptree.AHPTree for doing group AHP tree models.

add_alt(alt_name: str, ignore_existing=True) → None[source]

Add an alternative to the prioritizer. This should be overriden by the implementing class.

Parameters:alt_name – The name of the alternative to add.
Returns:Nothing
add_user(uname)[source]

Adds a user to this prioritizer object.

Parameters:user_name – The name of the user to add
Returns:Nothing
Raises:ValueError – If the user already existed.
alt_names()[source]
Returns:A list of the alts in this prioritizer object.
data_names(append_to=None, post_pend='') → str[source]

Return string of newline separated names for the data that this prioritizer needs for each user.

Parameters:
  • append_to – If not none, elements are appended here, otherwise a new list is created.
  • post_pend – A string to post_pend to each name
Returns:

List of strings of names.

nalts()[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) → pandas.core.series.Series[source]

Calculates the alternative priorities. Should be overriden by the implementing class.

Parameters:user_name – The name/names of the users to calculate the priority

of. If None, we get the priority of the group average. 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.

Parameters: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.
priority_df(user_infos=None) → pandas.core.frame.DataFrame[source]

Returns the priority scores dataframe for all users and the group

Parameters:user_infos – A list of users to do this for, if None is a part of this list, it means group average. If None, it defaults to None plus all users.
Returns:pandas.DataFrame rows are alternatives, cols are users.
user_names()[source]
Returns:A list of the users in this prioritizer object.
class pyanp.prioritizer.PriorityType[source]

An enumeration telling how to normalize priorities for a calculation

IDEALIZE = 3

Divide priorities by max, so that the largest is 1.

NORMALIZE = 2

Divide priorities by sum, so that they sum to 1.

RAW = 1

Leave the priorities unchanged.

apply(vals)[source]

Returns a copy of the parameter vals that has been adjusted as this PriorityType would.

Parameters:vals – A list-like object of values. We return a copy that is adjusted.
Returns:A list-like of the same type as ‘vals’ that has been normalized as

this PriorityType would do.