pyMentalModels package¶
Submodules¶
pyMentalModels.custom_logical_classes module¶
-
class
pyMentalModels.custom_logical_classes.Necessary[source]¶ Bases:
sympy.logic.boolalg.BooleanFunctionModal logical Operator Value of subformula must evaluate to True: i.e. Necessary(False) –> entire formula evaluates to false
Examples
>>> from pyMentalModels.custom_logical_classes import Necessary >>> from sympy import symbols >>> x, y, z = symbols('x y z') >>> Necessary() XXX >>> Necessary() XXX
Multiple arguments >>> Necessary() False >>> Necessary() True
-
default_assumptions= {}¶
-
pyMentalModels.infer module¶
-
class
pyMentalModels.infer.InferenceTask[source]¶ Bases:
enum.EnumAn enumeration.
-
FOLLOWS= 'what_follows'¶
-
NECESSARY= 'necessary'¶
-
ONLY_MODELS= 'only_models'¶
-
POSSIBLE= 'possible'¶
-
PROBABILITY= 'probability'¶
-
VERIFY= 'verify'¶
-
-
pyMentalModels.infer.infer(models: List, task: pyMentalModels.infer.InferenceTask)[source]¶ Parameters: - models (List of mental_model NamedTuples with attributes:) –
- Attributes:
- expression: Logical expression that has been processed (Sympy.object) model: The resulting mental model representation (np.ndarry) atoms_model: list of atoms in the expression (list) atom_index_mapping: mapping of atoms to their column in model (Dict)
- task (InferenceTask) –
- One of the InferenceTask.values:
- what_follows?:
- Set task: Infer what follows from all premises
- necessary?:
- Set task: Given all but last premises, infer if last premise necessarily follows
- possible?:
- Set task: Given all but last premises, infer if last premise possibly follows
- probability?:
- Set task: Given all but last premises, infer the probability of last premis
- verify?:
- Set task: Given evidence last premise, verify all but last
- only_models
- Builds models of all the premises
Returns: Return type: Returns a conclusion or inference of sort.
- models (List of mental_model NamedTuples with attributes:) –
-
pyMentalModels.infer.resize_model(model, atom_index_mapping_all, all_atoms_in_all_models)[source]¶ Resize models so that they all share the same form to be able to compare them
Parameters: - model (MentalModel NamedTuple) –
- atom_index_mapping_all (Dict) – maps each Atom to its column index in the mental_model.model np.ndarray
- all_atoms_in_all_models –
Returns: Return type: resized model
pyMentalModels.intensions module¶
pyMentalModels.mental_model module¶
pyMentalModels.modal_parser module¶
-
pyMentalModels.modal_parser.parse_format(expression: str)[source]¶ Short function to both parse and format an expression and return a sympy object
-
pyMentalModels.modal_parser.sympify_formatter(args: List)[source]¶ Formatting function to make the parsed list sympify-readable For sympify refer to: http://docs.sympy.org/latest/modules/core.html
Parameters: args: List[str]
List of Lists with logical expressionsReturns: Return type: Sympify ready formatted str of the original expression
pyMentalModels.numpy_reasoner module¶
File that collects numpy logic for mental model reasoner
-
class
pyMentalModels.numpy_reasoner.Insight[source]¶ Bases:
enum.EnumEnum for the diferent insight modes intuitive and full
-
EXPLICIT= 'explicit'¶
-
INTUITIVE= 'intuitive'¶
-
-
pyMentalModels.numpy_reasoner.build_and(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of And expression.
Parameters: - exp – expression with outer-most logical operator being And
- atom_index_mapping (Dict) – mapping from all the atoms to their index in the model/array
- exp_atoms (List) – List of all the Atoms of the mental_model
Returns: Model
Return type: np.ndarray
-
pyMentalModels.numpy_reasoner.build_equals(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds numpy representation of implication
Behaves differently depending on if it is called with parameter Insight.Intuitive or Insight.Full
“A -> B” Should yield model 1 1 mode = INTUITIVE — 0 1 mode = FULL 0 0
Parameters: - exp (symbolic expression) – Expression with only symbols or symbols and logical arguments
- atom_index_mapping –
- exp_atoms (TODO) –
- mode (TODO, optional) –
-
pyMentalModels.numpy_reasoner.build_implication(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds numpy representation of implication
Behaves differently depending on if it is called with parameter Insight.Intuitive or Insight.Full
“A -> B”
Should yield model
1 1 mode = INTUITIVE — 0 1 mode = FULL 0 0
Parameters: - exp (symbolic expression) – Expression with only symbols or symbols and logical arguments
- atom_index_mapping –
- exp_atoms (TODO) –
- mode (TODO, optional) –
-
pyMentalModels.numpy_reasoner.build_necessary(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of necessary expression
- Models represent possibilities (J-L & Byrne, 1991)
2. Compounds of alternatives refer by default to exhaustive conjunctions of possibilities, e.g.: A or else B, but not both has two mental models (system 1): A
B(J-L, Khemlani, & Goodwin, 2015.)
Fully explicit models (system 2) also represent what’s impossible.
3. A conjunction, A and B, makes a factual claim: both propositions hold in all possibilities.
4. Parsimony: possible that A and possible that B has a mental model of a single possibility:
A B
(2) Necessary The problem is that the truth value of A does not determine the truth value for []A. For example, when A is ‘Dogs are dogs’, []A is true, but when A is ‘Dogs are pets’, []A is false
- Possible
(~) v(~A, w)=T iff v(A, w)=F.
(->) v(A -> B, w)=T iff v(A, w)=F or v(B, w)=T. !!!!! Implication is AND in implicit mode
- v([]A, w)=T iff for every world w′ in W, v(A, w′)=T.
Furthermore, [](A&B) entails []A&[]B and vice versa; while []A|[]B entails [](A|B), but not vice versa. This reflects the patterns exhibited by the universal quantifier: ∀x(A&B) entails ∀xA&∀xB and vice versa, while ∀xA ∨ ∀xB entails ∀x(A ∨ B) but not vice versa
-
pyMentalModels.numpy_reasoner.build_not(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of expression with outer-most argument being Not
-
pyMentalModels.numpy_reasoner.build_or(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of Or expression.
Parameters: - exp – expression with outer-most logical operator being Or
- atom_index_mapping (Dict) – mapping from all the atoms to their index in the model/array
- exp_atoms (List) – List of all the Atoms of the mental_model
Returns: Model
Return type: np.ndarray
-
pyMentalModels.numpy_reasoner.build_possibly(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of possibly expression
-
pyMentalModels.numpy_reasoner.build_xor(exp, atom_index_mapping, exp_atoms, mode)[source]¶ Builds model of Xor expression.
Parameters: - exp – expression with outer-most logical operator being Xor
- atom_index_mapping (Dict) – mapping from all the atoms to their index in the model/array
- exp_atoms (List) – List of all the Atoms of the mental_model
Returns: Model
Return type: np.ndarray
-
pyMentalModels.numpy_reasoner.map_instance_to_operation(el, mode)[source]¶ maps every logical instance to its builder function.
-
pyMentalModels.numpy_reasoner.mental_model_builder(sympified_expr, mode)[source]¶ Builds a mental model representation of the logical expression.
A Mental model is a mental representation of a logical or indeed any expression. An example would be the expression:
You have either the salad or the soup or the breadThe mental model representation would then be:
- Salad
- Soup
- Bread
mental_model_builder recursively builds models of the subexpressions of the total expression, merges them and returns the overall mental model representation of the expression
Parameters: - sympified_expr (sympy BooleanFunction) –
An expression formatted and processed by the sympy python module Attributes:
- expression.atoms
- Set of all the atoms in the logical expression
- expression.args
- Tuple of arguments the outermost logical operator takes
- mode (Insight) – Insight can be either Insight.INTUITIVE or Insight.FULL
Returns: Return type: Mental model representation of logical expression
pyMentalModels.operators module¶
pyMentalModels.pretty_printing module¶
-
pyMentalModels.pretty_printing.pretty_print_atom_assign(atom_assignment, atoms, mode='intuitive', output='str')[source]¶ Returns a string representation of the atoms Atom. Assignment IMPL_NEG –> “¬atom” if explicit else ” ” Atom. Assignment EXPL_NEG –> “¬atom” always Atom. Assignment POS_VAL –> “atom”
Parameters: - atoms (List,) – Literals/Atoms of the logical expression i.e. the column labels for the model
- atom_assignment (Either EXPL_NEG, POS_VAL, IMPL_NEG) – Assignment of the Atoms in the model.
- mode (str, optional) – default is “intuitive” choices are “intuitive”, “explicit”
Returns: output – can be either “list” or “str”
Return type: [List, str]