gabm.abm.attributes.opinion module

Opinion module for GABM.

class gabm.abm.attributes.opinion.Opinion(opinion_topic_id: OpinionTopicID, opinion_values: OpinionValueMap, value: int)

Bases: object

An Opinion can belong to a Person, OpinionatedGroup, or OpinionatedEnvironment.

Attributes:

opinion_id (OpinionTopicID): The unique identifier for the opinion. opinion_values (OpinionValueMap): The opinion values for the opinion. value (int): The value of the opinion.

get_description() str

Get the description of the opinion value.

Returns:

str: The description of the opinion value, or None if not found.

get_value() int

Get the value of the opinion.

Returns:

int: The value of the opinion.

set_value(value: int)

Set the value of the opinion.

Args:

value: The new value of the opinion.

class gabm.abm.attributes.opinion.OpinionTopic(opinion_topic_id: OpinionTopicID, topic: str, description: str)

Bases: object

A topic for an opinion.

Examples:

id = 0, topic = “positive”, description = “A positive opinion.” id = 1, topic = “neutral”, description = “A neutral opinion.” id = 2, topic = “negative”, description = “A negative opinion.”

Attributes:

opinion_topic_id (OpinionTopicID): The unique identifier for the opinion topic. topic (str): The topic of the opinion. description (str): A description of the opinion topic.

class gabm.abm.attributes.opinion.OpinionTopicID(opinion_topic_id: int)

Bases: GABMAttributeID

A unique identifier for an opinion topic attribute.

Attributes:

id (int): The unique identifier for the opinion topic.

NEGATIVE = OpinionTopicID(3)
NEUTRAL = OpinionTopicID(2)
POSITIVE = OpinionTopicID(1)
UNKNOWN = OpinionTopicID(0)
class gabm.abm.attributes.opinion.OpinionValue(opinion_topic_id: OpinionTopicID, value: int, description: str)

Bases: object

A value for an opinion.

Attributes:
opinion_topic_id (OpinionTopicID):

The unique identifier for the opinion.

value (int):

An integer value of the opinion. This can be used as a key in a dictionary to map to the description. This could be a number mapped to a bipolar Likert scale (https://en.wikipedia.org/wiki/Likert_scale) survey response option. It is left to the user to decide how to interpret the value, and what it maps onto.

description (str):

A description of the opinion value.

Example:

-2, "Strongly disagree"
-1, "Disagree"
 0, "Neither agree nor disagree"
 1, "Agree"
 2, "Strongly agree"
class gabm.abm.attributes.opinion.OpinionValueMap(values: Dict[OpinionTopicID, OpinionValue])

Bases: object

A dictionary of OpinionValue objects.

The key is an OpinionTopicID, the value is an OpinionValue object.

This can be used to map from an OpinionTopicID and value to a description of the opinion value. For example, if the opinion topic is “positive”, then valid values might be -2, -1, 0, 1, 2, where -2 is “Strongly negative” and 2 is “Strongly positive”. The user can choose to enforce valid values or allow for more flexible representations of opinions. The description of the opinion value can be retrieved using the get_description() method, which looks up the description based on the opinion topic ID and value in the opinion_values dictionary. If the value is not found in the opinion_values, None will be returned. This allows for a clear mapping between numerical values and their corresponding descriptions, which can be useful for interpreting and analyzing opinions in the simulation.

Attributes:

values (Dict[OpinionTopicID, OpinionValue]): A dictionary mapping OpinionTopicID objects to OpinionValue objects.