Skip to content

Commit f725af0

Browse files
committed
Clean up docstrings so the Sphinx build is warning-free (#666)
Reformat the docstrings flagged by the Sphinx (autodoc) build so they parse as valid reStructuredText, without changing any wording or code: indented class hierarchies, attribute/argument lists, usage examples and equations are now proper literal blocks (`::` + surrounding blank lines), enumerated/bulleted lists get the required blank line, and stray inline markup (unbalanced backticks, `*args`, `P(e|s)` pipes) is escaped, switching the affected docstrings to raw strings where needed. Covers agents, agents4e, csp, planning, logic, logic4e, learning, learning4e, reinforcement_learning(4e), utils, utils4e, games, games4e, mdp, mdp4e, probability, probability4e, perception4e, deep_learning4e, knowledge, probabilistic_learning, search and text. The docs now build with 0 warnings (was 126); all module imports and test suites are unaffected.
1 parent a233e66 commit f725af0

24 files changed

Lines changed: 381 additions & 322 deletions

agents.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
"""
22
Implement Agents and Environments. (Chapters 1-2)
33
4-
The class hierarchies are as follows:
4+
The class hierarchies are as follows::
55
6-
Thing ## A physical object that can exist in an environment
7-
Agent
8-
Wumpus
9-
Dirt
10-
Wall
11-
...
6+
Thing ## A physical object that can exist in an environment
7+
Agent
8+
Wumpus
9+
Dirt
10+
Wall
11+
...
12+
13+
Environment ## An environment holds objects, runs simulations
14+
XYEnvironment
15+
VacuumEnvironment
16+
WumpusEnvironment
1217
13-
Environment ## An environment holds objects, runs simulations
14-
XYEnvironment
15-
VacuumEnvironment
16-
WumpusEnvironment
18+
An agent program is a callable instance, taking percepts and choosing actions::
1719
18-
An agent program is a callable instance, taking percepts and choosing actions
1920
SimpleReflexAgentProgram
2021
...
2122
22-
EnvGUI ## A window with a graphical representation of the Environment
23+
The GUI helpers are::
2324
24-
EnvToolbar ## contains buttons for controlling EnvGUI
25-
26-
EnvCanvas ## Canvas to display the environment of an EnvGUI
25+
EnvGUI ## A window with a graphical representation of the Environment
26+
EnvToolbar ## contains buttons for controlling EnvGUI
27+
EnvCanvas ## Canvas to display the environment of an EnvGUI
2728
"""
2829

2930
# TODO
@@ -284,10 +285,12 @@ def program(percept):
284285

285286
class Environment:
286287
"""Abstract class representing an Environment. 'Real' Environment classes
287-
inherit from this. Your Environment will typically need to implement:
288-
percept: Define the percept that an agent sees.
289-
execute_action: Define the effects of executing an action.
290-
Also update the agent.performance slot.
288+
inherit from this. Your Environment will typically need to implement::
289+
290+
percept: Define the percept that an agent sees.
291+
execute_action: Define the effects of executing an action;
292+
also update the agent.performance slot.
293+
291294
The environment keeps a list of .things and .agents (which is a subset
292295
of .things). Each agent has a .performance slot, initialized to 0.
293296
Each thing has a .location slot, even though some environments may not
@@ -385,13 +388,16 @@ def delete_thing(self, thing):
385388

386389

387390
class Direction:
388-
"""A direction class for agents that want to move in a 2D plane
389-
Usage:
390-
d = Direction("down")
391-
To change directions:
392-
d = d + "right" or d = d + Direction.R #Both do the same thing
393-
Note that the argument to __add__ must be a string and not a Direction object.
394-
Also, it (the argument) can only be right or left."""
391+
"""A direction class for agents that want to move in a 2D plane.
392+
393+
Usage::
394+
395+
d = Direction("down")
396+
# to change directions:
397+
d = d + "right" or d = d + Direction.R # both do the same thing
398+
399+
Note that the argument to __add__ must be a string and not a Direction
400+
object, and it can only be 'right' or 'left'."""
395401

396402
R = "right"
397403
L = "left"

agents4e.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
22
Implement Agents and Environments. (Chapters 1-2)
33
4-
The class hierarchies are as follows:
4+
The class hierarchies are as follows::
55
6-
Thing ## A physical object that can exist in an environment
7-
Agent
8-
Wumpus
9-
Dirt
10-
Wall
11-
...
6+
Thing ## A physical object that can exist in an environment
7+
Agent
8+
Wumpus
9+
Dirt
10+
Wall
11+
...
12+
13+
Environment ## An environment holds objects, runs simulations
14+
XYEnvironment
15+
VacuumEnvironment
16+
WumpusEnvironment
1217
13-
Environment ## An environment holds objects, runs simulations
14-
XYEnvironment
15-
VacuumEnvironment
16-
WumpusEnvironment
18+
An agent program is a callable instance, taking percepts and choosing actions::
1719
18-
An agent program is a callable instance, taking percepts and choosing actions
1920
SimpleReflexAgentProgram
2021
...
2122
@@ -289,10 +290,12 @@ def program(percept):
289290

290291
class Environment:
291292
"""Abstract class representing an Environment. 'Real' Environment classes
292-
inherit from this. Your Environment will typically need to implement:
293+
inherit from this. Your Environment will typically need to implement::
294+
293295
percept: Define the percept that an agent sees.
294296
execute_action: Define the effects of executing an action.
295297
Also update the agent.performance slot.
298+
296299
The environment keeps a list of .things and .agents (which is a subset
297300
of .things). Each agent has a .performance slot, initialized to 0.
298301
Each thing has a .location slot, even though some environments may not
@@ -391,12 +394,15 @@ def delete_thing(self, thing):
391394

392395
class Direction:
393396
"""A direction class for agents that want to move in a 2D plane
394-
Usage:
395-
d = Direction("down")
396-
To change directions:
397-
d = d + "right" or d = d + Direction.R #Both do the same thing
398-
Note that the argument to __add__ must be a string and not a Direction object.
399-
Also, it (the argument) can only be right or left."""
397+
398+
Usage::
399+
400+
d = Direction("down")
401+
To change directions:
402+
d = d + "right" or d = d + Direction.R #Both do the same thing
403+
Note that the argument to __add__ must be a string and not a Direction object.
404+
Also, it (the argument) can only be right or left.
405+
"""
400406

401407
R = "right"
402408
L = "left"

csp.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
class CSP(search.Problem):
1818
"""This class describes finite-domain Constraint Satisfaction Problems.
19-
A CSP is specified by the following inputs:
19+
A CSP is specified by the following inputs::
20+
2021
variables A list of variables; each is atomic (e.g. int or string).
2122
domains A dict of {var:[possible_value, ...]} entries.
2223
neighbors A dict of {var:[var,...]} that for each variable lists
@@ -35,18 +36,23 @@ class CSP(search.Problem):
3536
However, the class also supports data structures and methods that help you
3637
solve CSPs by calling a search function on the CSP. Methods and slots are
3738
as follows, where the argument 'a' represents an assignment, which is a
38-
dict of {var:val} entries:
39+
dict of {var:val} entries::
40+
3941
assign(var, val, a) Assign a[var] = val; do other bookkeeping
4042
unassign(var, a) Do del a[var], plus other bookkeeping
4143
nconflicts(var, val, a) Return the number of other variables that
4244
conflict with var=val
4345
curr_domains[var] Slot: remaining consistent values for var
4446
Used by constraint propagation routines.
45-
The following methods are used only by graph_search and tree_search:
47+
48+
The following methods are used only by graph_search and tree_search::
49+
4650
actions(state) Return a list of actions
4751
result(state, action) Return a successor of state
4852
goal_test(state) Return true if all constraints satisfied
49-
The following are just for debugging purposes:
53+
54+
The following are just for debugging purposes::
55+
5056
nassigns Slot: tracks the number of assignments made
5157
display(a) Print a human-readable representation
5258
"""
@@ -656,17 +662,20 @@ class NQueensCSP(CSP):
656662
Suitable for large n, it uses only data structures of size O(n).
657663
Think of placing queens one per column, from left to right.
658664
That means position (x, y) represents (var, val) in the CSP.
659-
The main structures are three arrays to count queens that could conflict:
665+
The main structures are three arrays to count queens that could conflict::
666+
660667
rows[i] Number of queens in the ith row (i.e. val == i)
661668
downs[i] Number of queens in the \ diagonal
662669
such that their (x, y) coordinates sum to i
663670
ups[i] Number of queens in the / diagonal
664671
such that their (x, y) coordinates have x-y+n-1 = i
672+
665673
We increment/decrement these counts each time a queen is placed/moved from
666674
a row/diagonal. So moving is O(1), as is nconflicts. But choosing
667675
a variable, and a best value for the variable, are each O(n).
668676
If you want, you can keep track of conflicted variables, then variable
669677
selection will also be O(1).
678+
670679
>>> len(backtracking_search(NQueensCSP(8)))
671680
8
672681
"""
@@ -947,8 +956,9 @@ def display(self, assignment=None):
947956

948957
def consistent(self, assignment):
949958
"""assignment is a variable:value dictionary
959+
950960
returns True if all of the constraints that can be evaluated
951-
evaluate to True given assignment.
961+
evaluate to True given assignment.
952962
"""
953963
return all(con.holds(assignment)
954964
for con in self.constraints

deep_learning4e.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,11 @@ def keras_dataset_loader(dataset, max_length=500):
526526
def SimpleRNNLearner(train_data, val_data, epochs=2, verbose=False):
527527
"""
528528
RNN example for text sentimental analysis.
529-
:param train_data: a tuple of (training data, targets)
530-
Training data: ndarray taking training examples, while each example is coded by embedding
531-
Targets: ndarray taking targets of each example. Each target is mapped to an integer
529+
530+
:param train_data:
531+
a tuple of (training data, targets)
532+
Training data: ndarray taking training examples, while each example is coded by embedding
533+
Targets: ndarray taking targets of each example. Each target is mapped to an integer
532534
:param val_data: a tuple of (validation data, targets)
533535
:param epochs: number of epochs
534536
:param verbose: verbosity mode

games.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def expect_minmax(state, game):
5050
"""
5151
[Figure 5.11]
5252
Return the best move for a player after dice are thrown. The game tree
53-
includes chance nodes along with min and max nodes.
54-
"""
53+
includes chance nodes along with min and max nodes.
54+
"""
5555
player = game.to_move(state)
5656

5757
def max_value(state):
@@ -535,8 +535,8 @@ def checkers_at_home(self, board, player):
535535

536536
def is_legal_move(self, board, start, steps, player):
537537
"""Move is a tuple which contains starting points of checkers to be
538-
moved during a player's turn. An on-board move is legal if both the destinations
539-
are open. A bear-off move is the one where a checker is moved off-board.
538+
moved during a player's turn. An on-board move is legal if both the destinations
539+
are open. A bear-off move is the one where a checker is moved off-board.
540540
It is legal only after a player has moved all his checkers to his home."""
541541
dest1, dest2 = vector_add(start, steps)
542542
dest_range = range(0, 24)

games4e.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def expect_minmax(state, game):
5050
"""
5151
[Figure 5.11]
5252
Return the best move for a player after dice are thrown. The game tree
53-
includes chance nodes along with min and max nodes.
54-
"""
53+
includes chance nodes along with min and max nodes.
54+
"""
5555
player = game.to_move(state)
5656

5757
def max_value(state):
@@ -576,8 +576,8 @@ def checkers_at_home(self, board, player):
576576

577577
def is_legal_move(self, board, start, steps, player):
578578
"""Move is a tuple which contains starting points of checkers to be
579-
moved during a player's turn. An on-board move is legal if both the destinations
580-
are open. A bear-off move is the one where a checker is moved off-board.
579+
moved during a player's turn. An on-board move is legal if both the destinations
580+
are open. A bear-off move is the one where a checker is moved off-board.
581581
It is legal only after a player has moved all his checkers to his home."""
582582
dest1, dest2 = vector_add(start, steps)
583583
dest_range = range(0, 24)

knowledge.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@ def choose_literal(self, literals, examples):
320320
def gain(self, l, examples):
321321
"""
322322
Find the utility of each literal when added to the body of the clause.
323-
Utility function is:
323+
Utility function is::
324+
324325
gain(R, l) = T * (log_2 (post_pos / (post_pos + post_neg)) - log_2 (pre_pos / (pre_pos + pre_neg)))
325326
326-
where:
327-
327+
where::
328+
328329
pre_pos = number of positive bindings of rule R (=current set of rules)
329330
pre_neg = number of negative bindings of rule R
330331
post_pos = number of positive bindings of rule R' (= R U {l} )

0 commit comments

Comments
 (0)