diff --git a/README.md b/README.md index dd8c0b38a..99b19c773 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,15 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | **Figure** | **Name (in 3rd edition)** | **Name (in repository)** | **File** | **Tests** | **Notebook** |:-------|:----------------------------------|:------------------------------|:--------------------------------|:-----|:---------| -| 2 | Random-Vacuum-Agent | `RandomVacuumAgent` | [`agents.py`][agents] | Done | | -| 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | | +| 2 | Random-Vacuum-Agent | `RandomVacuumAgent` | [`agents.py`][agents] | Done | Included | +| 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included | | 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included | -| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | | | -| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | | -| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | | -| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | | -| 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | | +| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | | Included | +| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | Included | +| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included | +| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included | +| 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included | | 3 | Problem | `Problem` | [`search.py`][search] | Done | | | 3 | Node | `Node` | [`search.py`][search] | Done | | | 3 | Queue | `Queue` | [`utils.py`][utils] | Done | | diff --git a/images/model_based_reflex_agent.jpg b/images/model_based_reflex_agent.jpg new file mode 100644 index 000000000..b6c12ed09 Binary files /dev/null and b/images/model_based_reflex_agent.jpg differ diff --git a/images/model_goal_based_agent.jpg b/images/model_goal_based_agent.jpg new file mode 100644 index 000000000..93d6182b4 Binary files /dev/null and b/images/model_goal_based_agent.jpg differ diff --git a/images/model_utility_based_agent.jpg b/images/model_utility_based_agent.jpg new file mode 100644 index 000000000..693230c00 Binary files /dev/null and b/images/model_utility_based_agent.jpg differ diff --git a/images/simple_reflex_agent.jpg b/images/simple_reflex_agent.jpg new file mode 100644 index 000000000..74002a720 Binary files /dev/null and b/images/simple_reflex_agent.jpg differ diff --git a/vacuum_world.ipynb b/vacuum_world.ipynb new file mode 100644 index 000000000..92f5b90d9 --- /dev/null +++ b/vacuum_world.ipynb @@ -0,0 +1,563 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# The Vacuum World \n", + "\n", + "In this notebook, we will be discussing about **the structure of agents** through an example of the **vacuum agent**. The job of AI is to design an **agent program** that implements the agent function: the mapping from percepts to actions. We assume this program will run on some sort of computing device with physical sensors and actuators: we call this the **architecture**: \n", + "\n", + " agent = architecture + program " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Before moving on, please review [agents.ipynb](https://github.com/aimacode/aima-python/blob/master/agents.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Agent Programs\n", + "\n", + "An agent program takes the current percept as input from the sensors and return an action to the actuators. There is a difference between an agent program and an agent function: an agent program takes the current percept as input whereas an agent function takes the entire percept history. \n", + "The agent program takes just the current percept as input because nothing more is available from the environment; if the agent's actions need to depend on the entire percept sequence, the agent will have to remember the percept. \n", + "\n", + "We'll discuss the following agent programs here with the help of the vacuum world example:\n", + "\n", + "* Random Agent Program\n", + "* Table Driven Agent Program\n", + "* Simple Reflex Agent Program\n", + "* Model-Based Reflex Agent Program\n", + "* Goal-Based Agent Program\n", + "* Utility-Based Agent Program" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Random Agent Program\n", + "\n", + "A random agent program, as the name suggests, choses an action at random, without taking into account the percepts. \n", + "Here, we will demonstrate a random vacuum agent for a trivial vacuum environment, that is, the two-state environment." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's begin by importing all the functions from the agents module:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: '/home/apurv/aima-python/aima-data/orings.csv'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0magents\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mnotebook\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpsource\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/aima-python/notebook.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgames\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mTicTacToe\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0malphabeta_player\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrandom_player\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mFig52Extended\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfinity\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlogic\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mparse_definite_clause\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstandardize_variables\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0munify\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msubst\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlearning\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mDataSet\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mIPython\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisplay\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mHTML\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mcollections\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefaultdict\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/aima-python/learning.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m orings = DataSet(name='orings', target='Distressed',\n\u001b[0;32m-> 1107\u001b[0;31m attrnames=\"Rings Distressed Temp Pressure Flightnum\")\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/aima-python/learning.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, examples, attrs, attrnames, target, inputs, values, distance, name, source, exclude)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexamples\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparse_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexamples\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mexamples\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 98\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexamples\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparse_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopen_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'.csv'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 99\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexamples\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexamples\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/aima-python/utils.py\u001b[0m in \u001b[0;36mopen_data\u001b[0;34m(name, mode)\u001b[0m\n\u001b[1;32m 414\u001b[0m \u001b[0maima_file\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maima_root\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'aima-data'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 415\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 416\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maima_file\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 417\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 418\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/home/apurv/aima-python/aima-data/orings.csv'" + ] + } + ], + "source": [ + "from agents import *\n", + "from notebook import psource" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us first see how we define the TrivialVacuumEnvironment. Run the next cell to see how abstract class TrivialVacuumEnvironment is defined in agents module:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "%psource TrivialVacuumEnvironment" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "State of the Environment: {(1, 0): 'Clean', (0, 0): 'Dirty'}.\n" + ] + } + ], + "source": [ + "# These are the two locations for the two-state environment.\n", + "loc_A, loc_B = (0, 0), (1, 0)\n", + "\n", + "# Initialise the two-state environment.\n", + "trivial_vacuum_env = TrivialVacuumEnvironment()\n", + "\n", + "# Check the intial state of the environment.\n", + "print(\"State of the Environment: {}.\".format(trivial_vacuum_env.status))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's create our agent now. This agent will chose any of the actions from 'Right', 'Left', 'Suck' and 'NoOp' (No Operation) randomly. " + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create the random agent.\n", + "random_agent = Agent(program=RandomAgentProgram(['Right', 'Left', 'Suck', 'NoOp']))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will now add our agent to the environment." + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "RandomVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# Add agent to the environment.\n", + "trivial_vacuum_env.add_thing(random_agent)\n", + "\n", + "print(\"RandomVacuumAgent is located at {}.\".format(random_agent.location))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's run our environment now." + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "State of the Environment: {(1, 0): 'Clean', (0, 0): 'Dirty'}.\n", + "RandomVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# Running the environment.\n", + "trivial_vacuum_env.step()\n", + "\n", + "# Check the current state of the environment.\n", + "print(\"State of the Environment: {}.\".format(trivial_vacuum_env.status))\n", + "\n", + "print(\"RandomVacuumAgent is located at {}.\".format(random_agent.location))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Table Driven Agent Program\n", + "\n", + "A table driven agent program keeps track of the percept sequence and then uses it to index into a table of actions to decide what to do. The table represents eplicitly the agent function that the agent program embodies. \n", + "In the two-state vacuum world, the table would consist of all the possible states of the agent." + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "table = {((loc_A, 'Clean'),): 'Right',\n", + " ((loc_A, 'Dirty'),): 'Suck',\n", + " ((loc_B, 'Clean'),): 'Left',\n", + " ((loc_B, 'Dirty'),): 'Suck',\n", + " ((loc_A, 'Clean'), (loc_A, 'Clean')): 'Right',\n", + " ((loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck',\n", + " ((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Clean')): 'Right',\n", + " ((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck',\n", + " }" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will now create a table driven agent program for our two-state environment." + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a table driven agent.\n", + "table_driven_agent = Agent(program=TableDrivenAgentProgram(table=table))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since we are using the same environment, let us remove the previously added random agent from the environment to avoid confusion." + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "trivial_vacuum_env.delete_thing(random_agent)" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "TableDrivenVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# Add the table driven agent to the environment\n", + "trivial_vacuum_env.add_thing(table_driven_agent)\n", + "\n", + "print(\"TableDrivenVacuumAgent is located at {}.\".format(table_driven_agent.location))" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "State of the Environment: {(1, 0): 'Clean', (0, 0): 'Clean'}.\n", + "TableDrivenVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# Run the environment.\n", + "trivial_vacuum_env.step()\n", + "\n", + "# Check the current state of the environment.\n", + "print(\"State of the Environment: {}.\".format(trivial_vacuum_env.status))\n", + "\n", + "print(\"TableDrivenVacuumAgent is located at {}.\".format(table_driven_agent.location))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simple Reflex Agent Program\n", + "\n", + "A simple reflex agent program selects actions on the basis of the current percept, ignoring the rest of the percept history. These agents work on a **condition-action rule** (also called **situation-action rule**, **production** or **if-then rule**), which tell the agent the action to trigger when a particular situtation is encountered. \n", + "\n", + "The schematic diagram shown in **Figure 2.9** of the book will make this more clear:\n", + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us now create a simple reflex agent for the environment." + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Delete the previously added table driven agent.\n", + "trivial_vacuum_env.delete_thing(table_driven_agent)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To create our agent, we need two functions: INTERPRET-INPUT function, which generates an abstracted description of the current state from the percerpt and the RULE-MATCH function, which returns the first rule in the set of rules that matches the given state description." + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# TODO: Implement these functions for two-dimensional environment.\n", + "# Interpret-input function for the two-state environment.\n", + "def interpret_input(percept):\n", + " pass\n", + "\n", + "rules = None\n", + "\n", + "# Rule-match function for the two-state environment.\n", + "def rule_match(state, rule):\n", + " for rule in rules:\n", + " if rule.matches(state):\n", + " return rule \n", + " \n", + "# Create a simple reflex agent the two-state environment.\n", + "simple_reflex_agent = ReflexVacuumAgent()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now add the agent to the environment:" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "SimpleReflexVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "trivial_vacuum_env.add_thing(simple_reflex_agent)\n", + "\n", + "print(\"SimpleReflexVacuumAgent is located at {}.\".format(simple_reflex_agent.location))" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "State of the Environment: {(1, 0): 'Clean', (0, 0): 'Clean'}.\n", + "SimpleReflexVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# Run the environment.\n", + "trivial_vacuum_env.step()\n", + "\n", + "# Check the current state of the environment.\n", + "print(\"State of the Environment: {}.\".format(trivial_vacuum_env.status))\n", + "\n", + "print(\"SimpleReflexVacuumAgent is located at {}.\".format(simple_reflex_agent.location))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Model-Based Reflex Agent Program\n", + "\n", + "A model-based reflex agent maintains some sort of internal state that depends on the percept history and thereby reflects at least some of the unobserved aspects of the current state. In additon to this, it also requires a model of the world, that is, knowledge about \"how the world works\". \n", + "\n", + "The schematic diagram shown in figure 2.11 of the book will make this more clear:\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will now create a model-based reflex agent for the environment:" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list.remove(x): x not in list\n", + " in Environment delete_thing\n", + " Thing to be removed: at (0, 0)\n", + " from list: []\n" + ] + } + ], + "source": [ + "# Delete the previously added simple reflex agent.\n", + "trivial_vacuum_env.delete_thing(simple_reflex_agent)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We need a another function UPDATE-STATE which will be reponsible for creating a new state description." + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ModelBasedVacuumAgent is located at (0, 0).\n" + ] + } + ], + "source": [ + "# TODO: Implement this function for the two-dimensional environment.\n", + "def update_state(state, action, percept, model):\n", + " pass\n", + "\n", + "# Create a model-based reflex agent.\n", + "model_based_reflex_agent = ModelBasedVacuumAgent()\n", + "\n", + "# Add the agent to the environment.\n", + "trivial_vacuum_env.add_thing(model_based_reflex_agent)\n", + "\n", + "print(\"ModelBasedVacuumAgent is located at {}.\".format(model_based_reflex_agent.location))" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "State of the Environment: {(1, 0): 'Clean', (0, 0): 'Clean'}.\n", + "ModelBasedVacuumAgent is located at (1, 0).\n" + ] + } + ], + "source": [ + "# Run the environment.\n", + "trivial_vacuum_env.step()\n", + "\n", + "# Check the current state of the environment.\n", + "print(\"State of the Environment: {}.\".format(trivial_vacuum_env.status))\n", + "\n", + "print(\"ModelBasedVacuumAgent is located at {}.\".format(model_based_reflex_agent.location))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Goal-Based Agent Program \n", + "\n", + "A goal-based agent needs some sort of goal information that describes situations that are desirable, apart from the current state description. \n", + "Figure 2.13 of the book shows a model-based, goal-based agent: \n", + "\n", + "\n", + "Search (Chapters 3 to 5) and Planning (Chapters 10 to 11) are the subfields of AI devoted to finding action sequences that achieve the agent's goals.\n", + "\n", + "## Utility-Based Agent Program\n", + "\n", + "A utility-based agent maximizes its utility using the agent's utility function, which is essentially an internalization of the agent's performance measure. \n", + "Figure 2.14 of the book shows a model-based, utility-based agent:\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy