carneades package

carneades.caes module

Overview

Propositions

First, let’s create some propositions using the PropLiteral constructor. All propositions are atomic, that is, either positive or negative literals.

>>> kill = PropLiteral('kill')
>>> kill.polarity
True
>>> intent = PropLiteral('intent')
>>> murder = PropLiteral('murder')
>>> witness1 = PropLiteral('witness1')
>>> unreliable1 = PropLiteral('unreliable1')
>>> witness2 = PropLiteral('witness2')
>>> unreliable2 = PropLiteral('unreliable2')

The negate() method allows us to introduce negated propositions.

>>> neg_intent = intent.negate()
>>> print(neg_intent)
-intent
>>> neg_intent.polarity
False
>>> neg_intent == intent
False
>>> neg_intent.negate() == intent
True

Arguments

Arguments are built with the Argument constructor. They are required to have a conclusion, and may also have premises and exceptions.

>>> arg1 = Argument(murder, premises={kill, intent})
>>> arg2 = Argument(intent, premises={witness1}, exceptions={unreliable1})
>>> arg3 = Argument(neg_intent, premises={witness2}, exceptions={unreliable2})
>>> print(arg1)
[intent, kill], ~[] => murder

In order to organise the dependencies between the conclusion of an argument and its premises and exceptions, we model them using a directed graph called an ArgumentSet. Notice that the premise of one argument (e.g., the intent premise of arg1) can be the conclusion of another argument (i.e., arg2)).

>>> argset = ArgumentSet()
>>> argset.add_argument(arg1, arg_id='arg1')
>>> argset.add_argument(arg2, arg_id='arg2')
>>> argset.add_argument(arg3, arg_id='arg3')

There is a draw() method which allows us to view the resulting graph.

>>> argset.draw() 

Proof Standards

In evaluating the relative value of arguments for a particular conclusion p, we need to determine what standard of proof is required to establish p. The notion of proof used here is not formal proof in a logical system. Instead, it tries to capture how substantial the arguments are in favour of, or against, a particular conclusion.

The ProofStandard constructor is initialised with a list of (proposition, name-of-proof-standard) pairs. The default proof standard, viz., 'scintilla', is the weakest level. Different propositions can be assigned different proof standards that they need to attain.

>>> ps = ProofStandard([(intent, "beyond_reasonable_doubt")],
... default='scintilla')

Carneades Argument Evaluation Structure

The core of the argumentation model is a data structure plus set of rules for evaluating arguments; this is called a Carneades Argument Evaluation Structure (CAES). A CAES consists of a set of arguments, an audience (or jury), and a method for determining whether propositions satisfy the relevant proof standards.

The role of the audience is modeled as an Audience, consisting of a set of assumed propositions, and an assignment of weights to arguments.

>>> assumptions = {kill, witness1, witness2, unreliable2}
>>> weights = {'arg1': 0.8, 'arg2': 0.3, 'arg3': 0.8}
>>> audience = Audience(assumptions, weights)

Once an audience has been defined, we can use it to initialise a CAES, together with instances of ArgumentSet and ProofStandard:

>>> caes = CAES(argset, audience, ps)
>>> caes.get_all_arguments()
[intent, kill], ~[] => murder
[witness1], ~[unreliable1] => intent
[witness2], ~[unreliable2] => -intent

The get_arguments() method returns the list of arguments in an ArgumentSet which support a given proposition.

A proposition is said to be acceptable in a CAES if it meets its required proof standard. The process of checking whether a proposition meets its proof standard requires another notion: namely, whether the arguments that support it are applicable. An argument arg is applicable if and only if all its premises either belong to the audience’s assumptions or are acceptable; moreover, the exceptions of arg must not belong to the assumptions or be acceptable. For example, arg2, which supports the conclusion intent, is acceptable since witness1 is an assumption, while the exception unreliable1 is neither an assumption nor acceptable.

>>> arg_for_intent = argset.get_arguments(intent)[0]
>>> print(arg_for_intent)
[witness1], ~[unreliable1] => intent
>>> caes.applicable(arg_for_intent)
True
>>> caes.acceptable(intent)
False

