ajar.judging_agent.JudgingAgent#

class ajar.judging_agent.JudgingAgent(moral_value: str, base_afdm: AFDM, j_transform: Callable[[AFDM, str], float])[source]#

Bases: object

A JudgingAgent judges the behaviour of learning agents, w.r.t a moral value.

This moral value is implemented (represented) by an AFDM and its arguments and attacks. The judgment of a given action in a situation is performed based on the AFDM, by computing its grounded extension, i.e., arguments that are alive in a given situation and that defend each other.

The JudgingAgent also contains a function j_transform to transform the grounded extension into a scalar measure, i.e., the reward. This function is configurable, and often relies on comparing the number of pros arguments (that support the idea that the learning agent’s action was moral) and cons arguments (that counter the idea that the action was moral).

__init__(moral_value: str, base_afdm: AFDM, j_transform: Callable[[AFDM, str], float])[source]#

Create a new JudgingAgent.

Parameters:
  • moral_value – The name of the moral value associated to this judging agent. Should be unique.

  • base_afdm – The argumentation framework (arguments + attacks) used to implement or represent the moral value.

  • j_transform – The function used to transform the grounded extension into a scalar reward. See the judgment module for examples of such functions.

Methods

__init__(moral_value, base_afdm, j_transform)

Create a new JudgingAgent.

judge(situation, decision)

Judge a situation and return the corresponding reward.

Attributes

moral_value

The name of the moral value that this Judging Agent represents.

base_afdm

The base AFDM, containing all arguments and attacks representing the moral value.

j_transform

The function that transforms the grounded extension into a scalar reward.

activation_rate

The proportions of situations in which each argument was activated.

last_activation

For each argument, whether it was activated at the last step.

_filter_afdm(situation) AFDM[source]#

Filters the base AFDM to return the current AFDM.

The current (or filtered) AFDM contains only arguments considered to be alive in the current situation. See activation_function for details.

Parameters:

situation – The current situation. Its type is voluntarily not specified, to avoid restricting users. The recommended type is a dictionary, mapping string (keys) to any object, thus representing the current situation as a list of properties.

Returns:

The new AFDM that corresponds to the current situation.

_update_activation_rate(current_afdm: AFDM)[source]#

Update the arguments’ activation rates, based on the grounded extension.

Arguments that are in the grounded are said to be activated, and we increment both counters (activated and total). For other arguments, we only increment the total counter, such that their proportion of activation decreases.

activation_rate: Dict[str, Activation]#

The proportions of situations in which each argument was activated.

Activation rates are indexed by the arguments’ name. They contain the number of times the argument was activated, i.e., in the grounded extension (activated); and the total number of steps (total). In other words, the proportion of an argument named k is activation_rate[k].activated / activation_rate[k].total. For easier access, this is also available as activation_rate[k].proportion.

Activation rates are only useful for post-run analysis and are not taken into account during the judgment process.

base_afdm: AFDM#

The base AFDM, containing all arguments and attacks representing the moral value.

All arguments means here that we consider arguments for all possible situations, e.g., “agent bought 10% of energy”, “agent bought energy 20%”, etc. Some of them will be “false” in some situations, e.g., if the agent bought in fact 15% of energy, the first argument is true (alive) but not the second one. The base AFDM contains all of them, and is thus refined by updating the arguments’ alive attribute in specific situations.

j_transform: Callable[[AFDM, str], float]#

The function that transforms the grounded extension into a scalar reward.

It is responsible for ultimately producing the reward, when the argumentation process is done and that only arguments that are acceptable remain, in the grounded extension. From this set of arguments, the j_transform determines how to measure the degree to which the learning agent’s action was moral. A simple version can be to compare the number of pros arguments to the total number of pros and cons arguments.

The j_transform function takes as a first input the current AFDM that represents the current situation and the grounded extension, and as a second input the decision that we want to measure. In the current version, the decision will always be 'moral', but in future versions it could be extended to support various decisions, ethical principles, etc. It then returns a float.

judge(situation, decision: str) float[source]#

Judge a situation and return the corresponding reward.

Parameters:
  • situation – A situation corresponds to an action that happened in a state, but does not have any “structured” type (it can be Any) to allow for flexibility. The situation should describe both the state and the action, and will usually be a dict, indexed by strings. See activation_function for details.

  • decision – The decision with respect to which the judgment should be done. In the current version, a single decision 'moral' is used; in future versions, different decisions could be used to implement various ethical principles.

Returns:

The reward associated to the given situation, as determined through this agent’s judgment, with respect to its moral value.

last_activation: Dict[str, bool]#

For each argument, whether it was activated at the last step.

moral_value: str#

The name of the moral value that this Judging Agent represents.

It should be unique, so that it can be used as key of dicts.