{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "brNDGX-kvzds"
      },
      "source": [
        "# Template for Notes for CIS 521 Midterm 1\n",
        "\n",
        "The midterm exam for CIS 521 will be **open notes**. No other matierals are allowed for the exam - you may not use the textbook, the internet, a Python envionement, or communicate with anyone during the exam. \n",
        "\n",
        "This python notebook is where you should save all of your notes.  It provides a structured template that allows you to add summaries for each of the textbook sections that are part of the required reading, plus room for lecture notes and definitions.\n",
        "\n",
        "Your summaries must be written in your own words.  Do not copy and paste from the textbook.  Do not share your notes with classmates, or copy any of your classmates' notes.  "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aPtM8g7R0Pds"
      },
      "source": [
        "# Instructions\n",
        "\n",
        "1. Make a copy of this Google Colab file. From the colab menu, pick **File > Save a copy in Drive**.  That will save a copy of this notebook in your Google drive.\n",
        "2. Go through each section of the notebook, and fill in all the summaries for each chapter and its corresponding sections.  Be sure to save your work frequently!\n",
        "3. Read the notes below about how you can format your summaries.\n",
        "4. In addition to these notes, you are allowed 1 page (both sides) for figures or handwritten notes.\n",
        "5. Submit your version of this notebook to Gradescope before you start the exam.\n",
        "6. If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print: \n",
        "* Run the last cell of this notebook\n",
        "* Click the \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n",
        "\n",
        "## Formatting Notes\n",
        "\n",
        "1. The max length for each section's summary is 500 words / 3000 characters.\n",
        "2. You can also write a 2000 word summary of the lectures for each module.\n",
        "3. You may also write definitions of concepts for each module.  The definitions should be written in your own words (not copy and pasted), and they should be no more than 20 words long for each concept. \n",
        "2. You can use Markdown formatting for your summaries. \n",
        "3. You can use Latex formatting for equations. Put two dollar signs before and after your equation like this: \n",
        "$$ \\epsilon = \\frac{1}{mc^2} $$\n",
        "4. When you write python code or psuedocode algorithms, you should surround it with triple backticks like this:\n",
        "```\n",
        "def function():\n",
        "      print('hello world')\n",
        "```\n",
        "5. Write \\ whenever you want to keep writing on the next line without a newline being inserted."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cw5IpDLCZa4W"
      },
      "source": [
        "## Example summary\n",
        "\n",
        "This is a sample summary of [Section 2.1.1](https://web.stanford.edu/~jurafsky/slp3/2.pdf ) of Jurfasky and Martin's Speech and Language Processing's book\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lzaavW96tcxM",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "bbd5629f-da18-48a4-b00d-9e2827d3eddf"
      },
      "source": [
        "chapter_2_1_example = \"\"\"\n",
        "Regular expressions are an algebraic notation for characterizing \\\n",
        "a set of strings that are useful for searching for a pattern or through a corpus.\\\n",
        "Only the first matching result will be shown. The search string is case sensitive, \\\n",
        "but it can consist of a single character or a sequence of characters. \\\n",
        "While square braces specify a disjunction of characters, the dash can more easily look \\\n",
        "for characters over a range. The caret specifies the non-existence of a character. \\\n",
        "Additionally, the (?) is used to for flexibility on a single character, meaning \\\n",
        "\"the preceding character or nothing\". More importantly, the Kleene star means zero or \\\n",
        "more occurrences of the immediately previous character or regular expression in square braces.\\\n",
        "...\n",
        "\"\"\"\n",
        "\n",
        "length = len(chapter_2_1_example.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(500-length)))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 116 words long, so you could write an additional 384 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "s3Uk9gQTevcj"
      },
      "source": [
        "## Example summary length\n",
        "\n",
        "The maximum summary length for each section is 500 words / 3000 characters.  Hopefully you'll find that to be quite generous. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8DvZ57A-djo1",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "9d80ba85-7a58-46ea-bb22-fd290d50c90e"
      },
      "source": [
        "# This is an example of a 500 word placeholder\n",
        "placeholder = \"\"\"ultrices vitae auctor eu augue ut lectus arcu bibendum at varius \\\n",
        " vel pharetra vel turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet \\\n",
        " bibendum enim facilisis gravida neque convallis a cras semper auctor neque vitae \\\n",
        " tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh \\\n",
        " venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut \\\n",
        " faucibus pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper \\ \n",
        " quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu \\\n",
        " scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque \\ \n",
        " laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt eget \\\n",
        " nullam non nisi est sit amet facilisis magna etiam tempor orci eu lobortis \\\n",
        " elementum nibh tellus molestie nunc non blandit massa enim nec dui nunc mattis \\\n",
        " enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor \\\n",
        " massa id neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus \\\n",
        " imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque \\\n",
        " penatibus et magnis dis parturient montes nascetur ridiculus mus mauris vitae \\\n",
        " ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan \\\n",
        " lacus vel facilisis volutpat est velit egestas dui id ornare arcu odio ut sem nulla \\\n",
        " pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer \\\n",
        " quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa \\\n",
        " tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc \\\n",
        " consequat interdum varius sit amet mattis vulputate enim nulla aliquet porttitor \\\n",
        " lacus luctus accumsan tortor posuere ac ut consequat semper viverra nam libero \\\n",
        " justo laoreet sit amet cursus sit amet dictum sit amet justo donec enim diam \\\n",
        " vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris \\\n",
        " pharetra et ultrices neque ornare aenean euismod elementum nisi quis eleifend quam \\\n",
        " adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque viverra justo \\\n",
        " nec ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis in \\\n",
        " eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod \\\n",
        " quis viverra nibh cras pulvinar mattis nunc sed blandit libero volutpat sed cras \\\n",
        " ornare arcu dui vivamus arcu felis bibendum ut tristique et egestas quis ipsum \\\n",
        " suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque \\\n",
        " dignissim enim sit amet venenatis urna cursus eget nunc scelerisque viverra mauris \\\n",
        " in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in \\\n",
        " pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet \\\n",
        " risus feugiat in ante metus dictum at tempor commodo ullamcorper a lacus vestibulum \\\n",
        " sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit \\\n",
        " volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in \\\n",
        " dictum non consectetur a erat nam at lectus urna\"\"\"\n",
        "\n",
        "print(\"The length in words is\", len(placeholder.split(' ')))\n",
        "print(\"The length in characters is\", len(placeholder))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = False"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GZZXyrV-xuAp"
      },
      "source": [
        "# Module 1 - Intro to AI"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y2NfE1CKxzS-"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
        "\n",
        "chapter1_1 = \"\"\" Chapter 1.1 summary. \"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter27_2 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\"\\\n",
        "**Agents**\n",
        "- *Perceive* its environment through sensors\n",
        "- *Acting* upon that environment through actuators\n",
        "- Ex: Human agent(sensors are eyes, ears ; actuators are hands, legs)\n",
        "- Ex: thermostats, robots\n",
        "\n",
        "**Rational agent**\n",
        "- Agent that perceives its environment and behaves rationally\n",
        "- It is not guaranteed to find optimal solutions\n",
        "- It selects an action that maximizes the expected value of its performance measure\n",
        "- Define *performance measure* with the evidence provided by the percept sequence\n",
        "- We need to specify a *task environment*\n",
        "  - PEAS(performance measure, environment, actuators, sensors)\n",
        "\n",
        "- An agent’s choice of action at a given instant does not depend both on its percept sequence and future perceptual inputs\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 1.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module1_definitions = {\n",
        "\"agent\" : \"anything that can perceive through sensors and act in an environment through actuators\",\n",
        "\"percept\" : \"agent's perceptual inputs\",\n",
        "\"reflex agent\" : \"action based on the current percept and ignore the percept history.\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "elCCgY64spuq"
      },
      "source": [
        "## Preview of your notes for Module 1\n",
        "\n",
        "Here's a preview of your how your notes will be displayed.  At the end of this Python notebook, we'll aggregate your notes for all modules together into a single display.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gYYeNcdM_maE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 966
        },
        "cellView": "form",
        "outputId": "cc138d2b-c904-4853-f0bb-4ad118104742"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "from IPython.display import display, Markdown, Latex\n",
        "\n",
        "module1_sections = [\n",
        "  (\"AIMA Chapter 1.1 What is AI?\", chapter1_1),\n",
        "  (\"AIMA Chapter 27.1 The Limits of AI\", chapter27_1),\n",
        "  (\"AIMA Chapter 27.1 Can Machines Really Think?\", chapter27_2),\n",
        "  (\"AIMA 2.1 Agents and Environments\", chapter2_1),\n",
        "  (\"AIMA 2.2 Good Behavior: The Concept of Rationality\", chapter2_2),\n",
        "  (\"AIMA 2.3 The Nature of Environments\", chapter2_3),\n",
        "  (\"AIMA 2.4 The Structure of Agents\", chapter2_4),\n",
        "  (\"Module 1 Lecture Notes\", module1_lecture_notes),\n",
        "]\n",
        "\n",
        "\n",
        "def length_check(sections):\n",
        "  warnings = \"\"\n",
        "  for section, summary in sections:\n",
        "    max_word_length = 500\n",
        "    max_character_length = 3000\n",
        "    if \"lecture\" in section.lower():\n",
        "      # It's OK to do longer summaries of the lectures\n",
        "      max_word_length = 2000\n",
        "      max_character_length = 12000  \n",
        "    if (len(summary) > max_character_length or len(summary.split(' ')) > max_word_length):\n",
        "      warnings += \"WARNING: Your summary of '{section}' is too long!\\n\".format(section=section)\n",
        "  return warnings\n",
        "\n",
        "def length_check_definitions(definitions):\n",
        "  warnings = \"\"\n",
        "  for concept, definition in definitions.items():\n",
        "    if(len(definition.split(' ')) > 20):\n",
        "      warnings += \"WARNING: Your definition of '{concept}' is too long!\\n\".format(concept=concept)\n",
        "  return warnings\n",
        "\n",
        "\n",
        "def format_module(module_num, title, sections, definitions, show_placeholder=False):\n",
        "  markdown = \"\"\n",
        "\n",
        "  # Check summary lengths\n",
        "  warnings = length_check(sections)\n",
        "  if warnings != \"\":\n",
        "    markdown += \"## \" + warnings\n",
        "\n",
        "  # Check definition lengths\n",
        "  warnings = length_check_definitions(definitions)\n",
        "  if warnings != \"\":\n",
        "    markdown += \"## \" + warnings\n",
        "\n",
        "  markdown += \"# Module {num}: {title}\\n\".format(num=module_num, title=title)\n",
        "\n",
        "\n",
        "  for section, summary in sections:\n",
        "    if show_placeholder and summary == \" Your summary here \":\n",
        "      summary = placeholder\n",
        "    markdown += \"## {section}\\n{summary}\\n\\n\".format(section=section, summary=summary)\n",
        "  \n",
        "  markdown += \"## Module {num} Definitions\\n\".format(num=module_num)\n",
        "  for concept, definition in definitions.items():\n",
        "    markdown += \"* **{concept}** - {definition}\\n\".format(concept=concept.capitalize(), definition=definition)\n",
        "  return markdown\n",
        "\n",
        "\n",
        "module1_markdown = format_module(1, \"Rational Agents and Task Environments\", module1_sections, module1_definitions)\n",
        "display(Markdown(module1_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n**Agents**\n- *Perceive* its environment through sensors\n- *Acting* upon that environment through actuators\n- Ex: Human agent(sensors are eyes, ears ; actuators are hands, legs)\n- Ex: thermostats, robots\n\n**Rational agent**\n- Agent that perceives its environment and behaves rationally\n- It is not guaranteed to find optimal solutions\n- It selects an action that maximizes the expected value of its performance measure\n- Define *performance measure* with the evidence provided by the percept sequence\n- We need to specify a *task environment*\n  - PEAS(performance measure, environment, actuators, sensors)\n\n- An agent’s choice of action at a given instant does not depend both on its percept sequence and future perceptual inputs\n\n\n## Module 1 Definitions\n* **Agent** - anything that can perceive through sensors and act in an environment through actuators\n* **Percept** - agent's perceptual inputs\n* **Reflex agent** - action based on the current percept and ignore the percept history.\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9xRbdqDox2zD"
      },
      "source": [
        "#Module 2 - Python"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DpBvu7EMx7sy"
      },
      "source": [
        "# No readings for this module.  Instead you can summarize the lecture instead.\n",
        "\n",
        "# Lecture notes \n",
        "module2_lecture_notes = \"\"\"\n",
        "- **Tuple**\n",
        "  - *immutable* ordered sequence of items\n",
        "- **Strings**\n",
        "  - *immutable*\n",
        "- **List**\n",
        "  - *Mutable*\n",
        "- **Dictionaries**\n",
        "  - keys are immutable\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"immutable\" : \"cannot be modified once created\"\n",
        "}"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 370
        },
        "outputId": "7c046f47-91f2-4004-8010-37f3e44b2e70"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "\n",
        "module2_sections = [\n",
        "  (\"Module 2 Lecture Notes\", module2_lecture_notes),\n",
        "]\n",
        "\n",
        "module2_markdown = format_module(2, \"Python\", module2_sections, module2_definitions)\n",
        "display(Markdown(module2_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n\n- **Tuple**\n  - *immutable* ordered sequence of items\n- **Strings**\n  - *immutable*\n- **List**\n  - *Mutable*\n- **Dictionaries**\n  - keys are immutable\n\n## Module 2 Definitions\n* **Immutable** - cannot be modified once created\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "46MQLR-Gx8dZ"
      },
      "source": [
        "#Module 3 - Search Problems"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BN0b1eVYx-nd"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
        "chapter3_1 = \"\"\" \\\n",
        "- Four phases of problem-solving process with known environment:\n",
        "  1) Goal-formation\n",
        "  2) Problem-formation(formulate a description of the states and actions needed to reach goal)\n",
        "  3) Search(simulate actions until you find a solution)\n",
        "  4) Execution\n",
        "\n",
        "- Known environment's solution is always a fixed sequence of actions.\n",
        "- A **search problem** consists of \n",
        "  1) state-space \n",
        "  2) initial-state \n",
        "  3) goal-states \n",
        "  4) actions \n",
        "  5) transition-model \n",
        "  6) action-cost-function\n",
        "\n",
        "- Total cost of a path is the sum of individual costs. \n",
        "- Optimal solution has the lowest total cost. \n",
        "- State space can be represented in graphs. \n",
        "- **Abstraction** is valid if we can elaborate abstract solution into a more detailed world. \n",
        "- **Abstraction** is useful if carrying actions is easier than the original problem.\"\"\"\n",
        "chapter3_2 = \"\"\"Standardized/Real-world problem.\n",
        "**Standardized problem**\n",
        "- Grid-world problem is a two-dimensional rectangular array of square \\\n",
        "cells in which agents can move from cell to cell. \n",
        "- Examples of grid world problem: \n",
        "  - vacuum world, sokoban puzzle, 8-puzzle.\n",
        "\n",
        "**Real-world problem**\n",
        "- route-finding problem. \n",
        "- Examples of route-finding problem\n",
        "  - web-sites, navigation, routing video streams, military operations planning, and airline travel-planning \\\n",
        "systems. \n",
        "- Example of airline travel problem: \n",
        "  - State space include location and the current time\n",
        "  - initial state is the user's home airport\n",
        "  - actions are taking a flight from the current location and leaving after the current time\n",
        "  - transition model will have the flight's destination as the new location and \\\n",
        "arrival time as the new time\n",
        "  - goal state is a destination city\n",
        "  - action cost is sa combination of multiple factors such as monetary cost, waiting time, flight time.\n",
        "\n",
        "Example: Touring \\\n",
        "problems, traveling-salesperson-problem, VLSI layout, Robot-navigation, Automatic-assembly-sequencing \"\"\"\n",
        "chapter3_3 = \"\"\"**State space vs Search tree**: State space decribes the set of states in the world and actions that allow movement from one state to another. \\\n",
        "Search tree describes paths between states and can have multiple paths to any given state, but each node should have unique path back to the root.\"\"\"\n",
        "chapter3_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" \\\n",
        "- **Uninformed**\n",
        "  - use no extra information about the environment\n",
        "- A simple reflex agent ignores the rest of percept history \\\n",
        "and select actions based on the current percept. \n",
        "- However, a problem-solving agent has to plan ahead through search. \n",
        "- If an environment is **fully observable, \\\n",
        "deterministic, and known**, then the solution is a fixed sequence. \n",
        "- If it is **partially observable or nondeterministic**, then the solution should recommend \\\n",
        "future actions through a branching strategy. \n",
        "- Formulate goal, search problem, and find solution. \n",
        "\n",
        "A **search problem** is defined by **6 different things**:\n",
        "- a set \\\n",
        "of states\n",
        "- an initial state\n",
        "- a set of actions that are applicable in s\n",
        "- transition model(successors)\n",
        "- path cost(performance measure)\n",
        "- a goal state.\n",
        "\n",
        "- **Optimal solution** is a solution with the lowest path cost. \n",
        "- **Abstraction** on state space should be done for problem solving. \n",
        "  - The abstraction is *valid* if the path \\\n",
        "between two states reflect the real world. It should be easier than the real problem. \n",
        "- **State space** is the set of all states reachable by the initial state using \\\n",
        "any path. \n",
        "- Frontier is states that are available for exansion. \n",
        "\n",
        "- Basic search algorithm: Tree Search. Root: initial state. Nodes are generated through transition model. \\\n",
        "- Difference between tree search and graph search is that tree search treats different paths to the same node as distinct. \n",
        "- General problem we face in a tree search problems \\\n",
        "is repeated states. \n",
        "- Repeated states can turn a linear problem to an exponential one. \n",
        "- The solution is switching to a graph search. \n",
        "- Graph search is slightly different \\ \n",
        "than the tree search in that it keeps track of all possible states and see if a node has been visited before adding to a search queue. \n",
        "- Extra steps in graph search \\\n",
        "algorithm: 1)initialize the visited set to empty. 2)add the node to the visited set. 3)Only if not in the frontier or explored set. \n",
        "\n",
        "- Uninformed search is also called \"blind search\" where it only uses infomration available in problem definition. \n",
        "- For uninformed search, all non-goal nodes in frontier has equal \\\n",
        "ranks. \n",
        "- For informed search, some can be ranked above others. \n",
        "- Search strategy means in what order we expand the nodes in the frontier queue. \n",
        "- Dimensions for evaluation: \\\n",
        "completeness, optimality, time complexity, and space complexity. \n",
        "- *Breadth-first search* expand shallowest unexpanded node.\n",
        "  - BFS frontier is FIFO queue where you put \\\n",
        "successors at the end of the frontier successor list. \n",
        "  - BFS is complete, O(b^d) time and space complexity, and optimal if cost=1. \n",
        "  - Exponential complexity is not good.\n",
        "\n",
        "- *Depth-first search* expand *deepest* unexpanded node. \n",
        "  - DFS frontier is LIFO queue where you put successors at the front of the successor list. \n",
        "  - DFS is not complete in infinite-depth spaces but complete in finite spaces. \n",
        "  - Time complexity is O(b^m) where m is the maximum depth of the state space. \n",
        "  - If solutions are \\\n",
        "dense, it may be faster than BFS. \n",
        "  - Space-complexity is linear O(bm). \n",
        "  - It is not optimal. \n",
        "\n",
        "- Use **DFS** 1.Space is restricted 2.search can be fine-tuned quickly \\\n",
        "3.Many possible solutions with long paths. \n",
        "- Use **BFS** 1.Possible infinite paths 2.Can quickly discard unlikely paths 3.Some solutions have short paths. \\\n",
        "**DFS** is good in space complexity. \n",
        "\n",
        "- ***Depth-limited search*** is a way to get best of both worlds. \n",
        "  - It is DFS but with depth limit *l*. Optimal if l=d, but \\\n",
        "if l<d then incomplete, and if l>d then not optimal. d is the depth of the shallowest node. \n",
        "  - Time-complexity is O(b^l) and space-complexity is O(bl). \n",
        "\n",
        "- **Iterative \\\n",
        "deepening search (ID-search)** is a strategy to find best depth limit *l*. \n",
        "  - This uses Depth-limited search as subroutine while increasing *l*. It is ***complete&optimal***. Goal \\\n",
        "is always found at depth d. ID search is complete, optimal, space-complexity(O(bd)) \n",
        "\"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",\n",
        "\"atomic\": \"representation used by problem-solving agents, which has no internal structure visible to the algorithm\",\n",
        "\"planning agent\": \"an agent that uses factored or structured representations of states\",\n",
        "\"informed\": \"algorithm that allows the agent to estimate how far it is from the goal state\",\n",
        "\"uninformed\": \"agent cannot estimate how far it is from the goal state\",\n",
        "\"open-loop\" : \"a system where the agent ignores percepts because the solution is guaranteed to end at a goal\",\n",
        "\"closed-loop\" : \"a system that monitors percepts to be safer in a non-deterministic and incorrect environment\",\n",
        "\"state space\" : \"a set of states that athe environment can be in\",\n",
        "\"transition model\" : \"describes what each action does\",\n",
        "\"action cost function\" : \"returns the numeric cost of applying action a in state s to reach state s'\",\n",
        "\"path\" : \"a sequence of actions\",\n",
        "\"solution\" : \"sequence of action that form a path from the initial to the goal state\",\n",
        "\"model\" : \"abstract math description\",\n",
        "\"abstraction\" : \"removing detail from a representation\",\n",
        "\"standardized problem\" : \"used by researchers to illustrate various problem-solving methods\",\n",
        "\"egocentric actions\" : \"actions defined relative to the viewpoint of the agent.\",\n",
        "\"sokoban puzzle\" : \"goal is to push boxes to designated storage locations\",\n",
        "\"Touring problem\" : \"multiple locations that ust be visited\",\n",
        "\"VLSI layout\" : \"positioning components and connections to minimize area, circuit delays, stray capacitances, and maximize manufacturing yield\",\n",
        "\"robot navigation\" : \"generalized version of a route-finding problem\",\n",
        "\"Completeness\" : \"does it always find the solution? and the branching factor b is finite.\",\n",
        "\"optimality\" : \"Find a lowest path cost solution first\",\n",
        "\"time complexity\" : \"number of nodes generated (worst case)\",\n",
        "\"space complexity\" : \"number of nodes simultaneously in memory (worst case)\"\n",
        " \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "bc368fa6-b87d-4da7-9bb2-4c293f86fb4e"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module3_sections = [\n",
        "  (\"AIMA Chapter 3.1 Problem-Solving Agents\", chapter3_1),\n",
        "  (\"AIMA Chapter 3.2 Example Problems\", chapter3_2),\n",
        "  (\"AIMA Chapter 3.3 Search Algorithms\", chapter3_3),\n",
        "  (\"AIMA Chapter 3.4 Uninformed Search Strategies\", chapter3_4),\n",
        "  (\"Module 3 Lecture Notes\", module3_lecture_notes),\n",
        "]\n",
        "\n",
        "module3_markdown = format_module(3, \"Search Problems\", module3_sections, module3_definitions)\n",
        "display(Markdown(module3_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n - Four phases of problem-solving process with known environment:\n  1) Goal-formation\n  2) Problem-formation(formulate a description of the states and actions needed to reach goal)\n  3) Search(simulate actions until you find a solution)\n  4) Execution\n\n- Known environment's solution is always a fixed sequence of actions.\n- A **search problem** consists of \n  1) state-space \n  2) initial-state \n  3) goal-states \n  4) actions \n  5) transition-model \n  6) action-cost-function\n\n- Total cost of a path is the sum of individual costs. \n- Optimal solution has the lowest total cost. \n- State space can be represented in graphs. \n- **Abstraction** is valid if we can elaborate abstract solution into a more detailed world. \n- **Abstraction** is useful if carrying actions is easier than the original problem.\n\n## AIMA Chapter 3.2 Example Problems\nStandardized/Real-world problem.\n**Standardized problem**\n- Grid-world problem is a two-dimensional rectangular array of square cells in which agents can move from cell to cell. \n- Examples of grid world problem: \n  - vacuum world, sokoban puzzle, 8-puzzle.\n\n**Real-world problem**\n- route-finding problem. \n- Examples of route-finding problem\n  - web-sites, navigation, routing video streams, military operations planning, and airline travel-planning systems. \n- Example of airline travel problem: \n  - State space include location and the current time\n  - initial state is the user's home airport\n  - actions are taking a flight from the current location and leaving after the current time\n  - transition model will have the flight's destination as the new location and arrival time as the new time\n  - goal state is a destination city\n  - action cost is sa combination of multiple factors such as monetary cost, waiting time, flight time.\n\nExample: Touring problems, traveling-salesperson-problem, VLSI layout, Robot-navigation, Automatic-assembly-sequencing \n\n## AIMA Chapter 3.3 Search Algorithms\n**State space vs Search tree**: State space decribes the set of states in the world and actions that allow movement from one state to another. Search tree describes paths between states and can have multiple paths to any given state, but each node should have unique path back to the root.\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n - **Uninformed**\n  - use no extra information about the environment\n- A simple reflex agent ignores the rest of percept history and select actions based on the current percept. \n- However, a problem-solving agent has to plan ahead through search. \n- If an environment is **fully observable, deterministic, and known**, then the solution is a fixed sequence. \n- If it is **partially observable or nondeterministic**, then the solution should recommend future actions through a branching strategy. \n- Formulate goal, search problem, and find solution. \n\nA **search problem** is defined by **6 different things**:\n- a set of states\n- an initial state\n- a set of actions that are applicable in s\n- transition model(successors)\n- path cost(performance measure)\n- a goal state.\n\n- **Optimal solution** is a solution with the lowest path cost. \n- **Abstraction** on state space should be done for problem solving. \n  - The abstraction is *valid* if the path between two states reflect the real world. It should be easier than the real problem. \n- **State space** is the set of all states reachable by the initial state using any path. \n- Frontier is states that are available for exansion. \n\n- Basic search algorithm: Tree Search. Root: initial state. Nodes are generated through transition model. - Difference between tree search and graph search is that tree search treats different paths to the same node as distinct. \n- General problem we face in a tree search problems is repeated states. \n- Repeated states can turn a linear problem to an exponential one. \n- The solution is switching to a graph search. \n- Graph search is slightly different \\ \nthan the tree search in that it keeps track of all possible states and see if a node has been visited before adding to a search queue. \n- Extra steps in graph search algorithm: 1)initialize the visited set to empty. 2)add the node to the visited set. 3)Only if not in the frontier or explored set. \n\n- Uninformed search is also called \"blind search\" where it only uses infomration available in problem definition. \n- For uninformed search, all non-goal nodes in frontier has equal ranks. \n- For informed search, some can be ranked above others. \n- Search strategy means in what order we expand the nodes in the frontier queue. \n- Dimensions for evaluation: completeness, optimality, time complexity, and space complexity. \n- *Breadth-first search* expand shallowest unexpanded node.\n  - BFS frontier is FIFO queue where you put successors at the end of the frontier successor list. \n  - BFS is complete, O(b^d) time and space complexity, and optimal if cost=1. \n  - Exponential complexity is not good.\n\n- *Depth-first search* expand *deepest* unexpanded node. \n  - DFS frontier is LIFO queue where you put successors at the front of the successor list. \n  - DFS is not complete in infinite-depth spaces but complete in finite spaces. \n  - Time complexity is O(b^m) where m is the maximum depth of the state space. \n  - If solutions are dense, it may be faster than BFS. \n  - Space-complexity is linear O(bm). \n  - It is not optimal. \n\n- Use **DFS** 1.Space is restricted 2.search can be fine-tuned quickly 3.Many possible solutions with long paths. \n- Use **BFS** 1.Possible infinite paths 2.Can quickly discard unlikely paths 3.Some solutions have short paths. **DFS** is good in space complexity. \n\n- ***Depth-limited search*** is a way to get best of both worlds. \n  - It is DFS but with depth limit *l*. Optimal if l=d, but if l<d then incomplete, and if l>d then not optimal. d is the depth of the shallowest node. \n  - Time-complexity is O(b^l) and space-complexity is O(bl). \n\n- **Iterative deepening search (ID-search)** is a strategy to find best depth limit *l*. \n  - This uses Depth-limited search as subroutine while increasing *l*. It is ***complete&optimal***. Goal is always found at depth d. ID search is complete, optimal, space-complexity(O(bd)) \n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Atomic** - representation used by problem-solving agents, which has no internal structure visible to the algorithm\n* **Planning agent** - an agent that uses factored or structured representations of states\n* **Informed** - algorithm that allows the agent to estimate how far it is from the goal state\n* **Uninformed** - agent cannot estimate how far it is from the goal state\n* **Open-loop** - a system where the agent ignores percepts because the solution is guaranteed to end at a goal\n* **Closed-loop** - a system that monitors percepts to be safer in a non-deterministic and incorrect environment\n* **State space** - a set of states that athe environment can be in\n* **Transition model** - describes what each action does\n* **Action cost function** - returns the numeric cost of applying action a in state s to reach state s'\n* **Path** - a sequence of actions\n* **Solution** - sequence of action that form a path from the initial to the goal state\n* **Model** - abstract math description\n* **Abstraction** - removing detail from a representation\n* **Standardized problem** - used by researchers to illustrate various problem-solving methods\n* **Egocentric actions** - actions defined relative to the viewpoint of the agent.\n* **Sokoban puzzle** - goal is to push boxes to designated storage locations\n* **Touring problem** - multiple locations that ust be visited\n* **Vlsi layout** - positioning components and connections to minimize area, circuit delays, stray capacitances, and maximize manufacturing yield\n* **Robot navigation** - generalized version of a route-finding problem\n* **Completeness** - does it always find the solution? and the branching factor b is finite.\n* **Optimality** - Find a lowest path cost solution first\n* **Time complexity** - number of nodes generated (worst case)\n* **Space complexity** - number of nodes simultaneously in memory (worst case)\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WHREsHSSyA-h"
      },
      "source": [
        "#Module 4 - Informed Search"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tuFC8w7CyCns"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
        "chapter3_5 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\"**Uniform-cost-search (UCS)** is a tree search algoirthm used to traverse a weighted tree. Used for map navigation problems where we care about the cost \\\n",
        "of the action. **g(n)** is the path cost function. Assuming all costs being equal, g(n) would be the depth in the search tree. Assigning unique costs \\\n",
        "g(n) would be the sum of all costs getting to the goal. **UCS** is an extension of BFS where it expands node with lowest path cost. Frontier is a priority queue \\\n",
        "ordered by g(n). *Difference from BFS*: It tests if a node is a goal state before adding to the frontier; It updates a node if a better path to the same state exists; \\\n",
        "Enqueues a node before checking whether it is a goal. UCS prioritizes lower cost paths. **INFORMED SEARCH** expands node based on estimation which includes \\\n",
        "distance to the goal. *Best-first search* select nodes based on an evaluation function f(n), where it is an estimate of distance to goal. You sort frontier queue \\\n",
        "using f(n). Heuristic function h(n) returns an estimate of the distance from n to the goal. ***Greedy Best-First Search*** Select node for exansion with minimum evaluation \\\n",
        "function f(n). Use priority queue. Same as UCS but f(n) instead of g(n). Greedy best-first search f(n)=h(n). Ignores g(n) which is the cost to get to n. \\\n",
        "Manhattan distance can be used as the heuristic distance in a grid. It is not complete nor optimal. ***A-star search*** expand most promising paths first. \\\n",
        "f(n) = g(n) + h(n). g(n) is the actual cost so far from the start to reach the node. h(n) is estimated cost to get from the node to the goal. f(n) is \\\n",
        "estimated total cost of path through n to goal. Frontier queue as increasing priority queue. Admissible heuristics - admissible if it never overestimates \\\n",
        "cost to reach the goal. *If h(n) is admissible, A-star using Tree Search is optimal* Admissible heuristics slow down bad plans but don't outwiegh true costs. \\\n",
        "It is not necessary to remove visited node from the frontier queue. Relaxed problem is a problem with less restricted actions than the original. The cost of \\\n",
        "an optimal solution to a relaxed problem is original problem's admissible heuristic. Dominance is a way of showing which heuristic is better. Better the \\\n",
        "heuristic, less nodes you ahve to visit. *Proving Optimality of A-star tree search*: Imagine b in frnotier, Some ancestor n of A in frontier too, Claim \\\n",
        "n will be expanded before B (f(n) is less or equal to f(A), f(A) is less than f(B), n expands before B), All ancestors of A expand before B, A expands \\\n",
        "before B, and A-star search is optimal. A-star algorithm is applied in routing problmes, video games, robot motion planning, etc.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 681
        },
        "cellView": "form",
        "outputId": "034d09ea-8dba-4868-d7ed-64aebb6d5bdf"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module4_sections = [\n",
        "  (\"AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\", chapter3_5),\n",
        "  (\"AIMA Chapter 3.6 Heuristic Functions\", chapter3_6),\n",
        "  (\"Module 4 Lecture Notes\", module4_lecture_notes),\n",
        "]\n",
        "\n",
        "module4_markdown = format_module(4, \"Informed Search\", \n",
        "                         module4_sections, \n",
        "                         module4_definitions)\n",
        "display(Markdown(module4_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n**Uniform-cost-search (UCS)** is a tree search algoirthm used to traverse a weighted tree. Used for map navigation problems where we care about the cost of the action. **g(n)** is the path cost function. Assuming all costs being equal, g(n) would be the depth in the search tree. Assigning unique costs g(n) would be the sum of all costs getting to the goal. **UCS** is an extension of BFS where it expands node with lowest path cost. Frontier is a priority queue ordered by g(n). *Difference from BFS*: It tests if a node is a goal state before adding to the frontier; It updates a node if a better path to the same state exists; Enqueues a node before checking whether it is a goal. UCS prioritizes lower cost paths. **INFORMED SEARCH** expands node based on estimation which includes distance to the goal. *Best-first search* select nodes based on an evaluation function f(n), where it is an estimate of distance to goal. You sort frontier queue using f(n). Heuristic function h(n) returns an estimate of the distance from n to the goal. ***Greedy Best-First Search*** Select node for exansion with minimum evaluation function f(n). Use priority queue. Same as UCS but f(n) instead of g(n). Greedy best-first search f(n)=h(n). Ignores g(n) which is the cost to get to n. Manhattan distance can be used as the heuristic distance in a grid. It is not complete nor optimal. ***A-star search*** expand most promising paths first. f(n) = g(n) + h(n). g(n) is the actual cost so far from the start to reach the node. h(n) is estimated cost to get from the node to the goal. f(n) is estimated total cost of path through n to goal. Frontier queue as increasing priority queue. Admissible heuristics - admissible if it never overestimates cost to reach the goal. *If h(n) is admissible, A-star using Tree Search is optimal* Admissible heuristics slow down bad plans but don't outwiegh true costs. It is not necessary to remove visited node from the frontier queue. Relaxed problem is a problem with less restricted actions than the original. The cost of an optimal solution to a relaxed problem is original problem's admissible heuristic. Dominance is a way of showing which heuristic is better. Better the heuristic, less nodes you ahve to visit. *Proving Optimality of A-star tree search*: Imagine b in frnotier, Some ancestor n of A in frontier too, Claim n will be expanded before B (f(n) is less or equal to f(A), f(A) is less than f(B), n expands before B), All ancestors of A expand before B, A expands before B, and A-star search is optimal. A-star algorithm is applied in routing problmes, video games, robot motion planning, etc.\n\n## Module 4 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" Game vs. Puzzle. Games have an opponent. *Simple game* is *multiagent, static, discrete, fully observable, and strategic*. \\\n",
        "Strategic: the next state is determined by the current and the action executed by the agent and the actions of one other agent. Zero-sum: one player's loss \\\n",
        "is another's gain. Game set up: *Min* and *Max* are two players where *Max* moves first. Utility function gives numerical value of terminal states. *Example*: \\\n",
        "*Hexapawn*. Game trees is a representation of the game problem space \\\n",
        "by a tree: nodes are 'board positions', edges are 'legal moves', and root \\\n",
        "node is the first position in which a decision must be made. f(n) is the evaluation \\\n",
        "function that evaluates how good a position is based on static features. \\\n",
        "Use zero-sum assumption to use one function to describe goodness for both players.\\\n",
        "f(n)>0 if MAX is winning, f(n)=0 if tied, f(n)<0 if MIN is winning. **Minimax algorithm**: \\\n",
        "Make the best move for MAX assuming the MIN always replies with the best move for MIN.\\\n",
        "Computed using a *recursive process*: The ***backed-up value*** for MAX node \\\n",
        "is the maximum of the values of its children, and for MIN node, it is the minimum of \\\n",
        "the values of its children. **Adversarial Search(Minimax)***: a state-space \\\n",
        "search tree, players alternate turns, compute each node's minimax value: \\\n",
        "the best achievable utility against an optimal adversary. ***Alpha-Beta \\\n",
        "Pruning*** alpha is MAX's current *lower* bound on MAX's outcome. beta \\\n",
        "is MIN's current *upper* bound on MIN's outcome. MAX will never allow \\\n",
        "a move that could lead to a worse score than alpha, and MIN will never allow a move that \\\n",
        "could lead to a better score(for MAX) than beta.\n",
        "\n",
        "**Expectimax**\n",
        "- used for games with uncertain outcome\n",
        "- We don't know what the expected result of an action is\n",
        "- Compute the average score under optimal play\n",
        "  - max nodes as in minimax search\n",
        "  - Chance nodes are like min nodes but the outcome is uncertain\n",
        "  - Calculate their expected utilities\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"Static\" : \"No change while an agent is deliberating\",\n",
        "\"Discrete\" : \"A finite set percepts and actions\",\n",
        "\"Fully observable\" : \"sensors give it the complete state of the environment\",\n",
        "    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "80ddef14-086b-457e-8a97-796a00632945"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module5_sections = [\n",
        "  (\"AIMA Chapter 5.1 Game Theory\", chapter5_1),\n",
        "  (\"AIMA Chapter 5.2 Optimal Decisions in Games\", chapter5_2),\n",
        "  (\"AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\", chapter5_3),\n",
        "  (\"AIMA Chapter 5.5 Stochastic Games\", chapter5_5),\n",
        "  (\"AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\", chapter16_1),\n",
        "  (\"AIMA Chapter 16.2 The Basis of Utility Theory\", chapter16_2),\n",
        "  (\"AIMA Chapter 16.3 Utility Functions\", chapter16_3),\n",
        "  (\"Module 5 Lecture Notes\", module5_lecture_notes),\n",
        "]\n",
        "\n",
        "module5_markdown = format_module(5, \"Adversarial Search and Games\", \n",
        "                         module5_sections, \n",
        "                         module5_definitions)\n",
        "display(Markdown(module5_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n Game vs. Puzzle. Games have an opponent. *Simple game* is *multiagent, static, discrete, fully observable, and strategic*. Strategic: the next state is determined by the current and the action executed by the agent and the actions of one other agent. Zero-sum: one player's loss is another's gain. Game set up: *Min* and *Max* are two players where *Max* moves first. Utility function gives numerical value of terminal states. *Example*: *Hexapawn*. Game trees is a representation of the game problem space by a tree: nodes are 'board positions', edges are 'legal moves', and root node is the first position in which a decision must be made. f(n) is the evaluation function that evaluates how good a position is based on static features. Use zero-sum assumption to use one function to describe goodness for both players.f(n)>0 if MAX is winning, f(n)=0 if tied, f(n)<0 if MIN is winning. **Minimax algorithm**: Make the best move for MAX assuming the MIN always replies with the best move for MIN.Computed using a *recursive process*: The ***backed-up value*** for MAX node is the maximum of the values of its children, and for MIN node, it is the minimum of the values of its children. **Adversarial Search(Minimax)***: a state-space search tree, players alternate turns, compute each node's minimax value: the best achievable utility against an optimal adversary. ***Alpha-Beta Pruning*** alpha is MAX's current *lower* bound on MAX's outcome. beta is MIN's current *upper* bound on MIN's outcome. MAX will never allow a move that could lead to a worse score than alpha, and MIN will never allow a move that could lead to a better score(for MAX) than beta.\n\n**Expectimax**\n- used for games with uncertain outcome\n- We don't know what the expected result of an action is\n- Compute the average score under optimal play\n  - max nodes as in minimax search\n  - Chance nodes are like min nodes but the outcome is uncertain\n  - Calculate their expected utilities\n\n## Module 5 Definitions\n* **Static** - No change while an agent is deliberating\n* **Discrete** - A finite set percepts and actions\n* **Fully observable** - sensors give it the complete state of the environment\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qVSQhTVSyYYO"
      },
      "source": [
        "#Module 6 - \"Constraint Satisfaction Problems\""
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wm4mfW82yaRH"
      },
      "source": [
        "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
        "chapter6_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\" \\\n",
        "What is Search for?\n",
        "- Assumptions baout the world: a single agent, deterministic actions, fully \\\n",
        "observable state, discrete state space.\n",
        "- We do search to formulate a plan\n",
        "- Identification: assignments to variables\n",
        "\n",
        "**Constraint Satisfaction Problems**\n",
        "- *Specialized for Identification problems*\n",
        "- Big Idea:\n",
        "  - Represent the *constraints* that solutions must satisfy in a uniform \\\n",
        "  *declarative* language\n",
        "  - Find solutions using *general purpose* search algorithms\n",
        "  - Only formal specification of the CSP is needed\n",
        "- A CSP consists of:\n",
        "  - finite set of variables, nonempty domain of possible values, \\\n",
        "  finite set of constraints\n",
        "  - A *consistent* assignment does not violate the constraints\n",
        "- Ex: Sudoku\n",
        "- A *solution* is a *complete, consistent* assignment.\n",
        "  - *Complete* is when every variable is assigned a value\n",
        "- **Benefits of CSP**\n",
        "  - Clean specification of many problems, generic goal, successor function \\\n",
        "  and heuristics\n",
        "  - \"knows\" which variable violate a constraint\n",
        "  - Automatically prune off all branches that violate constraints\n",
        "\n",
        "- **Varieties of CSPs**\n",
        "  - *Discrete variables*\n",
        "    - finite domains: Boolean CSPs\n",
        "    - infinite domains: job scheduling\n",
        "  - *Continuous variables*\n",
        "    - linear constraints solvable in polynomial time by linear programming\n",
        "\n",
        "- **Varieties of constraints**\n",
        "  - ***Unary*** involve single variable\n",
        "  - ***Binary*** involve pairs of variables\n",
        "  - ***Higher-order*** involve 3 or more variables\n",
        "  - ***Preference***(soft constraints) e.g. red is better than green\n",
        "\n",
        "- **CSP as a search problem**\n",
        "  - *Initial State*: empty assignment {}\n",
        "  - *Successor function*: assign value to any unassigned variable provided that there is not a constraint conflict\n",
        "  - *Goal test*: the current assignment is complete\n",
        "  - *Path cost* : a constant cost for every step\n",
        "  - Solution is always found at depth n, for n variables\n",
        "\n",
        "- **Backtracking algorithm**\n",
        "  - DFS for CSPs with single-variable assignments\n",
        "  - Basic *uninformed* algorithm for CSPs\n",
        "  - DFS that chooses values for one variable at a timte and backtracks when \\\n",
        "  when a variable has no legal values left to assign.\n",
        "  - *ways to improve speed*\n",
        "    - Assign most constrained variable first then most contraining variable\n",
        "      - *minimum remaining values* heuristic\n",
        "    - Least constraining value of a variable should be tried first\n",
        "    - Detect inevitable failure early through forward checking\n",
        "\n",
        "- Inference **(Forward) checking** algorithm\n",
        "  - Keep track of *remaining* legal values for *unassigned* variables\n",
        "  - Terminate search when any unassigned variable has no remaining legal values\n",
        "  - Propagates infomration from *assigned* to *unassigned* variables, \\\n",
        "  but doesn't provide early detection for all failures\n",
        "\n",
        "- ***Inference*** **in CSPs**\n",
        "  - CSP solvers combine search and inference\n",
        "    - Search is assigning a value to a variable\n",
        "    - Inference (constraint propagation): eliminates possible values for a variable\\\n",
        "    if the value would violate local consistency\n",
        "\n",
        "-**Node consistency**\n",
        "  - satisfies unary constraints\n",
        "\n",
        "- **Arc Consistency**\n",
        "  - satisfies binary constraints\n",
        "  - Definition: An arc(i,j) is **arc consistent** if and only if every \\\n",
        "  value v on X_i is consistent with some label on Y_j\n",
        "  \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "a0e90fa3-1012-4901-ff80-7c5f9aa1cad3"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module6_sections = [\n",
        "  (\"AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\", chapter6_1),\n",
        "  (\"AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\", chapter6_2),\n",
        "  (\"AIMA Chapter 6.3 Backtracking Search for CSPs\", chapter6_3),\n",
        "  (\"AIMA Chapter 6.4 Local Search for CSPs\", chapter6_4),\n",
        "  (\"AIMA Chapter 6.5 The Structure of Problems\", chapter6_5),\n",
        "  (\"Module 6 Lecture Notes\", module6_lecture_notes),\n",
        "]\n",
        "\n",
        "module6_markdown = format_module(6, \"Constraint Satisfaction Problems\", \n",
        "                         module6_sections, \n",
        "                         module6_definitions)\n",
        "display(Markdown(module6_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n What is Search for?\n- Assumptions baout the world: a single agent, deterministic actions, fully observable state, discrete state space.\n- We do search to formulate a plan\n- Identification: assignments to variables\n\n**Constraint Satisfaction Problems**\n- *Specialized for Identification problems*\n- Big Idea:\n  - Represent the *constraints* that solutions must satisfy in a uniform   *declarative* language\n  - Find solutions using *general purpose* search algorithms\n  - Only formal specification of the CSP is needed\n- A CSP consists of:\n  - finite set of variables, nonempty domain of possible values,   finite set of constraints\n  - A *consistent* assignment does not violate the constraints\n- Ex: Sudoku\n- A *solution* is a *complete, consistent* assignment.\n  - *Complete* is when every variable is assigned a value\n- **Benefits of CSP**\n  - Clean specification of many problems, generic goal, successor function   and heuristics\n  - \"knows\" which variable violate a constraint\n  - Automatically prune off all branches that violate constraints\n\n- **Varieties of CSPs**\n  - *Discrete variables*\n    - finite domains: Boolean CSPs\n    - infinite domains: job scheduling\n  - *Continuous variables*\n    - linear constraints solvable in polynomial time by linear programming\n\n- **Varieties of constraints**\n  - ***Unary*** involve single variable\n  - ***Binary*** involve pairs of variables\n  - ***Higher-order*** involve 3 or more variables\n  - ***Preference***(soft constraints) e.g. red is better than green\n\n- **CSP as a search problem**\n  - *Initial State*: empty assignment {}\n  - *Successor function*: assign value to any unassigned variable provided that there is not a constraint conflict\n  - *Goal test*: the current assignment is complete\n  - *Path cost* : a constant cost for every step\n  - Solution is always found at depth n, for n variables\n\n- **Backtracking algorithm**\n  - DFS for CSPs with single-variable assignments\n  - Basic *uninformed* algorithm for CSPs\n  - DFS that chooses values for one variable at a timte and backtracks when   when a variable has no legal values left to assign.\n  - *ways to improve speed*\n    - Assign most constrained variable first then most contraining variable\n      - *minimum remaining values* heuristic\n    - Least constraining value of a variable should be tried first\n    - Detect inevitable failure early through forward checking\n\n- Inference **(Forward) checking** algorithm\n  - Keep track of *remaining* legal values for *unassigned* variables\n  - Terminate search when any unassigned variable has no remaining legal values\n  - Propagates infomration from *assigned* to *unassigned* variables,   but doesn't provide early detection for all failures\n\n- ***Inference*** **in CSPs**\n  - CSP solvers combine search and inference\n    - Search is assigning a value to a variable\n    - Inference (constraint propagation): eliminates possible values for a variable    if the value would violate local consistency\n\n-**Node consistency**\n  - satisfies unary constraints\n\n- **Arc Consistency**\n  - satisfies binary constraints\n  - Definition: An arc(i,j) is **arc consistent** if and only if every   value v on X_i is consistent with some label on Y_j\n  \n\n## Module 6 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\"\\\n",
        "**Knowledge-Based Agents**\n",
        "- Use a process of **reasoning** over an internal **representation** \\\n",
        "of knowledge to decide what action to take\n",
        "- **Knowledge base(KB)** is a central component of a knowledge-based agent\n",
        "  - Contains a set of **sentence** that are written in a **knowledge representation language**\n",
        "  - KB is *false* in mnodels that contradict what the agent knows.\n",
        "\n",
        "-**Propositional Logic**\n",
        "  - **Atomic sentences** are represented with a single *propositional symbols*\n",
        "  - Propositional symbols stand for a statement that can be true or false\n",
        "  - **Complex sentences** are constructed from simpler ones using parentheses and *logical connectives*\n",
        "\n",
        "  \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"atomic\" : \"definition\",\n",
        "\"axioms\" : \"a sentence that is given\",\n",
        "\"Derived sentences\" : \"a new sentence that is derived from other sentences\",\n",
        "\"Model checking\" :\"the process of enumerating all possible models that are\\\n",
        "compatible with the KB\",\n",
        "\"Sound\" : \"inference algorithm shoudl only derive entailed sentences\",\n",
        "\"Complete\" : \"inference algorithm is complete if it can derive all sentences that are entailed\",\n",
        "\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 786
        },
        "outputId": "8c8de0d9-11d2-45fa-95ae-bd79be8c7731"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module7_sections = [\n",
        "  (\"AIMA Chapter 7.1 Knowledge-Based Agents\", chapter7_1),\n",
        "  (\"AIMA Chapter 7.2 The Wumpus World\", chapter7_2),\n",
        "  (\"AIMA Chapter 7.3 Logic\", chapter7_3),\n",
        "  (\"AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\", chapter7_4),\n",
        "  (\"AIMA 7.5 Propositional Theorem Proving\", chapter7_5),\n",
        "  (\"Module 7 Lecture Notes\", module7_lecture_notes),\n",
        "]\n",
        "\n",
        "module7_markdown = format_module(7, \"Logical Agents\", \n",
        "                         module7_sections, \n",
        "                         module7_definitions)\n",
        "display(Markdown(module7_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n**Knowledge-Based Agents**\n- Use a process of **reasoning** over an internal **representation** of knowledge to decide what action to take\n- **Knowledge base(KB)** is a central component of a knowledge-based agent\n  - Contains a set of **sentence** that are written in a **knowledge representation language**\n  - KB is *false* in mnodels that contradict what the agent knows.\n\n-**Propositional Logic**\n  - **Atomic sentences** are represented with a single *propositional symbols*\n  - Propositional symbols stand for a statement that can be true or false\n  - **Complex sentences** are constructed from simpler ones using parentheses and *logical connectives*\n\n  \n\n## Module 7 Definitions\n* **Atomic** - definition\n* **Axioms** - a sentence that is given\n* **Derived sentences** - a new sentence that is derived from other sentences\n* **Model checking** - the process of enumerating all possible models that arecompatible with the KB\n* **Sound** - inference algorithm shoudl only derive entailed sentences\n* **Complete** - inference algorithm is complete if it can derive all sentences that are entailed\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vX7lbnJd4sT5"
      },
      "source": [
        "# Your Exam Notes\n",
        "\n",
        "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
        "\n",
        "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
        "* Run the cell below. \n",
        "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "e2b61b2a-92e7-49a5-ab93-c8b967e36673"
      },
      "source": [
        "# This will generate the full set of notes that you can use for your exam.\n",
        "full_markdown = \"\\n\\n\".join([module1_markdown, \n",
        "                             module2_markdown, \n",
        "                             module3_markdown, \n",
        "                             module4_markdown, \n",
        "                             module5_markdown,\n",
        "                             module6_markdown,\n",
        "                             module7_markdown,]\n",
        "                       )\n",
        "display(Markdown(full_markdown))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n**Agents**\n- *Perceive* its environment through sensors\n- *Acting* upon that environment through actuators\n- Ex: Human agent(sensors are eyes, ears ; actuators are hands, legs)\n- Ex: thermostats, robots\n\n**Rational agent**\n- Agent that perceives its environment and behaves rationally\n- It is not guaranteed to find optimal solutions\n- It selects an action that maximizes the expected value of its performance measure\n- Define *performance measure* with the evidence provided by the percept sequence\n- We need to specify a *task environment*\n  - PEAS(performance measure, environment, actuators, sensors)\n\n- An agent’s choice of action at a given instant does not depend both on its percept sequence and future perceptual inputs\n\n\n## Module 1 Definitions\n* **Agent** - anything that can perceive through sensors and act in an environment through actuators\n* **Percept** - agent's perceptual inputs\n* **Reflex agent** - action based on the current percept and ignore the percept history.\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n\n- **Tuple**\n  - *immutable* ordered sequence of items\n- **Strings**\n  - *immutable*\n- **List**\n  - *Mutable*\n- **Dictionaries**\n  - keys are immutable\n\n## Module 2 Definitions\n* **Immutable** - cannot be modified once created\n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n - Four phases of problem-solving process with known environment:\n  1) Goal-formation\n  2) Problem-formation(formulate a description of the states and actions needed to reach goal)\n  3) Search(simulate actions until you find a solution)\n  4) Execution\n\n- Known environment's solution is always a fixed sequence of actions.\n- A **search problem** consists of \n  1) state-space \n  2) initial-state \n  3) goal-states \n  4) actions \n  5) transition-model \n  6) action-cost-function\n\n- Total cost of a path is the sum of individual costs. \n- Optimal solution has the lowest total cost. \n- State space can be represented in graphs. \n- **Abstraction** is valid if we can elaborate abstract solution into a more detailed world. \n- **Abstraction** is useful if carrying actions is easier than the original problem.\n\n## AIMA Chapter 3.2 Example Problems\nStandardized/Real-world problem.\n**Standardized problem**\n- Grid-world problem is a two-dimensional rectangular array of square cells in which agents can move from cell to cell. \n- Examples of grid world problem: \n  - vacuum world, sokoban puzzle, 8-puzzle.\n\n**Real-world problem**\n- route-finding problem. \n- Examples of route-finding problem\n  - web-sites, navigation, routing video streams, military operations planning, and airline travel-planning systems. \n- Example of airline travel problem: \n  - State space include location and the current time\n  - initial state is the user's home airport\n  - actions are taking a flight from the current location and leaving after the current time\n  - transition model will have the flight's destination as the new location and arrival time as the new time\n  - goal state is a destination city\n  - action cost is sa combination of multiple factors such as monetary cost, waiting time, flight time.\n\nExample: Touring problems, traveling-salesperson-problem, VLSI layout, Robot-navigation, Automatic-assembly-sequencing \n\n## AIMA Chapter 3.3 Search Algorithms\n**State space vs Search tree**: State space decribes the set of states in the world and actions that allow movement from one state to another. Search tree describes paths between states and can have multiple paths to any given state, but each node should have unique path back to the root.\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n - **Uninformed**\n  - use no extra information about the environment\n- A simple reflex agent ignores the rest of percept history and select actions based on the current percept. \n- However, a problem-solving agent has to plan ahead through search. \n- If an environment is **fully observable, deterministic, and known**, then the solution is a fixed sequence. \n- If it is **partially observable or nondeterministic**, then the solution should recommend future actions through a branching strategy. \n- Formulate goal, search problem, and find solution. \n\nA **search problem** is defined by **6 different things**:\n- a set of states\n- an initial state\n- a set of actions that are applicable in s\n- transition model(successors)\n- path cost(performance measure)\n- a goal state.\n\n- **Optimal solution** is a solution with the lowest path cost. \n- **Abstraction** on state space should be done for problem solving. \n  - The abstraction is *valid* if the path between two states reflect the real world. It should be easier than the real problem. \n- **State space** is the set of all states reachable by the initial state using any path. \n- Frontier is states that are available for exansion. \n\n- Basic search algorithm: Tree Search. Root: initial state. Nodes are generated through transition model. - Difference between tree search and graph search is that tree search treats different paths to the same node as distinct. \n- General problem we face in a tree search problems is repeated states. \n- Repeated states can turn a linear problem to an exponential one. \n- The solution is switching to a graph search. \n- Graph search is slightly different \\ \nthan the tree search in that it keeps track of all possible states and see if a node has been visited before adding to a search queue. \n- Extra steps in graph search algorithm: 1)initialize the visited set to empty. 2)add the node to the visited set. 3)Only if not in the frontier or explored set. \n\n- Uninformed search is also called \"blind search\" where it only uses infomration available in problem definition. \n- For uninformed search, all non-goal nodes in frontier has equal ranks. \n- For informed search, some can be ranked above others. \n- Search strategy means in what order we expand the nodes in the frontier queue. \n- Dimensions for evaluation: completeness, optimality, time complexity, and space complexity. \n- *Breadth-first search* expand shallowest unexpanded node.\n  - BFS frontier is FIFO queue where you put successors at the end of the frontier successor list. \n  - BFS is complete, O(b^d) time and space complexity, and optimal if cost=1. \n  - Exponential complexity is not good.\n\n- *Depth-first search* expand *deepest* unexpanded node. \n  - DFS frontier is LIFO queue where you put successors at the front of the successor list. \n  - DFS is not complete in infinite-depth spaces but complete in finite spaces. \n  - Time complexity is O(b^m) where m is the maximum depth of the state space. \n  - If solutions are dense, it may be faster than BFS. \n  - Space-complexity is linear O(bm). \n  - It is not optimal. \n\n- Use **DFS** 1.Space is restricted 2.search can be fine-tuned quickly 3.Many possible solutions with long paths. \n- Use **BFS** 1.Possible infinite paths 2.Can quickly discard unlikely paths 3.Some solutions have short paths. **DFS** is good in space complexity. \n\n- ***Depth-limited search*** is a way to get best of both worlds. \n  - It is DFS but with depth limit *l*. Optimal if l=d, but if l<d then incomplete, and if l>d then not optimal. d is the depth of the shallowest node. \n  - Time-complexity is O(b^l) and space-complexity is O(bl). \n\n- **Iterative deepening search (ID-search)** is a strategy to find best depth limit *l*. \n  - This uses Depth-limited search as subroutine while increasing *l*. It is ***complete&optimal***. Goal is always found at depth d. ID search is complete, optimal, space-complexity(O(bd)) \n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Atomic** - representation used by problem-solving agents, which has no internal structure visible to the algorithm\n* **Planning agent** - an agent that uses factored or structured representations of states\n* **Informed** - algorithm that allows the agent to estimate how far it is from the goal state\n* **Uninformed** - agent cannot estimate how far it is from the goal state\n* **Open-loop** - a system where the agent ignores percepts because the solution is guaranteed to end at a goal\n* **Closed-loop** - a system that monitors percepts to be safer in a non-deterministic and incorrect environment\n* **State space** - a set of states that athe environment can be in\n* **Transition model** - describes what each action does\n* **Action cost function** - returns the numeric cost of applying action a in state s to reach state s'\n* **Path** - a sequence of actions\n* **Solution** - sequence of action that form a path from the initial to the goal state\n* **Model** - abstract math description\n* **Abstraction** - removing detail from a representation\n* **Standardized problem** - used by researchers to illustrate various problem-solving methods\n* **Egocentric actions** - actions defined relative to the viewpoint of the agent.\n* **Sokoban puzzle** - goal is to push boxes to designated storage locations\n* **Touring problem** - multiple locations that ust be visited\n* **Vlsi layout** - positioning components and connections to minimize area, circuit delays, stray capacitances, and maximize manufacturing yield\n* **Robot navigation** - generalized version of a route-finding problem\n* **Completeness** - does it always find the solution? and the branching factor b is finite.\n* **Optimality** - Find a lowest path cost solution first\n* **Time complexity** - number of nodes generated (worst case)\n* **Space complexity** - number of nodes simultaneously in memory (worst case)\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n**Uniform-cost-search (UCS)** is a tree search algoirthm used to traverse a weighted tree. Used for map navigation problems where we care about the cost of the action. **g(n)** is the path cost function. Assuming all costs being equal, g(n) would be the depth in the search tree. Assigning unique costs g(n) would be the sum of all costs getting to the goal. **UCS** is an extension of BFS where it expands node with lowest path cost. Frontier is a priority queue ordered by g(n). *Difference from BFS*: It tests if a node is a goal state before adding to the frontier; It updates a node if a better path to the same state exists; Enqueues a node before checking whether it is a goal. UCS prioritizes lower cost paths. **INFORMED SEARCH** expands node based on estimation which includes distance to the goal. *Best-first search* select nodes based on an evaluation function f(n), where it is an estimate of distance to goal. You sort frontier queue using f(n). Heuristic function h(n) returns an estimate of the distance from n to the goal. ***Greedy Best-First Search*** Select node for exansion with minimum evaluation function f(n). Use priority queue. Same as UCS but f(n) instead of g(n). Greedy best-first search f(n)=h(n). Ignores g(n) which is the cost to get to n. Manhattan distance can be used as the heuristic distance in a grid. It is not complete nor optimal. ***A-star search*** expand most promising paths first. f(n) = g(n) + h(n). g(n) is the actual cost so far from the start to reach the node. h(n) is estimated cost to get from the node to the goal. f(n) is estimated total cost of path through n to goal. Frontier queue as increasing priority queue. Admissible heuristics - admissible if it never overestimates cost to reach the goal. *If h(n) is admissible, A-star using Tree Search is optimal* Admissible heuristics slow down bad plans but don't outwiegh true costs. It is not necessary to remove visited node from the frontier queue. Relaxed problem is a problem with less restricted actions than the original. The cost of an optimal solution to a relaxed problem is original problem's admissible heuristic. Dominance is a way of showing which heuristic is better. Better the heuristic, less nodes you ahve to visit. *Proving Optimality of A-star tree search*: Imagine b in frnotier, Some ancestor n of A in frontier too, Claim n will be expanded before B (f(n) is less or equal to f(A), f(A) is less than f(B), n expands before B), All ancestors of A expand before B, A expands before B, and A-star search is optimal. A-star algorithm is applied in routing problmes, video games, robot motion planning, etc.\n\n## Module 4 Definitions\n* **Concept** - definition\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n Game vs. Puzzle. Games have an opponent. *Simple game* is *multiagent, static, discrete, fully observable, and strategic*. Strategic: the next state is determined by the current and the action executed by the agent and the actions of one other agent. Zero-sum: one player's loss is another's gain. Game set up: *Min* and *Max* are two players where *Max* moves first. Utility function gives numerical value of terminal states. *Example*: *Hexapawn*. Game trees is a representation of the game problem space by a tree: nodes are 'board positions', edges are 'legal moves', and root node is the first position in which a decision must be made. f(n) is the evaluation function that evaluates how good a position is based on static features. Use zero-sum assumption to use one function to describe goodness for both players.f(n)>0 if MAX is winning, f(n)=0 if tied, f(n)<0 if MIN is winning. **Minimax algorithm**: Make the best move for MAX assuming the MIN always replies with the best move for MIN.Computed using a *recursive process*: The ***backed-up value*** for MAX node is the maximum of the values of its children, and for MIN node, it is the minimum of the values of its children. **Adversarial Search(Minimax)***: a state-space search tree, players alternate turns, compute each node's minimax value: the best achievable utility against an optimal adversary. ***Alpha-Beta Pruning*** alpha is MAX's current *lower* bound on MAX's outcome. beta is MIN's current *upper* bound on MIN's outcome. MAX will never allow a move that could lead to a worse score than alpha, and MIN will never allow a move that could lead to a better score(for MAX) than beta.\n\n**Expectimax**\n- used for games with uncertain outcome\n- We don't know what the expected result of an action is\n- Compute the average score under optimal play\n  - max nodes as in minimax search\n  - Chance nodes are like min nodes but the outcome is uncertain\n  - Calculate their expected utilities\n\n## Module 5 Definitions\n* **Static** - No change while an agent is deliberating\n* **Discrete** - A finite set percepts and actions\n* **Fully observable** - sensors give it the complete state of the environment\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n What is Search for?\n- Assumptions baout the world: a single agent, deterministic actions, fully observable state, discrete state space.\n- We do search to formulate a plan\n- Identification: assignments to variables\n\n**Constraint Satisfaction Problems**\n- *Specialized for Identification problems*\n- Big Idea:\n  - Represent the *constraints* that solutions must satisfy in a uniform   *declarative* language\n  - Find solutions using *general purpose* search algorithms\n  - Only formal specification of the CSP is needed\n- A CSP consists of:\n  - finite set of variables, nonempty domain of possible values,   finite set of constraints\n  - A *consistent* assignment does not violate the constraints\n- Ex: Sudoku\n- A *solution* is a *complete, consistent* assignment.\n  - *Complete* is when every variable is assigned a value\n- **Benefits of CSP**\n  - Clean specification of many problems, generic goal, successor function   and heuristics\n  - \"knows\" which variable violate a constraint\n  - Automatically prune off all branches that violate constraints\n\n- **Varieties of CSPs**\n  - *Discrete variables*\n    - finite domains: Boolean CSPs\n    - infinite domains: job scheduling\n  - *Continuous variables*\n    - linear constraints solvable in polynomial time by linear programming\n\n- **Varieties of constraints**\n  - ***Unary*** involve single variable\n  - ***Binary*** involve pairs of variables\n  - ***Higher-order*** involve 3 or more variables\n  - ***Preference***(soft constraints) e.g. red is better than green\n\n- **CSP as a search problem**\n  - *Initial State*: empty assignment {}\n  - *Successor function*: assign value to any unassigned variable provided that there is not a constraint conflict\n  - *Goal test*: the current assignment is complete\n  - *Path cost* : a constant cost for every step\n  - Solution is always found at depth n, for n variables\n\n- **Backtracking algorithm**\n  - DFS for CSPs with single-variable assignments\n  - Basic *uninformed* algorithm for CSPs\n  - DFS that chooses values for one variable at a timte and backtracks when   when a variable has no legal values left to assign.\n  - *ways to improve speed*\n    - Assign most constrained variable first then most contraining variable\n      - *minimum remaining values* heuristic\n    - Least constraining value of a variable should be tried first\n    - Detect inevitable failure early through forward checking\n\n- Inference **(Forward) checking** algorithm\n  - Keep track of *remaining* legal values for *unassigned* variables\n  - Terminate search when any unassigned variable has no remaining legal values\n  - Propagates infomration from *assigned* to *unassigned* variables,   but doesn't provide early detection for all failures\n\n- ***Inference*** **in CSPs**\n  - CSP solvers combine search and inference\n    - Search is assigning a value to a variable\n    - Inference (constraint propagation): eliminates possible values for a variable    if the value would violate local consistency\n\n-**Node consistency**\n  - satisfies unary constraints\n\n- **Arc Consistency**\n  - satisfies binary constraints\n  - Definition: An arc(i,j) is **arc consistent** if and only if every   value v on X_i is consistent with some label on Y_j\n  \n\n## Module 6 Definitions\n* **Concept** - definition\n\n\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n**Knowledge-Based Agents**\n- Use a process of **reasoning** over an internal **representation** of knowledge to decide what action to take\n- **Knowledge base(KB)** is a central component of a knowledge-based agent\n  - Contains a set of **sentence** that are written in a **knowledge representation language**\n  - KB is *false* in mnodels that contradict what the agent knows.\n\n-**Propositional Logic**\n  - **Atomic sentences** are represented with a single *propositional symbols*\n  - Propositional symbols stand for a statement that can be true or false\n  - **Complex sentences** are constructed from simpler ones using parentheses and *logical connectives*\n\n  \n\n## Module 7 Definitions\n* **Atomic** - definition\n* **Axioms** - a sentence that is given\n* **Derived sentences** - a new sentence that is derived from other sentences\n* **Model checking** - the process of enumerating all possible models that arecompatible with the KB\n* **Sound** - inference algorithm shoudl only derive entailed sentences\n* **Complete** - inference algorithm is complete if it can derive all sentences that are entailed\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "I_x1F21RAq-s"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}