Although there is an argument (arg3) for -intent, it is not applicable, since the exception unreliable2 does belong to the audience’s assumptions.

>>> any(caes.applicable(arg) for arg in argset.get_arguments(neg_intent))
False

This in turn has the consequence that -intent is not acceptable.

>>> caes.acceptable(neg_intent)
False

Despite the fact that the argument arg2 for murder is applicable, the conclusion murder is not acceptable, since

>>> caes.acceptable(murder)
False
>>> caes.acceptable(murder.negate())
False
class Argument(conclusion, premises=set(), exceptions=set())[source]

An argument consists of a conclusion, a set of premises and a set of exceptions (both of which can be empty).

Although arguments should have identifiers (arg_id), it is preferable to specify these when calling the add_argument() method of ArgumentSet.

__init__(conclusion, premises=set(), exceptions=set())[source]
Parameters:
  • conclusion (PropLiteral) – The conclusion of the argument.
  • premises (set(PropLiteral)) – The premises of the argument.
  • exceptions (set(PropLiteral)) – The exceptions of the argument
class ArgumentSet[source]

An ArgumentSet is modeled as a dependency graph where vertices represent the components of an argument. A vertex corresponding to the conclusion of an argument A will depend on the premises and exceptions in A.

The graph is built using the igraph library. This allows attributes to be associated with both vertices and edges. Attributes are represented as Python dictionaries where the key (which must be a string) is the name of the attribute and the value is the attribute itself. For more details, see the igraph tutorial.

__init__()[source]
add_argument(argument, arg_id=None)[source]

Add an argument to the graph.

Parameters:
  • argument (Argument) – The argument to be added to the graph.
  • arg_id (str or None) – The ID of the argument
add_proposition(proposition)[source]

Add a proposition to a graph if it is not already present as a vertex.

Parameters:proposition (PropLiteral) – The proposition to be added to the graph.
Returns:The graph vertex corresponding to the proposition.
Return type:Graph.Vertex
Raises TypeError:
 if the input is not a PropLiteral.
draw(debug=False)[source]

Visualise an ArgumentSet as a labeled graph.

Parameters:debug – If True, add the vertex index to the label.
get_arguments(proposition)[source]

Find the arguments for a proposition in an ArgumentSet.

Parameters:proposition (PropLiteral) – The proposition to be checked.
Returns:A list of the arguments pro the proposition
Return type:list(Argument)
Raises ValueError:
 if the input PropLiteral isn’t present in the graph.
propset()[source]

The set of PropLiterals represented by the vertices in the graph.

Retrieving this set relies on the fact that add_proposition() sets a value for the prop attribute in vertices created when a new proposition is added to the graph.

write_to_graphviz(fname=None)[source]

Write the graph to a file using the Graphviz dot language.

A dot file can be converted to multiple output formats, including png and pdf. For example, dot -Tpng graph.dot > graph.png will produce an output file graph.png.

Parameters:fname – Name of file to write the results to. If no filename is supplied, the results will be written to graph.dot.
class Audience

An audience has assumptions about which premises hold and also assigns weights to arguments.

Parameters:
  • assumptions (set(PropLiteral)) – The assumptions held by the audience
  • weights (dict) – An mapping from Arguments to weights.
assumptions

Alias for field number 0

weight

Alias for field number 1

class CAES(argset, audience, proofstandard, alpha=0.4, beta=0.3, gamma=0.2)[source]

A class that represents a Carneades Argument Evaluation Structure (CAES).

__init__(argset, audience, proofstandard, alpha=0.4, beta=0.3, gamma=0.2)[source]
Parameters:
  • argset (ArgSet) – the argument set used in the CAES
  • audience (Audience) – the audience for the CAES
  • proofstandard (ProofStandard) – the proof standards used in the CAES
  • alpha (float in interval [0, 1]) – threshold of strength of argument required for a proposition to reach the proof standards “clear and convincing” and “beyond reasonable doubt”.
  • beta (float in interval [0, 1]) – difference required between strength of argument pro a proposition vs strength of argument con to reach the proof standard “clear and convincing”.
  • gamma (float in interval [0, 1]) – threshold of strength of a con argument required for a proposition to reach the proof standard “beyond reasonable doubt”.
