diff --git a/README.md b/README.md index 968632477..3ab5777c1 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] | Done | | | 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] | Done | | | 9.8 | Append | | | | | -| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | | +| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | Included | | 10.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | | | 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | | | 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | | diff --git a/agents.py b/agents.py index 9b1ff0d33..eb085757a 100644 --- a/agents.py +++ b/agents.py @@ -96,7 +96,7 @@ def program(percept): self.program = program def can_grab(self, thing): - """Returns True if this agent can grab this thing. + """Return True if this agent can grab this thing. Override for appropriate subclasses of Agent and Thing.""" return False @@ -444,7 +444,7 @@ def move_to(self, thing, destination): return thing.bump def add_thing(self, thing, location=(1, 1), exclude_duplicate_class_items=False): - """Adds things to the world. If (exclude_duplicate_class_items) then the item won't be + """Add things to the world. If (exclude_duplicate_class_items) then the item won't be added if the location has at least one item of the same class.""" if (self.is_inbounds(location)): if (exclude_duplicate_class_items and @@ -809,7 +809,7 @@ def init_world(self, program): self.add_thing(Explorer(program), (1, 1), True) def get_world(self, show_walls=True): - """Returns the items in the world""" + """Return the items in the world""" result = [] x_start, y_start = (0, 0) if show_walls else (1, 1) @@ -826,7 +826,7 @@ def get_world(self, show_walls=True): return result def percepts_from(self, agent, location, tclass=Thing): - """Returns percepts from a given location, + """Return percepts from a given location, and replaces some items with percepts from chapter 7.""" thing_percepts = { Gold: Glitter(), @@ -846,7 +846,7 @@ def percepts_from(self, agent, location, tclass=Thing): return result if len(result) else [None] def percept(self, agent): - """Returns things in adjacent (not diagonal) cells of the agent. + """Return things in adjacent (not diagonal) cells of the agent. Result format: [Left, Right, Up, Down, Center / Current location]""" x, y = agent.location result = [] @@ -907,7 +907,7 @@ def execute_action(self, agent, action): agent.has_arrow = False def in_danger(self, agent): - """Checks if Explorer is in danger (Pit or Wumpus), if he is, kill him""" + """Check if Explorer is in danger (Pit or Wumpus), if he is, kill him""" for thing in self.list_things_at(agent.location): if isinstance(thing, Pit) or (isinstance(thing, Wumpus) and thing.alive): agent.alive = False diff --git a/csp.ipynb b/csp.ipynb index 1de9e1312..af85b81d6 100644 --- a/csp.ipynb +++ b/csp.ipynb @@ -18,7 +18,8 @@ "outputs": [], "source": [ "from csp import *\n", - "from notebook import psource, pseudocode\n", + "from notebook import psource, pseudocode, plot_NQueens\n", + "%matplotlib inline\n", "\n", "# Hide warnings in the matplotlib sections\n", "import warnings\n", @@ -52,7 +53,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(CSP)" @@ -105,7 +108,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(different_values_constraint)" @@ -139,7 +144,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(MapColoringCSP)" @@ -153,9 +160,9 @@ { "data": { "text/plain": [ - "(,\n", - " ,\n", - " )" + "(,\n", + " ,\n", + " )" ] }, "execution_count": 3, @@ -178,9 +185,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
def queen_constraint(A, a, B, b):\n",
+       "    """Constraint is satisfied (true) if A, B are really the same variable,\n",
+       "    or if they are not in the same row, down diagonal, or up diagonal."""\n",
+       "    return A == B or (a != b and A + a != B + b and A - a != B - b)\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "psource(queen_constraint)" ] @@ -194,9 +306,191 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
class NQueensCSP(CSP):\n",
+       "    """Make a CSP for the nQueens problem for search with min_conflicts.\n",
+       "    Suitable for large n, it uses only data structures of size O(n).\n",
+       "    Think of placing queens one per column, from left to right.\n",
+       "    That means position (x, y) represents (var, val) in the CSP.\n",
+       "    The main structures are three arrays to count queens that could conflict:\n",
+       "        rows[i]      Number of queens in the ith row (i.e val == i)\n",
+       "        downs[i]     Number of queens in the \\ diagonal\n",
+       "                     such that their (x, y) coordinates sum to i\n",
+       "        ups[i]       Number of queens in the / diagonal\n",
+       "                     such that their (x, y) coordinates have x-y+n-1 = i\n",
+       "    We increment/decrement these counts each time a queen is placed/moved from\n",
+       "    a row/diagonal. So moving is O(1), as is nconflicts.  But choosing\n",
+       "    a variable, and a best value for the variable, are each O(n).\n",
+       "    If you want, you can keep track of conflicted variables, then variable\n",
+       "    selection will also be O(1).\n",
+       "    >>> len(backtracking_search(NQueensCSP(8)))\n",
+       "    8\n",
+       "    """\n",
+       "\n",
+       "    def __init__(self, n):\n",
+       "        """Initialize data structures for n Queens."""\n",
+       "        CSP.__init__(self, list(range(n)), UniversalDict(list(range(n))),\n",
+       "                     UniversalDict(list(range(n))), queen_constraint)\n",
+       "\n",
+       "        self.rows = [0]*n\n",
+       "        self.ups = [0]*(2*n - 1)\n",
+       "        self.downs = [0]*(2*n - 1)\n",
+       "\n",
+       "    def nconflicts(self, var, val, assignment):\n",
+       "        """The number of conflicts, as recorded with each assignment.\n",
+       "        Count conflicts in row and in up, down diagonals. If there\n",
+       "        is a queen there, it can't conflict with itself, so subtract 3."""\n",
+       "        n = len(self.variables)\n",
+       "        c = self.rows[val] + self.downs[var+val] + self.ups[var-val+n-1]\n",
+       "        if assignment.get(var, None) == val:\n",
+       "            c -= 3\n",
+       "        return c\n",
+       "\n",
+       "    def assign(self, var, val, assignment):\n",
+       "        """Assign var, and keep track of conflicts."""\n",
+       "        oldval = assignment.get(var, None)\n",
+       "        if val != oldval:\n",
+       "            if oldval is not None:  # Remove old val if there was one\n",
+       "                self.record_conflict(assignment, var, oldval, -1)\n",
+       "            self.record_conflict(assignment, var, val, +1)\n",
+       "            CSP.assign(self, var, val, assignment)\n",
+       "\n",
+       "    def unassign(self, var, assignment):\n",
+       "        """Remove var from assignment (if it is there) and track conflicts."""\n",
+       "        if var in assignment:\n",
+       "            self.record_conflict(assignment, var, assignment[var], -1)\n",
+       "        CSP.unassign(self, var, assignment)\n",
+       "\n",
+       "    def record_conflict(self, assignment, var, val, delta):\n",
+       "        """Record conflicts caused by addition or deletion of a Queen."""\n",
+       "        n = len(self.variables)\n",
+       "        self.rows[val] += delta\n",
+       "        self.downs[var + val] += delta\n",
+       "        self.ups[var - val + n - 1] += delta\n",
+       "\n",
+       "    def display(self, assignment):\n",
+       "        """Print the queens and the nconflicts values (for debugging)."""\n",
+       "        n = len(self.variables)\n",
+       "        for val in range(n):\n",
+       "            for var in range(n):\n",
+       "                if assignment.get(var, '') == val:\n",
+       "                    ch = 'Q'\n",
+       "                elif (var + val) % 2 == 0:\n",
+       "                    ch = '.'\n",
+       "                else:\n",
+       "                    ch = '-'\n",
+       "                print(ch, end=' ')\n",
+       "            print('    ', end=' ')\n",
+       "            for var in range(n):\n",
+       "                if assignment.get(var, '') == val:\n",
+       "                    ch = '*'\n",
+       "                else:\n",
+       "                    ch = ' '\n",
+       "                print(str(self.nconflicts(var, val, assignment)) + ch, end=' ')\n",
+       "            print()\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "psource(NQueensCSP)" ] @@ -210,7 +504,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "collapsed": true }, @@ -219,6 +513,241 @@ "eight_queens = NQueensCSP(8)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have defined our CSP. \n", + "We now need to solve this.\n", + "\n", + "### Min-conflicts\n", + "As stated above, the `min_conflicts` algorithm is an efficient method to solve such a problem.\n", + "
\n", + "To begin with, all the variables of the CSP are _randomly_ initialized. \n", + "
\n", + "The algorithm then randomly selects a variable that has conflicts and violates some constraints of the CSP.\n", + "
\n", + "The selected variable is then assigned a value that _minimizes_ the number of conflicts.\n", + "
\n", + "This is a simple stochastic algorithm which works on a principle similar to **Hill-climbing**.\n", + "The conflicting state is repeatedly changed into a state with fewer conflicts in an attempt to reach an approximate solution.\n", + "
\n", + "This algorithm sometimes benefits from having a good initial assignment.\n", + "Using greedy techniques to get a good initial assignment and then using `min_conflicts` to solve the CSP can speed up the procedure dramatically, especially for CSPs with a large state space." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
def min_conflicts(csp, max_steps=100000):\n",
+       "    """Solve a CSP by stochastic hillclimbing on the number of conflicts."""\n",
+       "    # Generate a complete assignment for all variables (probably with conflicts)\n",
+       "    csp.current = current = {}\n",
+       "    for var in csp.variables:\n",
+       "        val = min_conflicts_value(csp, var, current)\n",
+       "        csp.assign(var, val, current)\n",
+       "    # Now repeatedly choose a random conflicted variable and change it\n",
+       "    for i in range(max_steps):\n",
+       "        conflicted = csp.conflicted_vars(current)\n",
+       "        if not conflicted:\n",
+       "            return current\n",
+       "        var = random.choice(conflicted)\n",
+       "        val = min_conflicts_value(csp, var, current)\n",
+       "        csp.assign(var, val, current)\n",
+       "    return None\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "psource(min_conflicts)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's use this algorithm to solve the `eight_queens` CSP." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "solution = min_conflicts(eight_queens)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is indeed a valid solution. \n", + "
\n", + "`notebook.py` has a helper function to visualize the solution space." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAAHwCAYAAABkPlyAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3X+4FNWd7/vPd9gbEMOvDRtMgGtg\nkifnTowY2SPOELnEkDEgGD137gxco0dzczk39xiC4GRGnmeemDwnmqsCIXHu5OTIgOeMAc04RtRE\niUYwYNTZMMrEZOY+BkxE5McWCCgmAmfdP2q3u7t3VXV1d1VXV9X79Tz9dHfVqrVW92Lz7bVq1Spz\nzgkAALS330u7AgAAoDYCNgAAGUDABgAgAwjYAABkAAEbAIAMIGADAJABBGwAADKAgA0AQAYQsIE2\nY2bvN7MfmNlRMztgZneZWUdI+jFm9rf9aU+a2b+Y2X9oZZ0BJI+ADbSf/1fSIUnvlXSBpP9F0v/t\nl9DMhkp6QtK5kv5I0mhJfyHpdjNb2pLaAmgJAjbQfqZKut8591vn3AFJj0n6cEDaayT9T5L+N+fc\nXufcKefcY5KWSvrPZjZSkszMmdkHSgeZ2QYz+89l7xeY2QtmdszMnjGz88v2vc/MHjCzw2a2t/yH\ngJndYmb3m9l/M7MTZva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AAAAElFTkSuQmCC\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "plot_NQueens(solution)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lets' see if we can find a different solution." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAAHwCAYAAABkPlyAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3X+4FNWd7/vPd9gbEMOvDRtMgGtg\nkifnTowY2SPOELnEkDEgGD137gxco0dzczk39xiC4GRGnmeemDwnmqsCIXHu5OTIgOeMAc04RtRE\niUYwYNTZMMrEZOY+BkxE5McWCCgmAmfdP2q3u7t3VXV1d1VXV9X79Tz9dHfVqrVW92Lz7bVq1Spz\nzgkAALS330u7AgAAoDYCNgAAGUDABgAgAwjYAABkAAEbAIAMIGADAJABBGwAADKAgA0AQAYQsIE2\nY2bvN7MfmNlRMztgZneZWUdI+jFm9rf9aU+a2b+Y2X9oZZ0BJI+ADbSf/1fSIUnvlXSBpP9F0v/t\nl9DMhkp6QtK5kv5I0mhJfyHpdjNb2pLaAmgJAjbQfqZKut8591vn3AFJj0n6cEDaayT9T5L+N+fc\nXufcKefcY5KWSvrPZjZSkszMmdkHSgeZ2QYz+89l7xeY2QtmdszMnjGz88v2vc/MHjCzw2a2t/yH\ngJndYmb3m9l/M7MTZvaSmfWU7f9LM3utf9+/mdkn4vmKgOIhYAPtZ62kRWY2wswmSZonL2j7+aSk\nHzrn3qra/oCkEZIurlWYmV0o6e8k/UdJ4yT9F0mbzWyYmf2epIclvShpkqRPSFpmZpeVZXGFpE2S\nxkjaLOmu/nw/JOkGSX/onBsp6T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3ucc+9I\n2iTp0ynXKTbOuaclHZMOmcMAAAJ8SURBVEm7Hklxzr3unNvV//qEpF9ImpRureLlPG/2v+3sf+Tm\nF7WZTZZ0uaS7064L6mdmoyTNlrROkpxz7+QxWPf7hKRftlOwlooVsCdJerXs/T7l7D/8ojCz90v6\nqKTn0q1J/PqHjF+QdEjSj5xzefqM35D0JUn/I+2KJMhJ2mJmO81sSdqVidk0SYclre8/rXG3mZ2d\ndqUSskjSxrQrUa1IAdtvMdrc9F6KwszeI+kBScucc8fTrk/cnHNnnHMXSJos6SIzy8XpDTNbIOmQ\nc25n2nVJ2Czn3IWS5kn6T/2nqvKiQ9KFkv7WOfdRSW9JytVcIEnqH+q/QtL30q5LtSIF7H2SppS9\nnyxpf0p1QQP6z+s+IOle59w/pl2fJPUPNW6V9KmUqxKXWZKu6D/Hu0nSpWb29+lWKX7Ouf39z4ck\nPSjvVFxe7JO0r2zU5x/kBfC8mSdpl3PuYNoVqVakgP1Pkj5oZlP7f0EtkrQ55Tohov4JWesk/cI5\ntzrt+iTBzLrNbEz/67MkzZX0r+nWKh7OuZudc5Odc++X97f3Y+fcZ1KuVqzM7Oz+CZHqHyr+E0m5\nuWrDOXdA0qtm9qH+TZ+QlJtJn2UWqw2Hw6X2uL1mSzjnTpvZDZIelzRE0t85515KuVqxMbONkuZI\nGm9m+yR92Tm3Lt1axWqWpGsk/Uv/OV5JWumc+0GKdYrbeyXd0z9D9fck3e+cy+XlTzk1UdKD/beC\n7JD0XefcY+lWKXZfkHRvf6dnj6TrU65PrMxshLwrif5j2nXxU5jLugAAyLIiDYkDAJBZBGwAADKA\ngA0AQAYQsAEAyAACNgAAGUDABgAgAwjYAABkwP8PfpHmmmpMFEsAAAAASUVORK5CYII=\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "eight_queens = NQueensCSP(8)\n", + "solution = min_conflicts(eight_queens)\n", + "plot_NQueens(solution)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution is a bit different this time. \n", + "Running the above cell several times should give you various valid solutions.\n", + "
\n", + "In the `search.ipynb` notebook, we will see how NQueensProblem can be solved using a heuristic search method such as `uniform_cost_search` and `astar_search`." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -466,7 +995,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(mrv)" @@ -475,7 +1006,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(num_legal_values)" @@ -484,7 +1017,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(CSP.nconflicts)" @@ -500,7 +1035,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(lcv)" @@ -663,7 +1200,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "psource(tree_csp_solver)" @@ -1162,11 +1701,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.3" - }, - "widgets": { - "state": {}, - "version": "1.1.1" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/csp.py b/csp.py index 62772c322..70223acf2 100644 --- a/csp.py +++ b/csp.py @@ -351,7 +351,7 @@ def topological_sort(X, root): def build_topological(node, parent, neighbors, visited, stack, parents): - """Builds the topological sort and the parents of each node in the graph""" + """Build the topological sort and the parents of each node in the graph.""" visited[node] = True for n in neighbors[node]: @@ -427,7 +427,7 @@ def MapColoringCSP(colors, neighbors): different_values_constraint) -def parse_neighbors(neighbors, variables=[]): +def parse_neighbors(neighbors, variables=None): """Convert a string of the form 'X: Y Z; Y: Z' into a dict mapping regions to neighbors. The syntax is a region name followed by a ':' followed by zero or more region names, followed by ';', repeated for diff --git a/knowledge.py b/knowledge.py index 6fe09acd2..2bb12f3b8 100644 --- a/knowledge.py +++ b/knowledge.py @@ -11,13 +11,14 @@ # ______________________________________________________________________________ -def current_best_learning(examples, h, examples_so_far=[]): +def current_best_learning(examples, h, examples_so_far=None): """ [Figure 19.2] The hypothesis is a list of dictionaries, with each dictionary representing a disjunction.""" if not examples: return h + examples_so_far = examples_so_far or [] e = examples[0] if is_consistent(e, h): return current_best_learning(examples[1:], h, examples_so_far + [e]) @@ -95,7 +96,7 @@ def generalizations(examples_so_far, h): def add_or(examples_so_far, h): - """Adds an OR operation to the hypothesis. The AND operations in the disjunction + """Add an OR operation to the hypothesis. The AND operations in the disjunction are generated by the last example (which is the problematic one).""" ors = [] e = examples_so_far[-1] @@ -135,7 +136,7 @@ def version_space_update(V, e): def all_hypotheses(examples): - """Builds a list of all the possible hypotheses""" + """Build a list of all the possible hypotheses""" values = values_table(examples) h_powerset = powerset(values.keys()) hypotheses = [] @@ -148,7 +149,7 @@ def all_hypotheses(examples): def values_table(examples): - """Builds a table with all the possible values for each attribute. + """Build a table with all the possible values for each attribute. Returns a dictionary with keys the attribute names and values a list with the possible values for the corresponding attribute.""" values = defaultdict(lambda: []) @@ -210,7 +211,7 @@ def build_h_combinations(hypotheses): def minimal_consistent_det(E, A): - """Returns a minimal set of attributes which give consistent determination""" + """Return a minimal set of attributes which give consistent determination""" n = len(A) for i in range(n + 1): @@ -220,7 +221,7 @@ def minimal_consistent_det(E, A): def consistent_det(A, E): - """Checks if the attributes(A) is consistent with the examples(E)""" + """Check if the attributes(A) is consistent with the examples(E)""" H = {} for e in E: @@ -235,9 +236,9 @@ def consistent_det(A, E): class FOIL_container(FolKB): - """Holds the kb and other necessary elements required by FOIL""" + """Hold the kb and other necessary elements required by FOIL.""" - def __init__(self, clauses=[]): + def __init__(self, clauses=None): self.const_syms = set() self.pred_syms = set() FolKB.__init__(self, clauses) @@ -251,7 +252,7 @@ def tell(self, sentence): raise Exception("Not a definite clause: {}".format(sentence)) def foil(self, examples, target): - """Learns a list of first-order horn clauses + """Learn a list of first-order horn clauses 'examples' is a tuple: (positive_examples, negative_examples). positive_examples and negative_examples are both lists which contain substitutions.""" clauses = [] @@ -268,10 +269,10 @@ def foil(self, examples, target): return clauses def new_clause(self, examples, target): - """Finds a horn clause which satisfies part of the positive + """Find a horn clause which satisfies part of the positive examples but none of the negative examples. The horn clause is specified as [consequent, list of antecedents] - Return value is the tuple (horn_clause, extended_positive_examples)""" + Return value is the tuple (horn_clause, extended_positive_examples).""" clause = [target, []] # [positive_examples, negative_examples] extended_examples = examples @@ -284,14 +285,14 @@ def new_clause(self, examples, target): return (clause, extended_examples[0]) def extend_example(self, example, literal): - """Generates extended examples which satisfy the literal""" + """Generate extended examples which satisfy the literal.""" # find all substitutions that satisfy literal for s in self.ask_generator(subst(example, literal)): s.update(example) yield s def new_literals(self, clause): - """Generates new literals based on known predicate symbols. + """Generate new literals based on known predicate symbols. Generated literal must share atleast one variable with clause""" share_vars = variables(clause[0]) for l in clause[1]: @@ -304,7 +305,7 @@ def new_literals(self, clause): yield Expr(pred, *[var for var in args]) def choose_literal(self, literals, examples): - """Chooses the best literal based on the information gain""" + """Choose the best literal based on the information gain.""" def gain(l): pre_pos = len(examples[0]) pre_neg = len(examples[1]) @@ -328,8 +329,8 @@ def represents(d): return max(literals, key=gain) def update_examples(self, target, examples, extended_examples): - """Adds to the kb those examples what are represented in extended_examples - List of omitted examples is returned""" + """Add to the kb those examples what are represented in extended_examples + List of omitted examples is returned.""" uncovered = [] for example in examples: def represents(d): @@ -346,7 +347,7 @@ def represents(d): def check_all_consistency(examples, h): - """Check for the consistency of all examples under h""" + """Check for the consistency of all examples under h.""" for e in examples: if not is_consistent(e, h): return False @@ -355,7 +356,7 @@ def check_all_consistency(examples, h): def check_negative_consistency(examples, h): - """Check if the negative examples are consistent under h""" + """Check if the negative examples are consistent under h.""" for e in examples: if e['GOAL']: continue @@ -367,7 +368,7 @@ def check_negative_consistency(examples, h): def disjunction_value(e, d): - """The value of example e under disjunction d""" + """The value of example e under disjunction d.""" for k, v in d.items(): if v[0] == '!': # v is a NOT expression @@ -381,7 +382,7 @@ def disjunction_value(e, d): def guess_value(e, h): - """Guess value of example e under hypothesis h""" + """Guess value of example e under hypothesis h.""" for d in h: if disjunction_value(e, d): return True @@ -394,16 +395,8 @@ def is_consistent(e, h): def false_positive(e, h): - if e["GOAL"] == False: - if guess_value(e, h): - return True - - return False + return guess_value(e, h) and not e["GOAL"] def false_negative(e, h): - if e["GOAL"] == True: - if not guess_value(e, h): - return True - - return False + return e["GOAL"] and not guess_value(e, h) diff --git a/logic.ipynb b/logic.ipynb index 0cd6cbc1f..92b8f51ed 100644 --- a/logic.ipynb +++ b/logic.ipynb @@ -946,7 +946,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -955,7 +955,7 @@ "(True, False)" ] }, - "execution_count": 22, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -973,7 +973,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -982,7 +982,7 @@ "(False, False)" ] }, - "execution_count": 23, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -1438,55 +1438,520 @@ "\n" ], "text/plain": [ - "" + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "psource(pl_resolution)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(True, False)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pl_resolution(wumpus_kb, ~P11), pl_resolution(wumpus_kb, P11)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(False, False)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pl_resolution(wumpus_kb, ~P22), pl_resolution(wumpus_kb, P22)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Forward and backward chaining\n", + "Previously, we said we will look at two algorithms to check if a sentence is entailed by the `KB`, \n", + "but here's a third one. \n", + "The difference here is that our goal now is to determine if a knowledge base of definite clauses entails a single proposition symbol *q* - the query.\n", + "There is a catch however, the knowledge base can only contain **Horn clauses**.\n", + "
\n", + "#### Horn Clauses\n", + "Horn clauses can be defined as a *disjunction* of *literals* with **at most** one positive literal. \n", + "
\n", + "A Horn clause with exactly one positive literal is called a *definite clause*.\n", + "
\n", + "A Horn clause might look like \n", + "
\n", + "$\\neg a\\lor\\neg b\\lor\\neg c\\lor\\neg d... \\lor z$\n", + "
\n", + "This, coincidentally, is also a definite clause.\n", + "
\n", + "Using De Morgan's laws, the example above can be simplified to \n", + "
\n", + "$a\\land b\\land c\\land d ... \\implies z$\n", + "
\n", + "This seems like a logical representation of how humans process known data and facts. \n", + "Assuming percepts `a`, `b`, `c`, `d` ... to be true simultaneously, we can infer `z` to also be true at that point in time. \n", + "There are some interesting aspects of Horn clauses that make algorithmic inference or *resolution* easier.\n", + "- Definite clauses can be written as implications:\n", + "
\n", + "The most important simplification a definite clause provides is that it can be written as an implication.\n", + "The premise (or the knowledge that leads to the implication) is a conjunction of positive literals.\n", + "The conclusion (the implied statement) is also a positive literal.\n", + "The sentence thus becomes easier to understand.\n", + "The premise and the conclusion are conventionally called the *body* and the *head* respectively.\n", + "A single positive literal is called a *fact*.\n", + "- Forward chaining and backward chaining can be used for inference from Horn clauses:\n", + "
\n", + "Forward chaining is semantically identical to `AND-OR-Graph-Search` from the chapter on search algorithms.\n", + "Implementational details will be explained shortly.\n", + "- Deciding entailment with Horn clauses is linear in size of the knowledge base:\n", + "
\n", + "Surprisingly, the forward and backward chaining algorithms traverse each element of the knowledge base at most once, greatly simplifying the problem.\n", + "
\n", + "
\n", + "The function `pl_fc_entails` implements forward chaining to see if a knowledge base `KB` entails a symbol `q`.\n", + "
\n", + "Before we proceed further, note that `pl_fc_entails` doesn't use an ordinary `KB` instance. \n", + "The knowledge base here is an instance of the `PropDefiniteKB` class, derived from the `PropKB` class, \n", + "but modified to store definite clauses.\n", + "
\n", + "The main point of difference arises in the inclusion of a helper method to `PropDefiniteKB` that returns a list of clauses in KB that have a given symbol `p` in their premise." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
    def clauses_with_premise(self, p):\n",
+       "        """Return a list of the clauses in KB that have p in their premise.\n",
+       "        This could be cached away for O(1) speed, but we'll recompute it."""\n",
+       "        return [c for c in self.clauses\n",
+       "                if c.op == '==>' and p in conjuncts(c.args[0])]\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "psource(PropDefiniteKB.clauses_with_premise)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's now have a look at the `pl_fc_entails` algorithm." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
def pl_fc_entails(KB, q):\n",
+       "    """Use forward chaining to see if a PropDefiniteKB entails symbol q.\n",
+       "    [Figure 7.15]\n",
+       "    >>> pl_fc_entails(horn_clauses_KB, expr('Q'))\n",
+       "    True\n",
+       "    """\n",
+       "    count = {c: len(conjuncts(c.args[0]))\n",
+       "             for c in KB.clauses\n",
+       "             if c.op == '==>'}\n",
+       "    inferred = defaultdict(bool)\n",
+       "    agenda = [s for s in KB.clauses if is_prop_symbol(s.op)]\n",
+       "    while agenda:\n",
+       "        p = agenda.pop()\n",
+       "        if p == q:\n",
+       "            return True\n",
+       "        if not inferred[p]:\n",
+       "            inferred[p] = True\n",
+       "            for c in KB.clauses_with_premise(p):\n",
+       "                count[c] -= 1\n",
+       "                if count[c] == 0:\n",
+       "                    agenda.append(c.args[1])\n",
+       "    return False\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "psource(pl_fc_entails)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The function accepts a knowledge base `KB` (an instance of `PropDefiniteKB`) and a query `q` as inputs.\n", + "
\n", + "
\n", + "`count` initially stores the number of symbols in the premise of each sentence in the knowledge base.\n", + "
\n", + "The `conjuncts` helper function separates a given sentence at conjunctions.\n", + "
\n", + "`inferred` is initialized as a *boolean* defaultdict. \n", + "This will be used later to check if we have inferred all premises of each clause of the agenda.\n", + "
\n", + "`agenda` initially stores a list of clauses that the knowledge base knows to be true.\n", + "The `is_prop_symbol` helper function checks if the given symbol is a valid propositional logic symbol.\n", + "
\n", + "
\n", + "We now iterate through `agenda`, popping a symbol `p` on each iteration.\n", + "If the query `q` is the same as `p`, we know that entailment holds.\n", + "
\n", + "The agenda is processed, reducing `count` by one for each implication with a premise `p`.\n", + "A conclusion is added to the agenda when `count` reaches zero. This means we know all the premises of that particular implication to be true.\n", + "
\n", + "`clauses_with_premise` is a helpful method of the `PropKB` class.\n", + "It returns a list of clauses in the knowledge base that have `p` in their premise.\n", + "
\n", + "
\n", + "Now that we have an idea of how this function works, let's see a few examples of its usage, but we first need to define our knowledge base. We assume we know the following clauses to be true." + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "clauses = ['(B & F)==>E', \n", + " '(A & E & F)==>G', \n", + " '(B & C)==>F', \n", + " '(A & B)==>D', \n", + " '(E & F)==>H', \n", + " '(H & I)==>J',\n", + " 'A', \n", + " 'B', \n", + " 'C']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will now `tell` this information to our knowledge base." + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "definite_clauses_KB = PropDefiniteKB()\n", + "for clause in clauses:\n", + " definite_clauses_KB.tell(expr(clause))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can now check if our knowledge base entails the following queries." + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" ] }, + "execution_count": 44, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ - "psource(pl_resolution)" + "pl_fc_entails(definite_clauses_KB, expr('G'))" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(True, False)" + "True" ] }, - "execution_count": 25, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "pl_resolution(wumpus_kb, ~P11), pl_resolution(wumpus_kb, P11)" + "pl_fc_entails(definite_clauses_KB, expr('H'))" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(False, False)" + "False" ] }, - "execution_count": 26, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "pl_resolution(wumpus_kb, ~P22), pl_resolution(wumpus_kb, P22)" + "pl_fc_entails(definite_clauses_KB, expr('I'))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pl_fc_entails(definite_clauses_KB, expr('J'))" ] }, { @@ -2357,7 +2822,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 48, "metadata": { "collapsed": true }, @@ -2386,7 +2851,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 49, "metadata": { "collapsed": true }, @@ -2407,7 +2872,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 50, "metadata": { "collapsed": true }, @@ -2428,7 +2893,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 51, "metadata": { "collapsed": true }, @@ -2452,7 +2917,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 52, "metadata": { "collapsed": true }, @@ -2473,7 +2938,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 53, "metadata": { "collapsed": true }, @@ -2493,7 +2958,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 54, "metadata": { "collapsed": true }, @@ -2512,7 +2977,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 55, "metadata": { "collapsed": true }, @@ -2539,7 +3004,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -2548,7 +3013,7 @@ "{x: 3}" ] }, - "execution_count": 35, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -2559,7 +3024,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 57, "metadata": {}, "outputs": [ { @@ -2568,7 +3033,7 @@ "{x: B}" ] }, - "execution_count": 36, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -2579,7 +3044,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 58, "metadata": {}, "outputs": [ { @@ -2588,7 +3053,7 @@ "{x: Bella, y: Dobby}" ] }, - "execution_count": 37, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -2606,7 +3071,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 59, "metadata": {}, "outputs": [ { @@ -2630,7 +3095,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -2657,13 +3122,145 @@ }, { "cell_type": "code", - "execution_count": 40, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
def fol_fc_ask(KB, alpha):\n",
+       "    """A simple forward-chaining algorithm. [Figure 9.3]"""\n",
+       "    # TODO: Improve efficiency\n",
+       "    kb_consts = list({c for clause in KB.clauses for c in constant_symbols(clause)})\n",
+       "    def enum_subst(p):\n",
+       "        query_vars = list({v for clause in p for v in variables(clause)})\n",
+       "        for assignment_list in itertools.product(kb_consts, repeat=len(query_vars)):\n",
+       "            theta = {x: y for x, y in zip(query_vars, assignment_list)}\n",
+       "            yield theta\n",
+       "\n",
+       "    # check if we can answer without new inferences\n",
+       "    for q in KB.clauses:\n",
+       "        phi = unify(q, alpha, {})\n",
+       "        if phi is not None:\n",
+       "            yield phi\n",
+       "\n",
+       "    while True:\n",
+       "        new = []\n",
+       "        for rule in KB.clauses:\n",
+       "            p, q = parse_definite_clause(rule)\n",
+       "            for theta in enum_subst(p):\n",
+       "                if set(subst(theta, p)).issubset(set(KB.clauses)):\n",
+       "                    q_ = subst(theta, q)\n",
+       "                    if all([unify(x, q_, {}) is None for x in KB.clauses + new]):\n",
+       "                        new.append(q_)\n",
+       "                        phi = unify(q_, alpha, {})\n",
+       "                        if phi is not None:\n",
+       "                            yield phi\n",
+       "        if not new:\n",
+       "            break\n",
+       "        for clause in new:\n",
+       "            KB.tell(clause)\n",
+       "    return None\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "%psource fol_fc_ask" + "psource(fol_fc_ask)" ] }, { @@ -2675,7 +3272,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 62, "metadata": {}, "outputs": [ { @@ -2700,7 +3297,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -2742,7 +3339,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 64, "metadata": { "collapsed": true }, @@ -2761,7 +3358,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 65, "metadata": { "collapsed": true }, @@ -2779,7 +3376,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 66, "metadata": { "collapsed": true }, @@ -2791,7 +3388,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -2800,7 +3397,7 @@ "{v_5: x, x: Nono}" ] }, - "execution_count": 46, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -2827,7 +3424,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -2836,7 +3433,7 @@ "(P ==> ~Q)" ] }, - "execution_count": 47, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -2854,7 +3451,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -2863,7 +3460,7 @@ "(P ==> ~Q)" ] }, - "execution_count": 48, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -2881,7 +3478,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 70, "metadata": {}, "outputs": [ { @@ -2890,7 +3487,7 @@ "PartialExpr('==>', P)" ] }, - "execution_count": 49, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -2910,7 +3507,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 71, "metadata": {}, "outputs": [ { @@ -2919,7 +3516,7 @@ "(P ==> ~Q)" ] }, - "execution_count": 50, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -2949,7 +3546,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 72, "metadata": {}, "outputs": [ { @@ -2958,7 +3555,7 @@ "(~(P & Q) ==> (~P | ~Q))" ] }, - "execution_count": 51, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -2976,7 +3573,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -2985,7 +3582,7 @@ "(~(P & Q) ==> (~P | ~Q))" ] }, - "execution_count": 52, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -3004,7 +3601,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 74, "metadata": {}, "outputs": [ { @@ -3013,7 +3610,7 @@ "(((P & Q) ==> P) | Q)" ] }, - "execution_count": 53, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } @@ -3031,7 +3628,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -3040,7 +3637,7 @@ "((P & Q) ==> (P | Q))" ] }, - "execution_count": 54, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } @@ -3058,11 +3655,133 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "\n", + "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from notebook import Canvas_fol_bc_ask\n", "canvas_bc_ask = Canvas_fol_bc_ask('canvas_bc_ask', crime_kb, expr('Criminal(x)'))" diff --git a/logic.py b/logic.py index 5810e633f..130718faa 100644 --- a/logic.py +++ b/logic.py @@ -690,16 +690,321 @@ def sat_count(sym): # ______________________________________________________________________________ +class WumpusKB(PropKB): + """ + Create a Knowledge Base that contains the atemporal "Wumpus physics" and temporal rules with time zero. + """ + def __init__(self,dimrow): + super().__init__() + self.dimrow = dimrow + self.tell('( NOT W1s1 )') + self.tell('( NOT P1s1 )') + for i in range(1, dimrow+1): + for j in range(1, dimrow+1): + bracket = 0 + sentence_b_str = "( B" + i + "s" + j + " <=> " + sentence_s_str = "( S" + i + "s" + j + " <=> " + if i > 1: + sentence_b_str += "( P" + (i-1) + "s" + j + " OR " + sentence_s_str += "( W" + (i-1) + "s" + j + " OR " + bracket += 1 + + if i < dimRow: + sentence_b_str += "( P" + (i+1) + "s" + j + " OR " + sentence_s_str += "( W" + (i+1) + "s" + j + " OR " + bracket += 1 + + if j > 1: + if j == dimRow: + sentence_b_str += "P" + i + "s" + (j-1) + " " + sentence_s_str += "W "+ i + "s" + (j-1) + " " + else: + sentence_b_str += "( P" + i + "s" + (j-1) + " OR " + sentence_s_str += "( W" + i + "s" + (j-1) + " OR " + bracket += 1 + + if j < dimRow: + sentence_b_str += "P" + i + "s" + (j+1) + " " + sentence_s_str += "W" + i + "s" + (j+1) + " " + + + for _ in range(bracket): + sentence_b_str += ") " + sentence_s_str += ") " + + sentence_b_str += ") " + sentence_s_str += ") " + + self.tell(sentence_b_str) + self.tell(sentence_s_str) + + + ## Rule that describes existence of at least one Wumpus + sentence_w_str = "" + for i in range(1, dimrow+1): + for j in range(1, dimrow+1): + if (i == dimrow) and (j == dimrow): + sentence_w_str += " W" + dimRow + "s" + dimrow + " " + else: + sentence_w_str += "( W" + i + "s" + j + " OR " + for _ in range(dimrow**2): + sentence_w_str += ") " + self.tell(sentence_w_str) + + + ## Rule that describes existence of at most one Wumpus + for i in range(1, dimrow+1): + for j in range(1, dimrow+1): + for u in range(1, dimrow+1): + for v in range(1, dimrow+1): + if i!=u or j!=v: + self.tell("( ( NOT W" + i + "s" + j + " ) OR ( NOT W" + u + "s" + v + " ) )") + + ## Temporal rules at time zero + self.tell("L1s1s0") + for i in range(1, dimrow+1): + for j in range(1, dimrow + 1): + self.tell("( L" + i + "s" + j + "s0 => ( Breeze0 <=> B" + i + "s" + j + " ) )") + self.tell("( L" + i + "s" + j + "s0 => ( Stench0 <=> S" + i + "s" + j + " ) )") + if i != 1 or j != 1: + self.tell("( NOT L" + i + "s" + j + "s" + "0 )") + self.tell("WumpusAlive0") + self.tell("HaveArrow0") + self.tell("FacingEast0") + self.tell("( NOT FacingWest0 )") + self.tell("( NOT FacingNorth0 )") + self.tell("( NOT FacingSouth0 )") + + + def make_action_sentence(self, action, time): + self.tell(action + time) + + + def make_percept_sentence(self, percept, time): + self.tell(percept + time) + + def add_temporal_sentences(self, time): + if time == 0: + return + t = time - 1 + + ## current location rules (L2s2s3 represent tile 2,2 at time 3) + ## ex.: ( L2s2s3 <=> ( ( L2s2s2 AND ( ( NOT Forward2 ) OR Bump3 ) ) + ## OR ( ( L1s2s2 AND ( FacingEast2 AND Forward2 ) ) OR ( L2s1s2 AND ( FacingNorth2 AND Forward2 ) ) ) + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + self.tell("( L" + i + "s" + j + "s" + time + " => ( Breeze" + time + " <=> B" + i + "s" + j + " ) )") + self.tell("( L" + i + "s" + j + "s" + time + " => ( Stench" + time + " <=> S" + i + "s" + j + " ) )") + s = "( L" + i + "s" + j + "s" + time + " <=> ( ( L" + i + "s" + j + "s" + t + " AND ( ( NOT Forward"\ + + t + " ) OR Bump" + time + " ) )" + + count = 2 + if i != 1: + s += " OR ( ( L" + (i - 1) + "s" + j + "s" + t + " AND ( FacingEast" + t + " AND Forward" + t\ + + " ) )" + count += 1 + if i != self.dimrow: + s += " OR ( ( L" + (i + 1) + "s" + j + "s" + t + " AND ( FacingWest" + t + " AND Forward" + t\ + + " ) )" + count += 1 + if j != 1: + if j == self.dimrow: + s += " OR ( L" + i + "s" + (j - 1) + "s" + t + " AND ( FacingNorth" + t + " AND Forward" + t\ + + " ) )" + else: + s += " OR ( ( L" + i + "s" + (j - 1) + "s" + t + " AND ( FacingNorth" + t + " AND Forward" \ + + t + " ) )" + count += 1 + if j != self.dimrow: + s += " OR ( L" + i + "s" + (j + 1) + "s" + t + " AND ( FacingSouth" + t + " AND Forward" + t\ + + " ) )" + + for _ in range(count): + s += " )" + + ## add sentence about location i,j + self.tell(s) + + ## add sentence about safety of location i,j + self.tell("( OK" + i + "s" + j + "s" + time + " <=> ( ( NOT P" + i + "s" + j + " ) AND ( NOT ( W" + i\ + + "s" + j + " AND WumpusAlive" + time + " ) ) ) )") + + ## Rules about current orientation + ## ex.: ( FacingEast3 <=> ( ( FacingNorth2 AND TurnRight2 ) OR ( ( FacingSouth2 AND TurnLeft2 ) + ## OR ( FacingEast2 AND ( ( NOT TurnRight2 ) AND ( NOT TurnLeft2 ) ) ) ) ) ) + a = "( FacingNorth" + t + " AND TurnRight" + t + " )" + b = "( FacingSouth" + t + " AND TurnLeft" + t + " )" + c = "( FacingEast" + t + " AND ( ( NOT TurnRight" + t + " ) AND ( NOT TurnLeft" + t + " ) ) )" + s = "( FacingEast" + (t + 1) + " <=> ( " + a + " OR ( " + b + " OR " + c + " ) ) )" + this.tell(s) + + a = "( FacingNorth" + t + " AND TurnLeft" + t + " )" + b = "( FacingSouth" + t + " AND TurnRight" + t + " )" + c = "( FacingWest" + t + " AND ( ( NOT TurnRight" + t + " ) AND ( NOT TurnLeft" + t + " ) ) )" + s = "( FacingWest" + (t + 1) + " <=> ( " + a + " OR ( " + b + " OR " + c + " ) ) )" + this.tell(s) + + a = "( FacingEast" + t + " AND TurnLeft" + t + " )" + b = "( FacingWest" + t + " AND TurnRight" + t + " )" + c = "( FacingNorth" + t + " AND ( ( NOT TurnRight" + t + " ) AND ( NOT TurnLeft" + t + " ) ) )" + s = "( FacingNorth" + (t + 1) + " <=> ( " + a + " OR ( " + b + " OR " + c + " ) ) )" + this.tell(s) + + a = "( FacingWest" + t + " AND TurnLeft" + t + " )" + b = "( FacingEast" + t + " AND TurnRight" + t + " )" + c = "( FacingSouth" + t + " AND ( ( NOT TurnRight" + t + " ) AND ( NOT TurnLeft" + t + " ) ) )" + s = "( FacingSouth" + (t + 1) + " <=> ( " + a + " OR ( " + b + " OR " + c + " ) ) )" + this.tell(s) + + ## Rules about last action + self.tell("( Forward" + t + " <=> ( NOT TurnRight" + t + " ) )") + self.tell("( Forward" + t + " <=> ( NOT TurnLeft" + t + " ) )") + + ##Rule about the arrow + self.tell("( HaveArrow" + time + " <=> ( HaveArrow" + (time - 1) + " AND ( NOT Shot" + (time - 1) + " ) ) )") + + ##Rule about Wumpus (dead or alive) + self.tell("( WumpusAlive" + time + " <=> ( WumpusAlive" + (time - 1) + " AND ( NOT Scream" + time + " ) ) )") + + +# ______________________________________________________________________________ + + +class WumpusPosition(): + def __init__(self, X, Y, orientation): + self.X = X + self.Y = Y + self.orientation = orientation + + + def get_location(self): + return self.X, self.Y + + def get_orientation(self): + return self.orientation + + def equals(self, wumpus_position): + if wumpus_position.get_location() == self.get_location() and \ + wumpus_position.get_orientation()==self.get_orientation(): + return True + else: + return False + +# ______________________________________________________________________________ + + class HybridWumpusAgent(agents.Agent): """An agent for the wumpus world that does logical inference. [Figure 7.20]""" def __init__(self): - raise NotImplementedError + super().__init__() + self.dimrow = 3 + self.kb = WumpusKB(self.dimrow) + self.t = 0 + self.plan = list() + self.current_position = WumpusPosition(1, 1, 'UP') + + + def execute(self, percept): + self.kb.make_percept_sentence(percept, self.t) + self.kb.add_temporal_sentences(self.t) + + temp = list() + + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + if self.kb.ask_with_dpll('L' + i + 's' + j + 's' + self.t): + temp.append(i) + temp.append(j) + + if self.kb.ask_with_dpll('FacingNorth' + self.t): + self.current_position = WumpusPosition(temp[0], temp[1], 'UP') + elif self.kb.ask_with_dpll('FacingSouth' + self.t): + self.current_position = WumpusPosition(temp[0], temp[1], 'DOWN') + elif self.kb.ask_with_dpll('FacingWest' + self.t): + self.current_position = WumpusPosition(temp[0], temp[1], 'LEFT') + elif self.kb.ask_with_dpll('FacingEast' + self.t): + self.current_position = WumpusPosition(temp[0], temp[1], 'RIGHT') + + safe_points = list() + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + if self.kb.ask_with_dpll('OK' + i + 's' + j + 's' + self.t): + safe_points.append([i, j]) + + if self.kb.ask_with_dpll('Glitter' + self.t): + goals = list() + goals.append([1, 1]) + self.plan.append('Grab') + actions = plan_route(self.current_position,goals,safe_points) + for action in actions: + self.plan.append(action) + self.plan.append('Climb') + + if len(self.plan) == 0: + unvisited = list() + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + for k in range(1, self.dimrow+1): + if self.kb.ask_with_dpll("L" + i + "s" + j + "s" + k): + unvisited.append([i, j]) + unvisited_and_safe = list() + for u in unvisited: + for s in safe_points: + if u not in unvisited_and_safe and s == u: + unvisited_and_safe.append(u) + + temp = plan_route(self.current_position,unvisited_and_safe,safe_points) + for t in temp: + self.plan.append(t) + + if len(self.plan) == 0 and self.kb.ask_with_dpll('HaveArrow' + self.t): + possible_wumpus = list() + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + if not self.kb.ask_with_dpll('W' + i + 's' + j): + possible_wumpus.append([i, j]) + + temp = plan_shot(self.current_position, possible_wumpus, safe_points) + for t in temp: + self.plan.append(t) + + if len(self.plan) == 0: + not_unsafe = list() + for i in range(1, self.dimrow+1): + for j in range(1, self.dimrow+1): + if not self.kb.ask_with_dpll('OK' + i + 's' + j + 's' + self.t): + not_unsafe.append([i, j]) + temp = plan_route(self.current_position, not_unsafe, safe_points) + for t in temp: + self.plan.append(t) + + if len(self.plan) == 0: + start = list() + start.append([1, 1]) + temp = plan_route(self.current_position, start, safe_points) + for t in temp: + self.plan.append(t) + self.plan.append('Climb') + + + + action = self.plan[1:] + + self.kb.make_action_sentence(action, self.t) + self.t += 1 + + return action def plan_route(current, goals, allowed): raise NotImplementedError + +def plan_shot(current, goals, allowed): + raise NotImplementedError + + # ______________________________________________________________________________ @@ -901,10 +1206,11 @@ class FolKB(KB): False """ - def __init__(self, initial_clauses=[]): + def __init__(self, initial_clauses=None): self.clauses = [] # inefficient: no indexing - for clause in initial_clauses: - self.tell(clause) + if initial_clauses: + for clause in initial_clauses: + self.tell(clause) def tell(self, sentence): if is_definite_clause(sentence): diff --git a/neural_nets.ipynb b/neural_nets.ipynb index a6bb6f43b..9c5db9a56 100644 --- a/neural_nets.ipynb +++ b/neural_nets.ipynb @@ -82,7 +82,7 @@ "\n", "In both the Perceptron and the Neural Network, we are using the Backpropagation algorithm to train our weights. Basically it achieves that by propagating the errors from our last layer into our first layer, this is why it is called Backpropagation. In order to use Backpropagation, we need a cost function. This function is responsible for indicating how good our neural network is for a given example. One common cost function is the *Mean Squared Error* (MSE). This cost function has the following format:\n", "\n", - "$$MSE=\\frac{1}{2} \\sum_{i=1}^{n}(y - \\hat{y})^{2}$$\n", + "$$MSE=\\frac{1}{n} \\sum_{i=1}^{n}(y - \\hat{y})^{2}$$\n", "\n", "Where `n` is the number of training examples, $\\hat{y}$ is our prediction and $y$ is the correct prediction for the example.\n", "\n", @@ -221,14 +221,14 @@ "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.3" + "pygments_lexer": "ipython2", + "version": "2.7.14" } }, "nbformat": 4, diff --git a/nlp.py b/nlp.py index ace6de90d..6ad92b6bb 100644 --- a/nlp.py +++ b/nlp.py @@ -272,7 +272,7 @@ def __repr__(self): class Chart: """Class for parsing sentences using a chart data structure. - >>> chart = Chart(E0); + >>> chart = Chart(E0) >>> len(chart.parses('the stench is in 2 2')) 1 """ diff --git a/notebook.py b/notebook.py index ae0976900..795f1bdb1 100644 --- a/notebook.py +++ b/notebook.py @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt import numpy as np +from PIL import Image import os, struct import array @@ -912,17 +913,17 @@ def show_map(graph_data, node_colors = None): # set the size of the plot plt.figure(figsize=(18,13)) # draw the graph (both nodes and edges) with locations from romania_locations - nx.draw(G, pos = {k : node_positions[k] for k in G.nodes()}, - node_color = [node_colors[node] for node in G.nodes()], linewidths = 0.3, edgecolors = 'k') + nx.draw(G, pos={k: node_positions[k] for k in G.nodes()}, + node_color=[node_colors[node] for node in G.nodes()], linewidths=0.3, edgecolors='k') # draw labels for nodes - node_label_handles = nx.draw_networkx_labels(G, pos = node_label_pos, font_size = 14) + node_label_handles = nx.draw_networkx_labels(G, pos=node_label_pos, font_size=14) # add a white bounding box behind the node labels [label.set_bbox(dict(facecolor='white', edgecolor='none')) for label in node_label_handles.values()] # add edge lables to the graph - nx.draw_networkx_edge_labels(G, pos = node_positions, edge_labels = edge_weights, font_size = 14) + nx.draw_networkx_edge_labels(G, pos=node_positions, edge_labels=edge_weights, font_size=14) # add a legend white_circle = lines.Line2D([], [], color="white", marker='o', markersize=15, markerfacecolor="white") @@ -932,7 +933,7 @@ def show_map(graph_data, node_colors = None): green_circle = lines.Line2D([], [], color="green", marker='o', markersize=15, markerfacecolor="green") plt.legend((white_circle, orange_circle, red_circle, gray_circle, green_circle), ('Un-explored', 'Frontier', 'Currently Exploring', 'Explored', 'Final Solution'), - numpoints=1,prop={'size':16}, loc=(.8,.75)) + numpoints=1, prop={'size':16}, loc=(.8,.75)) # show the plot. No need to use in notebooks. nx.draw will show the graph itself. plt.show() @@ -940,7 +941,7 @@ def show_map(graph_data, node_colors = None): ## helper functions for visualisations def final_path_colors(initial_node_colors, problem, solution): - "returns a node_colors dict of the final path provided the problem and solution" + "Return a node_colors dict of the final path provided the problem and solution." # get initial node colors final_colors = dict(initial_node_colors) @@ -956,7 +957,7 @@ def display_visual(graph_data, user_input, algorithm=None, problem=None): def slider_callback(iteration): # don't show graph for the first time running the cell calling this function try: - show_map(graph_data, node_colors = all_node_colors[iteration]) + show_map(graph_data, node_colors=all_node_colors[iteration]) except: pass def visualize_callback(Visualize): @@ -976,26 +977,26 @@ def visualize_callback(Visualize): #time.sleep(.5) slider = widgets.IntSlider(min=0, max=1, step=1, value=0) - slider_visual = widgets.interactive(slider_callback, iteration = slider) + slider_visual = widgets.interactive(slider_callback, iteration=slider) display(slider_visual) - button = widgets.ToggleButton(value = False) - button_visual = widgets.interactive(visualize_callback, Visualize = button) + button = widgets.ToggleButton(value=False) + button_visual = widgets.interactive(visualize_callback, Visualize=button) display(button_visual) if user_input == True: node_colors = dict(initial_node_colors) if isinstance(algorithm, dict): - assert set(algorithm.keys()).issubset(set(["Breadth First Tree Search", + assert set(algorithm.keys()).issubset({"Breadth First Tree Search", "Depth First Tree Search", "Breadth First Search", "Depth First Graph Search", "Uniform Cost Search", - "A-star Search"])) + "A-star Search"}) - algo_dropdown = widgets.Dropdown(description = "Search algorithm: ", - options = sorted(list(algorithm.keys())), - value = "Breadth First Tree Search") + algo_dropdown = widgets.Dropdown(description="Search algorithm: ", + options=sorted(list(algorithm.keys())), + value="Breadth First Tree Search") display(algo_dropdown) elif algorithm is None: print("No algorithm to run.") @@ -1004,7 +1005,7 @@ def visualize_callback(Visualize): def slider_callback(iteration): # don't show graph for the first time running the cell calling this function try: - show_map(graph_data, node_colors = all_node_colors[iteration]) + show_map(graph_data, node_colors=all_node_colors[iteration]) except: pass @@ -1027,18 +1028,45 @@ def visualize_callback(Visualize): slider.value = i #time.sleep(.5) - start_dropdown = widgets.Dropdown(description = "Start city: ", - options = sorted(list(node_colors.keys())), value = "Arad") + start_dropdown = widgets.Dropdown(description="Start city: ", + options=sorted(list(node_colors.keys())), value="Arad") display(start_dropdown) - end_dropdown = widgets.Dropdown(description = "Goal city: ", - options = sorted(list(node_colors.keys())), value = "Fagaras") + end_dropdown = widgets.Dropdown(description="Goal city: ", + options=sorted(list(node_colors.keys())), value="Fagaras") display(end_dropdown) - button = widgets.ToggleButton(value = False) - button_visual = widgets.interactive(visualize_callback, Visualize = button) + button = widgets.ToggleButton(value=False) + button_visual = widgets.interactive(visualize_callback, Visualize=button) display(button_visual) slider = widgets.IntSlider(min=0, max=1, step=1, value=0) - slider_visual = widgets.interactive(slider_callback, iteration = slider) - display(slider_visual) \ No newline at end of file + slider_visual = widgets.interactive(slider_callback, iteration=slider) + display(slider_visual) + + +# Function to plot NQueensCSP in csp.py and NQueensProblem in search.py +def plot_NQueens(solution): + n = len(solution) + board = np.array([2 * int((i + j) % 2) for j in range(n) for i in range(n)]).reshape((n, n)) + im = Image.open('images/queen_s.png') + height = im.size[1] + im = np.array(im).astype(np.float) / 255 + fig = plt.figure(figsize=(7, 7)) + ax = fig.add_subplot(111) + ax.set_title('{} Queens'.format(n)) + plt.imshow(board, cmap='binary', interpolation='nearest') + # NQueensCSP gives a solution as a dictionary + if isinstance(solution, dict): + for (k, v) in solution.items(): + newax = fig.add_axes([0.064 + (k * 0.112), 0.062 + ((7 - v) * 0.112), 0.1, 0.1], zorder=1) + newax.imshow(im) + newax.axis('off') + # NQueensProblem gives a solution as a list + elif isinstance(solution, list): + for (k, v) in enumerate(solution): + newax = fig.add_axes([0.064 + (k * 0.112), 0.062 + ((7 - v) * 0.112), 0.1, 0.1], zorder=1) + newax.imshow(im) + newax.axis('off') + fig.tight_layout() + plt.show() diff --git a/planning.ipynb b/planning.ipynb index 1054f1ee8..ca648a3a0 100644 --- a/planning.ipynb +++ b/planning.ipynb @@ -23,9 +23,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from planning import *" @@ -51,9 +49,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "%psource Action" @@ -83,9 +79,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "%psource PDDL" @@ -110,9 +104,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from utils import *\n", @@ -141,9 +133,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "knowledge_base.extend([\n", @@ -163,9 +153,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -203,9 +191,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "#Sibiu to Bucharest\n", @@ -261,9 +247,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#Drive\n", @@ -284,9 +268,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def goal_test(kb):\n", @@ -303,31 +285,119 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "prob = PDDL(knowledge_base, [fly_s_b, fly_b_s, fly_s_c, fly_c_s, fly_b_c, fly_c_b, drive], goal_test)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Air Cargo Problem:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Air Cargo problem involves loading and unloading of cargo and flying it from place to place. The problem can be with defined with three actions: Load, Unload and Fly. Let us now define an object of `air_cargo` problem:" + ] + }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 15, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "airCargo = air_cargo()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, before taking any actions, we will check the `airCargo` if it has completed the goal it is required to do:" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "print(airCargo.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As we can see, it hasn't completed the goal. Now, we define the sequence of actions that it should take in order to achieve\n", + "the goal. Then the `airCargo` acts on each of them." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "solution = [expr(\"Load(C1 , P1, SFO)\"),\n", + " expr(\"Fly(P1, SFO, JFK)\"),\n", + " expr(\"Unload(C1, P1, JFK)\"),\n", + " expr(\"Load(C2, P2, JFK)\"),\n", + " expr(\"Fly(P2, JFK, SFO)\"),\n", + " expr(\"Unload (C2, P2, SFO)\")] \n", + "\n", + "for action in solution:\n", + " airCargo.act(action)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As the `airCargo` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal:" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "airCargo.goal_test()" + ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "It has now achieved its goal." + ] } ], "metadata": { @@ -346,9 +416,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/planning.py b/planning.py index e31c8b3a3..95d7655d1 100644 --- a/planning.py +++ b/planning.py @@ -276,8 +276,8 @@ def find_mutex(self): if negeff in self.next_state_links_neg: for a in self.next_state_links_pos[poseff]: for b in self.next_state_links_neg[negeff]: - if set([a, b]) not in self.mutex: - self.mutex.append(set([a, b])) + if {a, b} not in self.mutex: + self.mutex.append({a, b}) # Interference for posprecond in self.current_state_links_pos: @@ -285,16 +285,16 @@ def find_mutex(self): if negeff in self.next_state_links_neg: for a in self.current_state_links_pos[posprecond]: for b in self.next_state_links_neg[negeff]: - if set([a, b]) not in self.mutex: - self.mutex.append(set([a, b])) + if {a, b} not in self.mutex: + self.mutex.append({a, b}) for negprecond in self.current_state_links_neg: poseff = negprecond if poseff in self.next_state_links_pos: for a in self.next_state_links_pos[poseff]: for b in self.current_state_links_neg[negprecond]: - if set([a, b]) not in self.mutex: - self.mutex.append(set([a, b])) + if {a, b} not in self.mutex: + self.mutex.append({a, b}) # Competing needs for posprecond in self.current_state_links_pos: @@ -302,8 +302,8 @@ def find_mutex(self): if negprecond in self.current_state_links_neg: for a in self.current_state_links_pos[posprecond]: for b in self.current_state_links_neg[negprecond]: - if set([a, b]) not in self.mutex: - self.mutex.append(set([a, b])) + if {a, b} not in self.mutex: + self.mutex.append({a, b}) # Inconsistent support state_mutex = [] @@ -314,7 +314,7 @@ def find_mutex(self): else: next_state_1 = self.next_action_links[list(pair)[0]] if (len(next_state_0) == 1) and (len(next_state_1) == 1): - state_mutex.append(set([next_state_0[0], next_state_1[0]])) + state_mutex.append({next_state_0[0], next_state_1[0]}) self.mutex = self.mutex+state_mutex @@ -565,18 +565,20 @@ class HLA(Action): """ unique_group = 1 - def __init__(self, action, precond=[None, None], effect=[None, None], duration=0, - consume={}, use={}): + def __init__(self, action, precond=None, effect=None, duration=0, + consume=None, use=None): """ As opposed to actions, to define HLA, we have added constraints. duration holds the amount of time required to execute the task consumes holds a dictionary representing the resources the task consumes uses holds a dictionary representing the resources the task uses """ + precond = precond or [None, None] + effect = effect or [None, None] super().__init__(action, precond, effect) self.duration = duration - self.consumes = consume - self.uses = use + self.consumes = consume or {} + self.uses = use or {} self.completed = False # self.priority = -1 # must be assigned in relation to other HLAs # self.job_group = -1 # must be assigned in relation to other HLAs @@ -644,10 +646,10 @@ class Problem(PDDL): This class is identical to PDLL, except that it overloads the act function to handle resource and ordering conditions imposed by HLA as opposed to Action. """ - def __init__(self, initial_state, actions, goal_test, jobs=None, resources={}): + def __init__(self, initial_state, actions, goal_test, jobs=None, resources=None): super().__init__(initial_state, actions, goal_test) self.jobs = jobs - self.resources = resources + self.resources = resources or {} def act(self, action): """ diff --git a/probability.ipynb b/probability.ipynb index 2fd1c9dae..365039874 100644 --- a/probability.ipynb +++ b/probability.ipynb @@ -11,21 +11,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from probability import *\n", - "from notebook import psource" + "from notebook import *" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "## Probability Distribution\n", "\n", @@ -34,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": { "collapsed": true }, @@ -45,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -54,7 +52,7 @@ "0.75" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -255,9 +253,7 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "_A probability model is completely determined by the joint distribution for all of the random variables._ (**Section 13.3**) The probability module implements these as the class **JointProbDist** which inherits from the **ProbDist** class. This class specifies a discrete probability distribute over a set of variables. " ] @@ -512,9 +508,124 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "

\n", + "\n", + "
def enumerate_joint_ask(X, e, P):\n",
+       "    """Return a probability distribution over the values of the variable X,\n",
+       "    given the {var:val} observations e, in the JointProbDist P. [Section 13.3]\n",
+       "    >>> P = JointProbDist(['X', 'Y'])\n",
+       "    >>> P[0,0] = 0.25; P[0,1] = 0.5; P[1,1] = P[2,1] = 0.125\n",
+       "    >>> enumerate_joint_ask('X', dict(Y=1), P).show_approx()\n",
+       "    '0: 0.667, 1: 0.167, 2: 0.167'\n",
+       "    """\n",
+       "    assert X not in e, "Query variable must be distinct from evidence"\n",
+       "    Q = ProbDist(X)  # probability distribution for X, initially empty\n",
+       "    Y = [v for v in P.variables if v != X and v not in e]  # hidden variables.\n",
+       "    for xi in P.values(X):\n",
+       "        Q[xi] = enumerate_joint(Y, extend(e, X, xi), P)\n",
+       "    return Q.normalize()\n",
+       "
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "psource(enumerate_joint_ask)" ] @@ -792,7 +903,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -1178,7 +1289,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": { "collapsed": true }, @@ -1418,21 +1529,8 @@ ] }, { - "cell_type": "code", - "execution_count": 45, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'False: 0.184, True: 0.816'" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "likelihood_weighting('Cloudy', dict(Rain=True), sprinkler, 200).show_approx()" ] @@ -1450,7 +1548,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "collapsed": true }, @@ -1485,6 +1583,245 @@ "source": [ "gibbs_ask('Cloudy', dict(Rain=True), sprinkler, 200).show_approx()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Inference in Temporal Models" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Before we start, it will be helpful to understand the structure of a temporal model. We will use the example of the book with the guard and the umbrella. In this example, the state $\\textbf{X}$ is whether it is a rainy day (`X = True`) or not (`X = False`) at Day $\\textbf{t}$. In the sensor or observation model, the observation or evidence $\\textbf{U}$ is whether the professor holds an umbrella (`U = True`) or not (`U = False`) on **Day** $\\textbf{t}$. Based on that, the transition model is \n", + "\n", + "| $X_{t-1}$ | $X_{t}$ | **P**$(X_{t}| X_{t-1})$| \n", + "| ------------- |------------- | ----------------------------------|\n", + "| ***${False}$*** | ***${False}$*** | 0.7 |\n", + "| ***${False}$*** | ***${True}$*** | 0.3 |\n", + "| ***${True}$*** | ***${False}$*** | 0.3 |\n", + "| ***${True}$*** | ***${True}$*** | 0.7 |\n", + "\n", + "And the the sensor model will be,\n", + "\n", + "| $X_{t}$ | $U_{t}$ | **P**$(U_{t}|X_{t})$| \n", + "| :-------------: |:-------------: | :------------------------:|\n", + "| ***${False}$*** | ***${True}$*** | 0.2 |\n", + "| ***${False}$*** | ***${False}$*** | 0.8 |\n", + "| ***${True}$*** | ***${True}$*** | 0.9 |\n", + "| ***${True}$*** | ***${False}$*** | 0.1 |\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the filtering task we are given evidence **U** in each time **t** and we want to compute the belief $B_{t}(x)= P(X_{t}|U_{1:t})$. \n", + "We can think of it as a three step process:\n", + "1. In every step we start with the current belief $P(X_{t}|e_{1:t})$\n", + "2. We update it for time\n", + "3. We update it for evidence\n", + "\n", + "The forward algorithm performs the step 2 and 3 at once. It updates, or better say reweights, the initial belief using the transition and the sensor model. Let's see the umbrella example. On **Day 0** no observation is available, and for that reason we will assume that we have equal possibilities to rain or not. In the **`HiddenMarkovModel`** class, the prior probabilities for **Day 0** are by default [0.5, 0.5]. " + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "%psource HiddenMarkovModel" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We instantiate the object **`hmm`** of the class using a list of lists for both the transition and the sensor model." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "umbrella_transition_model = [[0.7, 0.3], [0.3, 0.7]]\n", + "umbrella_sensor_model = [[0.9, 0.2], [0.1, 0.8]]\n", + "hmm = HiddenMarkovModel(umbrella_transition_model, umbrella_sensor_model)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The **`sensor_dist()`** method returns a list with the conditional probabilities of the sensor model." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.9, 0.2]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hmm.sensor_dist(ev=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The observation update is calculated with the **`forward()`** function. Basically, we update our belief using the observation model. The function returns a list with the probabilities of **raining or not** on **Day 1**." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "psource(forward)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability of raining on day 1 is 0.82\n" + ] + } + ], + "source": [ + "belief_day_1 = forward(hmm, umbrella_prior, ev=True)\n", + "print ('The probability of raining on day 1 is {:.2f}'.format(belief_day_1[0]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In **Day 2** our initial belief is the updated belief of **Day 1**. Again using the **`forward()`** function we can compute the probability of raining in **Day 2**" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability of raining in day 2 is 0.88\n" + ] + } + ], + "source": [ + "belief_day_2 = forward(hmm, belief_day_1, ev=True)\n", + "print ('The probability of raining in day 2 is {:.2f}'.format(belief_day_2[0]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the smoothing part we are interested in computing the distribution over past states given evidence up to the present. Assume that we want to compute the distribution for the time **k**, for $0\\leq k