You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/user_guide/8_advanced_usage.rst
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,4 +18,10 @@ Reasoning Multiple Times
18
18
-------------------------
19
19
PyReason allows you to reason over the graph multiple times. This can be useful when you want to reason over the graph iteratively
20
20
and add facts that were not available before. To reason over the graph multiple times, you can set ``again=True`` in ``pr.reason(again=True)``.
21
-
To specify additional facts, use the ``node_facts`` or ``edge_facts`` parameters in ``pr.reason(...)``. These parameters allow you to add additional facts to the graph before reasoning again.
21
+
To specify additional facts, use the ``facts`` parameter in ``pr.reason(...)``. These parameters allow you to add additional
22
+
facts to the graph before reasoning again. The facts are specified as a list of PyReason facts.
23
+
24
+
.. note::
25
+
When reasoning multiple times, the time continues to increment. Therefore any facts that are added should take this into account.
26
+
The timestep parameter specifies how many additional timesteps to reason. For example, if the initial reasoning converges at
27
+
timestep 5, and you want to reason for 3 more timesteps, you can set ``timestep=3`` in ``pr.reason(timestep=3, again=True, facts=[some_new_fact])``.
"""Function to start the main reasoning process. Graph and rules must already be loaded.
629
629
630
630
:param timesteps: Max number of timesteps to run. -1 specifies run till convergence. If reasoning again, this is the number of timesteps to reason for extra (no zero timestep), defaults to -1
631
631
:param convergence_threshold: Maximum number of interpretations that have changed between timesteps or fixed point operations until considered convergent. Program will end at convergence. -1 => no changes, perfect convergence, defaults to -1
632
632
:param convergence_bound_threshold: Maximum change in any interpretation (bounds) between timesteps or fixed point operations until considered convergent, defaults to -1
633
633
:param queries: A list of PyReason query objects that can be used to filter the ruleset based on the query. Default is None
634
634
:param again: Whether to reason again on an existing interpretation, defaults to False
635
-
:param node_facts: New node facts to use during the next reasoning process. Other facts from file will be discarded, defaults to None
636
-
:param edge_facts: New edge facts to use during the next reasoning process. Other facts from file will be discarded, defaults to None
635
+
:param facts: New facts to use during the next reasoning process when reasoning again. Other facts from file will be discarded, defaults to None
637
636
:return: The final interpretation after reasoning.
638
637
"""
639
638
globalsettings, __timestamp
@@ -654,10 +653,10 @@ def reason(timesteps: int = -1, convergence_threshold: int = -1, convergence_bou
assertlen(dataframes[2]) ==1, 'At t=0 there should be one popular person'
42
+
assertlen(dataframes[3]) ==2, 'At t=1 there should be two popular people'
43
+
assertlen(dataframes[4]) ==3, 'At t=2 there should be three popular people'
44
+
45
+
# Mary should be popular in all three timesteps
46
+
assert'Mary'indataframes[2]['component'].valuesanddataframes[2].iloc[0].popular== [1, 1], 'Mary should have popular bounds [1,1] for t=0 timesteps'
47
+
assert'Mary'indataframes[3]['component'].valuesanddataframes[3].iloc[0].popular== [1, 1], 'Mary should have popular bounds [1,1] for t=1 timesteps'
48
+
assert'Mary'indataframes[4]['component'].valuesanddataframes[4].iloc[0].popular== [1, 1], 'Mary should have popular bounds [1,1] for t=2 timesteps'
49
+
50
+
# Justin should be popular in timesteps 1, 2
51
+
assert'Justin'indataframes[3]['component'].valuesanddataframes[3].iloc[1].popular== [1, 1], 'Justin should have popular bounds [1,1] for t=1 timesteps'
52
+
assert'Justin'indataframes[4]['component'].valuesanddataframes[4].iloc[2].popular== [1, 1], 'Justin should have popular bounds [1,1] for t=2 timesteps'
53
+
54
+
# John should be popular in timestep 3
55
+
assert'John'indataframes[4]['component'].valuesanddataframes[4].iloc[1].popular== [1, 1], 'John should have popular bounds [1,1] for t=2 timesteps'
0 commit comments