acceptable(proposition)[source]

A conclusion is acceptable in a CAES if it can be arrived at under the relevant proof standards, given the beliefs of the audience.

Parameters:proposition (PropLiteral) – The conclusion whose acceptability is to be determined.
Return type:bool
applicable(argument)[source]

An argument is applicable in a CAES if it needs to be taken into account when evaluating the CAES.

Parameters:argument (Argument) – The argument whose applicablility is being determined.
Return type:bool
get_all_arguments()[source]

Show all arguments in the ArgSet of the CAES.

max_weight_applicable(arguments)[source]

Retrieve the weight of the strongest applicable argument in a list of arguments.

Parameters:arguments (list(Argument)) – The arguments whose weight is being compared.
Returns:The maximum of the weights of the arguments.
Return type:float in interval [0, 1]
max_weight_con(proposition)[source]

The maximum of the weights con the proposition.

Parameters:proposition (PropLiteral) – The conclusion whose acceptability is to be determined.
Return type:float in interval [0, 1]
max_weight_pro(proposition)[source]

The maximum of the weights pro the proposition.

Parameters:proposition (PropLiteral) – The conclusion whose acceptability is to be determined.
Return type:float in interval [0, 1]
meets_proof_standard(proposition, standard)[source]

Determine whether a proposition meets a given proof standard.

Parameters:
  • proposition (PropLiteral) – The proposition which should meet the relevant proof standard.
  • standard (str) – a specific level of proof; see ProofStandard for admissible values
Return type:

bool

weight_of(argument)[source]

Retrieve the weight associated by the CAES audience with an argument.

Parameters:argument (Argument) – The argument whose weight is being determined.
Returns:The weight of the argument.
Return type:float in interval [0, 1]
class ProofStandard(propstandards, default='scintilla')[source]

Each proposition in a CAES is associated with a proof standard.

A proof standard is initialised by supplying a (possibly empty) list of pairs, each consisting of a proposition and the name of a proof standard.

>>> intent = PropLiteral('intent')
>>> ps = ProofStandard([(intent, "beyond_reasonable_doubt")])

Possible values for proof standards: "scintilla", "preponderance", "clear_and_convincing", "beyond_reasonable_doubt", and "dialectical_validity".

__init__(propstandards, default='scintilla')[source]
Parameters:propstandards (list(tuple(PropLiteral, str))) – the proof standard associated with each proposition under consideration.
get_proofstandard(proposition)[source]

Determine the proof standard associated with a proposition.

Parameters:proposition (PropLiteral) – The proposition to be checked.
class PropLiteral(string, polarity=True)[source]

Proposition literals have most of the properties of ordinary strings, except that the negation method is Boolean; i.e.

>>> a = PropLiteral('a')
>>> a.negate().negate() == a
True
__init__(string, polarity=True)[source]

Propositions are either positive or negative atoms.

negate()[source]

Negation of a proposition.

We create a copy of the current proposition and flip its polarity.

arg_demo()[source]

Demo of how to initialise and call methods of a CAES.

carneades.tracecalls module

Module to see what calls actually occurred during execution, their arguments and return values, when executing algorithms with complex function call sequences, and especially ones that require recursion.

The class TraceCalls is called as a decorator @TraceCalls().

class TraceCalls(stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, indent_step=2, show_ret=True)[source]

Use as a decorator on functions that should be traced. Several functions can be decorated; they will all be indented according to their call depth.

__init__(stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, indent_step=2, show_ret=True)[source]
Parameters:
  • stream – The output stream
  • indent_step (int) – How much to indent strings relative to call depth.
  • show_ret – If True, show the return value of the function call.
cur_indent = 0