{
  "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": "cdf11ce6-e076-4be5-ce11-193abbbb29d4"
      },
      "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": 31,
      "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": "45d58ec8-c5d4-41f8-f4da-d1b4bdc1fd58"
      },
      "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": 32,
      "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 = True"
      ],
      "execution_count": 33,
      "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 = r\"\"\" Rene Descartes: Principle of dualism – the mind or thinking self is essentially incorporeal or spiritual – that the mind exists separately from the body \\ The Turing test, computer passes the test if a human interrogator, after posing some written questions, cannot tell whether the written responses come from a person or from a computer. \"\"\" \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 = r\"\"\" An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.\n",
        "percept - A percept is the agent’s perceptual inputs at any given instance. agent = architecture + program \"\"\"\n",
        "chapter2_2 = \"\"\" For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, \\\n",
        "given the evidence provided by the percept sequence and whatever built-in knowledge the agent has. \n",
        "\"\"\"\n",
        "chapter2_3 = \"\"\" task environment: Performance, Environment, Actuators, Sensors \"\"\"\n",
        "chapter2_4 = \"\"\" A simple reflex agent is one that selects an action based on the current percept, and ignores the rest of the percept history \\ \n",
        "A problem-solving agent must plan ahead. It will consider a sequence of actions that form a path to a goal state. \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Your summary here \"\"\"\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 and act in an environment\",\n",
        "\"percept\" : \"your definitions here\",\n",
        "\"other concept\" : \"your definitions here\",\n",
        "\"etc.\": \"your definitions here\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": 34,
      "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": 810
        },
        "cellView": "form",
        "outputId": "5c65ee7f-2b07-4e79-ad04-f4abf75cd269"
      },
      "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": 35,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Rene Descartes: Principle of dualism – the mind or thinking self is essentially incorporeal or spiritual – that the mind exists separately from the body \\ The Turing test, computer passes the test if a human interrogator, after posing some written questions, cannot tell whether the written responses come from a person or from a computer. \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 An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.\npercept - A percept is the agent’s perceptual inputs at any given instance. agent = architecture + program \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence and whatever built-in knowledge the agent has. \n\n\n## AIMA 2.3 The Nature of Environments\n task environment: Performance, Environment, Actuators, Sensors \n\n## AIMA 2.4 The Structure of Agents\n A simple reflex agent is one that selects an action based on the current percept, and ignores the rest of the percept history \\ \nA problem-solving agent must plan ahead. It will consider a sequence of actions that form a path to a goal state. \n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - your definitions here\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\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 = \"\"\" All data treated as objects\n",
        "<br> **Strong Typing**: Every object has a fixed type, interpreter doesn’t allow things incompatible with that type (eg. “foo” + 2) \n",
        "<br> **dynamic typing**: Variables come into existence when first assigned\n",
        "<br> r’\\n’: raw\n",
        "<br> Tuple : A simple immutable ordered sequence of items, Immutable: a tuple cannot be modified once created, Items can be of mixed types, including collection types\n",
        "<br> Strings: Immutable Regular strings are Unicode and use 2-byte characters \n",
        "<br> List : Mutable ordered sequence of items of mixed types\n",
        "<br> Slicing: Return Copy of a Subsequence\n",
        "\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "\"String Formating\" : \"print(\\\"%s can speak %d languages\\\" % (\\\"C3PO\\\", 6000000))\"\n",
        "}"
      ],
      "execution_count": 36,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 345
        },
        "outputId": "5bbbf00f-f032-4a95-d709-c85296f47e62"
      },
      "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": 37,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n All data treated as objects\n<br> **Strong Typing**: Every object has a fixed type, interpreter doesn’t allow things incompatible with that type (eg. “foo” + 2) \n<br> **dynamic typing**: Variables come into existence when first assigned\n<br> r’\n’: raw\n<br> Tuple : A simple immutable ordered sequence of items, Immutable: a tuple cannot be modified once created, Items can be of mixed types, including collection types\n<br> Strings: Immutable Regular strings are Unicode and use 2-byte characters \n<br> List : Mutable ordered sequence of items of mixed types\n<br> Slicing: Return Copy of a Subsequence\n\n\n## Module 2 Definitions\n* **Mutability** - your definition here\n* **String formating** - print(\"%s can speak %d languages\" % (\"C3PO\", 6000000))\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 = \"\"\" **informed algorithms** : the agent can estimate how far it is from the goal, and uninformed algorithms, where no such estimate is available. <br>\n",
        "**search problem** : state space, initial state, goal states, actions, transition model, action cost function. A sequence of actions forms a path, and a solution is a path from the initial state to a goal state.<br>\n",
        "**optimal solution** has the lowest path cost among all solutions.\"\"\"\n",
        "chapter3_2 = \"\"\" A standardized problem is intended to illustrate or exercise various problem-solving methods. <br> \"\"\"\n",
        "chapter3_3 = \"\"\" **A search algorithm** takes a search problem as input and returns a solution, or an indication of failure. <br>\n",
        "**State space**: the set of all states reachable from the initial state by any sequence of actions <br>\n",
        "**Path**: a sequence of actions leading from one state s_j to another state s_k <br>\n",
        "**Solution**: a path from the initial state si to a state sf that satisfies the goal test <br>\n",
        "**Search tree**: a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states <br>\n",
        "**Frontier**: those states that are available for expanding <br>\"\"\"\n",
        "chapter3_4 = \"\"\"**Uninformed search**: All non-goal nodes in frontier look equally good; **Informed search**: Some non-goal nodes can be ranked above others <br>\n",
        "b: maximum branching factor of search tree , d: depth of the least cost solution, m: maximum depth of the state space (∞) <br>\n",
        "**BFS** : Expand shallowest unexpanded node, frontier is FIFO (First-In-First-Out) Queue. <br> Complete if b is finite, optimal if cost = 1 per step, time = O(b^d), space = O(b^d) <br>\n",
        "**DFS** : Expand deepest unexpanded node, frontier is LIFO (Last-In-First-Out) Queue. <br> not complete, not optimal, time = O(b^m), space = O(b * m) <br>\n",
        "Use depth-first if • Space is restricted • There are many possible solutions with long paths and wrong paths are usually terminated quickly • Search can be fine-tuned quickly <br>\n",
        "Use breadth-first if • Possible infinite paths • Some solutions have short paths • Can quickly discard unlikely paths <br>\n",
        "**Depth-limited search** : if l < d iincomplete, l > d not optimal, **iterative deepening search** : complete and optimal, time = O(b^d), space = O(bd)\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" Your summary here \"\"\"\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",
        "}\n",
        "\n"
      ],
      "execution_count": 38,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 763
        },
        "outputId": "0d4a14b0-fa4e-4167-ae18-e0a763e9a90b"
      },
      "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": 39,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n **informed algorithms** : the agent can estimate how far it is from the goal, and uninformed algorithms, where no such estimate is available. <br>\n**search problem** : state space, initial state, goal states, actions, transition model, action cost function. A sequence of actions forms a path, and a solution is a path from the initial state to a goal state.<br>\n**optimal solution** has the lowest path cost among all solutions.\n\n## AIMA Chapter 3.2 Example Problems\n A standardized problem is intended to illustrate or exercise various problem-solving methods. <br> \n\n## AIMA Chapter 3.3 Search Algorithms\n **A search algorithm** takes a search problem as input and returns a solution, or an indication of failure. <br>\n**State space**: the set of all states reachable from the initial state by any sequence of actions <br>\n**Path**: a sequence of actions leading from one state s_j to another state s_k <br>\n**Solution**: a path from the initial state si to a state sf that satisfies the goal test <br>\n**Search tree**: a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states <br>\n**Frontier**: those states that are available for expanding <br>\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n**Uninformed search**: All non-goal nodes in frontier look equally good; **Informed search**: Some non-goal nodes can be ranked above others <br>\nb: maximum branching factor of search tree , d: depth of the least cost solution, m: maximum depth of the state space (∞) <br>\n**BFS** : Expand shallowest unexpanded node, frontier is FIFO (First-In-First-Out) Queue. <br> Complete if b is finite, optimal if cost = 1 per step, time = O(b^d), space = O(b^d) <br>\n**DFS** : Expand deepest unexpanded node, frontier is LIFO (Last-In-First-Out) Queue. <br> not complete, not optimal, time = O(b^m), space = O(b * m) <br>\nUse depth-first if • Space is restricted • There are many possible solutions with long paths and wrong paths are usually terminated quickly • Search can be fine-tuned quickly <br>\nUse breadth-first if • Possible infinite paths • Some solutions have short paths • Can quickly discard unlikely paths <br>\n**Depth-limited search** : if l < d iincomplete, l > d not optimal, **iterative deepening search** : complete and optimal, time = O(b^d), space = O(bd)\n\n\n## Module 3 Lecture Notes\n Your summary here \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\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 = \"\"\"**Uniform Cost Search**: it expand mode with lowest path cost，frontier = priority queue ordered by g(n)<br>\n",
        "Tests if a node is a goal state when it is selected for expansion, not when it is added to the frontier. So always enqueues a node before checking whether it is a goal<br>\n",
        "**Greedy best-first search**: f(n) = h(n) expands first the node with the lowest h(n) value - the node that appears to be closest to the goal. **not optimal, not complete** <br>\n",
        "**A* search**: uses the evaluation function f(n) = g(n) + h(n) where g(n) is the path cost from the initial state to node n and h(n) is the estimated cost of the shortest path from n to a goal state. It is **complete** and **cost-optimal** if heuristic is admissible.<br>\n",
        "A heuristic h(n) is **admissible** if it never overestimates the cost to reach the goal; <br>\n",
        "A problem with fewer restrictions on the actions than the original is called a **relaxed problem**; The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem\n",
        "\"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" **admissible** : \"A heuristic h(n) is admissible if it never overestimates the cost to reach the goal. h(n) <=h*(n) where h*(n) is the true cost from n; h(n) >= 0.<br>\", \n",
        "<br>**inadmissible** : \"Inadmissible (pessimistic) heuristics break optimality by pushing good plans too far back on the frontier, which means they may never get expanded.\", \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"dominate\" : \"A* using h2 will never expand more nodes than A* using h1 if h2(n)>=h1(n) -> h2 dominates h1\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 40,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 511
        },
        "cellView": "form",
        "outputId": "4d203174-44dc-4823-d867-65ba1bfeac55"
      },
      "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": 41,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n**Uniform Cost Search**: it expand mode with lowest path cost，frontier = priority queue ordered by g(n)<br>\nTests if a node is a goal state when it is selected for expansion, not when it is added to the frontier. So always enqueues a node before checking whether it is a goal<br>\n**Greedy best-first search**: f(n) = h(n) expands first the node with the lowest h(n) value - the node that appears to be closest to the goal. **not optimal, not complete** <br>\n**A* search**: uses the evaluation function f(n) = g(n) + h(n) where g(n) is the path cost from the initial state to node n and h(n) is the estimated cost of the shortest path from n to a goal state. It is **complete** and **cost-optimal** if heuristic is admissible.<br>\nA heuristic h(n) is **admissible** if it never overestimates the cost to reach the goal; <br>\nA problem with fewer restrictions on the actions than the original is called a **relaxed problem**; The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem\n\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n **admissible** : \"A heuristic h(n) is admissible if it never overestimates the cost to reach the goal. h(n) <=h*(n) where h*(n) is the true cost from n; h(n) >= 0.<br>\", \n<br>**inadmissible** : \"Inadmissible (pessimistic) heuristics break optimality by pushing good plans too far back on the frontier, which means they may never get expanded.\", \n\n## Module 4 Definitions\n* **Dominate** - A* using h2 will never expand more nodes than A* using h1 if h2(n)>=h1(n) -> h2 dominates h1\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 = \"\"\" Game environment: **Multiagent**\n",
        "<br> **Static**: No change while an agent is deliberating.\n",
        "<br> **Discrete**: A finite set of percepts and actions.\n",
        "<br> **Fully observable**: An agent's sensors give it the complete state of the environment.\n",
        "<br> **Strategic**: The next state is determined by the current state and the action executed by the agent and the actions of one other agent. \"\"\"\n",
        "chapter5_2 = \"\"\" **Game Tree**: Represent the game problem space by a tree: Nodes represent ‘board positions’; edges represent legal moves. Root node is the first position in which a decision must be made.\n",
        "<br> **Evaluation function** f assigns real-number scores to `board positions’ without reference to path\n",
        "<br> **Terminal nodes** represent ways the game could end, labeled with the\n",
        "desirability of that ending (e.g. win/lose/draw or a numerical score)\"\"\"\n",
        "chapter5_3 = \"\"\" **minmax**: Make the best move for MAX assuming that MIN always replies with the best move for MIN \n",
        "<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n",
        "<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n",
        "```\n",
        "def max-value(state):\n",
        "  if the state is a terminal state:\n",
        "    return the state’s utility\n",
        "  initialize v = -∞\n",
        "  for each successor of state:\n",
        "    v = max(v, min-value(successor))\n",
        "  return v\n",
        "```\n",
        "\"\"\"\n",
        "chapter5_5 = \"\"\" **Alpha-Beta Pruning**: During Minimax, keep track of two additional values: α: MAX’s current lower bound on MAX’s outcome / MAX’s best already explored option on path to root\n",
        " β: MIN’s current upper bound on MIN’s outcome / MIN’s best already explored option on path to root\n",
        "<br>Therefore, stop evaluating a branch whenever:\n",
        "<br> When evaluating a MAX node: a value v ≥ β is backed-up\n",
        "• MIN will never select that MAX node\n",
        "<br>When evaluating a MIN node: a value v ≤ α is found\n",
        "• MAX will never select that MIN node\n",
        "<br> **Expectimax search**: compute the average score under optimal play\n",
        "```\n",
        "def value(state):\n",
        "  if the state is a terminal state: return the state’s utility\n",
        "  if the next agent is MAX: return max-value(state)\n",
        "  if the next agent is EXP: return exp-value(state)\n",
        "\n",
        "def max-value(state):\n",
        "  initialize v = -∞\n",
        "  for each successor of state:\n",
        "    v = max(v, value(successor))\n",
        "  return v\n",
        "\n",
        "def exp-value(state):\n",
        "  initialize v = 0\n",
        "  for each successor of state:\n",
        "    p = probability(successor)\n",
        "    v += p * value(successor)\n",
        "  return v\n",
        "```\n",
        "A **random variable** represents an event whose outcome is unknown\n",
        "\"\"\"\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 = \"\"\" minimax: O(b^m), alpha-beta pruning with optimal order: O(b^(m/2)), worst order: O(b^m) \n",
        "<br> Heuristic alpha-beta search replaces the utility function with an evaluation function (estimates the value of non-terminal nodes)\n",
        "<br> In heuristic alpha-beta pruning, the terminal test is replaced with a cutoff test\n",
        "<br> The evaluation function should be applied only to positions that are quiescent (there is no pending move that would wildly swing the valuation)\n",
        "<br> The horizon effect is when an agent try to erroneously delay the inevitable\n",
        "<br> forward pruning prunes moves that appear to be bad moves (beam search)\n",
        "<br> MCTS evaluate an action by repeatedly play the game from that state and take the average of the results\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"Type A Strategy\" : \"proposed by Claude Shannon, explores a wide but shallow portion of the tree\",  \n",
        "\"Type B Strategy\" : \"explores a deep but narrow portion of the tree\",  \n",
        "\"MCTS\" : \"Monte Carlo tree search, playing the game to the end while randomly selecting moves\",\n",
        "\"Expectiminimax\" : \"Expectiminimax uses expected value at chance nodes\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": 42,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "25d1fa27-637c-4056-cdb8-704ab808363b"
      },
      "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": 43,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Game environment: **Multiagent**\n<br> **Static**: No change while an agent is deliberating.\n<br> **Discrete**: A finite set of percepts and actions.\n<br> **Fully observable**: An agent's sensors give it the complete state of the environment.\n<br> **Strategic**: The next state is determined by the current state and the action executed by the agent and the actions of one other agent. \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n **Game Tree**: Represent the game problem space by a tree: Nodes represent ‘board positions’; edges represent legal moves. Root node is the first position in which a decision must be made.\n<br> **Evaluation function** f assigns real-number scores to `board positions’ without reference to path\n<br> **Terminal nodes** represent ways the game could end, labeled with the\ndesirability of that ending (e.g. win/lose/draw or a numerical score)\n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n **minmax**: Make the best move for MAX assuming that MIN always replies with the best move for MIN \n<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n```\ndef max-value(state):\n  if the state is a terminal state:\n    return the state’s utility\n  initialize v = -∞\n  for each successor of state:\n    v = max(v, min-value(successor))\n  return v\n```\n\n\n## AIMA Chapter 5.5 Stochastic Games\n **Alpha-Beta Pruning**: During Minimax, keep track of two additional values: α: MAX’s current lower bound on MAX’s outcome / MAX’s best already explored option on path to root\n β: MIN’s current upper bound on MIN’s outcome / MIN’s best already explored option on path to root\n<br>Therefore, stop evaluating a branch whenever:\n<br> When evaluating a MAX node: a value v ≥ β is backed-up\n• MIN will never select that MAX node\n<br>When evaluating a MIN node: a value v ≤ α is found\n• MAX will never select that MIN node\n<br> **Expectimax search**: compute the average score under optimal play\n```\ndef value(state):\n  if the state is a terminal state: return the state’s utility\n  if the next agent is MAX: return max-value(state)\n  if the next agent is EXP: return exp-value(state)\n\ndef max-value(state):\n  initialize v = -∞\n  for each successor of state:\n    v = max(v, value(successor))\n  return v\n\ndef exp-value(state):\n  initialize v = 0\n  for each successor of state:\n    p = probability(successor)\n    v += p * value(successor)\n  return v\n```\nA **random variable** represents an event whose outcome is unknown\n\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 minimax: O(b^m), alpha-beta pruning with optimal order: O(b^(m/2)), worst order: O(b^m) \n<br> Heuristic alpha-beta search replaces the utility function with an evaluation function (estimates the value of non-terminal nodes)\n<br> In heuristic alpha-beta pruning, the terminal test is replaced with a cutoff test\n<br> The evaluation function should be applied only to positions that are quiescent (there is no pending move that would wildly swing the valuation)\n<br> The horizon effect is when an agent try to erroneously delay the inevitable\n<br> forward pruning prunes moves that appear to be bad moves (beam search)\n<br> MCTS evaluate an action by repeatedly play the game from that state and take the average of the results\n\n## Module 5 Definitions\n* **Type a strategy** - proposed by Claude Shannon, explores a wide but shallow portion of the tree\n* **Type b strategy** - explores a deep but narrow portion of the tree\n* **Mcts** - Monte Carlo tree search, playing the game to the end while randomly selecting moves\n* **Expectiminimax** - Expectiminimax uses expected value at chance nodes\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 = \"\"\" Represent the constraints that solutions must satisfy in a uniform declarative language. Find solutions by GENERAL PURPOSE search algorithms with no changes from problem to problem \n",
        "<br> A CSP consists of: 1.Finite set of variables, 2.Nonempty domain of possible values for each variable, 3.Finite set of constraints\n",
        "<br> A **consistent** assignment does not violate the constraints.\n",
        "<br> An assignment is **complete** when every variable is assigned a value.\n",
        "<br> A solution to a CSP is a complete, consistent assignment.\n",
        "<br> Higher-order constraints involve 3 or more variables\"\"\"\n",
        "chapter6_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_3 = \"\"\" Depth-first search for CSPs with single-variable assignments is called **backtracking** (uninformed) search\n",
        "<br> General-purpose methods & general-purpose heuristics can give huge gains in speed, on average: Most constrained variable (minimum remaining values (MRV))\"\"\"\n",
        "chapter6_4 = \"\"\" Constraint propagation (inference): Eliminates possible values for a variable if the value would violate local consistency \n",
        "<br> X-Y is consistent iff for every value x of X there is some allowed y\n",
        "<br> **Arc Consistency**: 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, given d values: time to check = O(d^2)\n",
        ".\"\"\"\n",
        "chapter6_5 = \"\"\" **ac3**: \n",
        "<br> 1.At each iteration, we only need to examine those Xi where at least one neighbor of Xi has lost a value in the previous iteration.\n",
        "<br>2. If Xi loses a value only because of arc inconsistencies with Yj, we don’t need to check Yj on the next iteration.\n",
        "<br>3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only need to check that (j,i) is still arc-consistent.\n",
        "<br> time: If there are d values, n^2 arcs, checking arc (i,j) takes O(d2 ) time, Each arc (i,j) can only be inserted into the queue d times, Worst case complexity: O(n^2d^3)\n",
        "<br> CSPs can rule out variable assignments using **search** and **inference**\n",
        "<br> A CSP is k-consistent if, for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable\n",
        "<br> Constraint learning records the conflicts as they are encountered in the search in order to avoid the same conflict later\n",
        "<br> Cutset conditioning is used to reduce a general CSP to a tree structured one (exponential -> linear time). Cutset conditioning is efficient if a small cutset can be found.\n",
        "<br> Tree decomposition techniques transform the CSP into a tree of subproblems. efficient if the tree width of the constraint graph is small.\n",
        "<br> Whenever you have a cycle-cutset of size c, there is also a tree of width w<c+1, and it may be far smaller in some cases. Cutset conditioning can be executed in linear memory, while tree decomposition requries memory exponential in the tree width w,\n",
        "<br> MAC is a way of interleaving search and inference. AC-3 is pure inference.\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\" Tree decomposition. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "\"Node consistency\" : \"k-consistency for k=1\",\n",
        "\"Arc consistency\" : \"k = 2\",\n",
        "\"Path consistency\" : \"k = 3\",\n",
        "\"Stringly k-consistent\" : \"if a CSP is k-consistent, k-1-consistent, ..., 1-consistent\",\n",
        "\"MRV heuristic\" : \"stands for Minimum Remaining Value, chooses the variable with the fewest 'legal' values\",\n",
        "\"degree heuristic\" : \"chooses the variable with the largest number of constraints\",\n",
        "\"least constraining value heuristic\" : \"chooses the value that rules out the fewest values for neighboring variables\",\n",
        "\"MAC\" : \"Maintaing Arc Consistency, MAC recursively propogrates constraints, whereas forward checking does not.\"\n",
        "}\n"
      ],
      "execution_count": 44,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "a355da00-c3b9-4c57-ca04-fdb6b670c7f4"
      },
      "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": 45,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Represent the constraints that solutions must satisfy in a uniform declarative language. Find solutions by GENERAL PURPOSE search algorithms with no changes from problem to problem \n<br> A CSP consists of: 1.Finite set of variables, 2.Nonempty domain of possible values for each variable, 3.Finite set of constraints\n<br> A **consistent** assignment does not violate the constraints.\n<br> An assignment is **complete** when every variable is assigned a value.\n<br> A solution to a CSP is a complete, consistent assignment.\n<br> Higher-order constraints involve 3 or more variables\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 Depth-first search for CSPs with single-variable assignments is called **backtracking** (uninformed) search\n<br> General-purpose methods & general-purpose heuristics can give huge gains in speed, on average: Most constrained variable (minimum remaining values (MRV))\n\n## AIMA Chapter 6.4 Local Search for CSPs\n Constraint propagation (inference): Eliminates possible values for a variable if the value would violate local consistency \n<br> X-Y is consistent iff for every value x of X there is some allowed y\n<br> **Arc Consistency**: 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, given d values: time to check = O(d^2)\n.\n\n## AIMA Chapter 6.5 The Structure of Problems\n **ac3**: \n<br> 1.At each iteration, we only need to examine those Xi where at least one neighbor of Xi has lost a value in the previous iteration.\n<br>2. If Xi loses a value only because of arc inconsistencies with Yj, we don’t need to check Yj on the next iteration.\n<br>3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only need to check that (j,i) is still arc-consistent.\n<br> time: If there are d values, n^2 arcs, checking arc (i,j) takes O(d2 ) time, Each arc (i,j) can only be inserted into the queue d times, Worst case complexity: O(n^2d^3)\n<br> CSPs can rule out variable assignments using **search** and **inference**\n<br> A CSP is k-consistent if, for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable\n<br> Constraint learning records the conflicts as they are encountered in the search in order to avoid the same conflict later\n<br> Cutset conditioning is used to reduce a general CSP to a tree structured one (exponential -> linear time). Cutset conditioning is efficient if a small cutset can be found.\n<br> Tree decomposition techniques transform the CSP into a tree of subproblems. efficient if the tree width of the constraint graph is small.\n<br> Whenever you have a cycle-cutset of size c, there is also a tree of width w<c+1, and it may be far smaller in some cases. Cutset conditioning can be executed in linear memory, while tree decomposition requries memory exponential in the tree width w,\n<br> MAC is a way of interleaving search and inference. AC-3 is pure inference.\n\n\n## Module 6 Lecture Notes\n Tree decomposition. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. \n\n## Module 6 Definitions\n* **Concept** - definition\n* **Node consistency** - k-consistency for k=1\n* **Arc consistency** - k = 2\n* **Path consistency** - k = 3\n* **Stringly k-consistent** - if a CSP is k-consistent, k-1-consistent, ..., 1-consistent\n* **Mrv heuristic** - stands for Minimum Remaining Value, chooses the variable with the fewest 'legal' values\n* **Degree heuristic** - chooses the variable with the largest number of constraints\n* **Least constraining value heuristic** - chooses the value that rules out the fewest values for neighboring variables\n* **Mac** - Maintaing Arc Consistency, MAC recursively propogrates constraints, whereas forward checking does not.\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 = \"\"\" (α ⋀ β) ≡ (β ⋀ α) Commutativity of ⋀\n",
        "<br> (α ⋁ β) ≡ (β ⋁ α) Commutativity of ⋁\n",
        "<br> ((α ⋀ β) ⋀ ɣ) ≡ (α ⋀ (β ⋀ ɣ)) Associativity of ⋀\n",
        "<br> ((α ⋁ β) ⋁ ɣ) ≡ (α ⋁ (β ⋁ ɣ)) Associativity of ⋁\n",
        "<br> ¬ (¬ α) ≡ α Double-negation elimination\n",
        "<br> (α ⟹ β) ≡ (¬β ⟹ ¬α) Contraposition\n",
        "<br> (α ⟹ β) ≡ (¬α ⋁ β) Implication elimination\n",
        "<br> (α ⇔ β) ≡ ((α ⟹ β) ⋀ (β ⟹α)) Biconditional elimination\n",
        "<br> ¬(α ⋀ β) ≡ (¬α ⋁ ¬β) De Morgan\n",
        "<br> ¬(α ⋁ β) ≡ (¬α ⋀ ¬β) De Morgan\n",
        "<br> ((α ⋀ β) ⋁ ɣ) ≡ ((α ⋀ β) ⋁ (α ⋀ ɣ))) Distributivity of ⋀ over ⋁\n",
        "<br> ((α ⋁ β) ⋀ ɣ) ≡ ((α ⋁ β) ⋀ (α ⋁ ɣ))) Distributivity of ⋁ over ⋀ \n",
        ">\n",
        "<br> Two sentences α and β are logically equivalent if they are true in the same set of models. (α ≡ β)\n",
        "<br> two sentences α and β are logically equivalent if any only if they entail each other. (α ≡ β if and only if α⊨β and β⊨α.)\n",
        "<br> **Monotonicity**: if KB⊨α then KB ⋀ β ⊨α We can safely add to the KB, without invalidating anything else that we inferred. \n",
        "<br> If l_i and m are complementary literals, which means that one is the negation of another, then we can eliminate them via **unit resolution**.\n",
        "<br> **CNF**: Every sentence of propositional logic is logically equivalent to a conjunction of clauses. Clauses are disjunctions of literals.\n",
        "<br> The resolution algorithm is **complete**.\n",
        "<br> Backward chaining(goal-directed) works backwards from a query. If query = true, then stop. Otherwise, the algorithm finds implications in the KB whose conclusions is the query. If all the premises of one of those can be proved to be true (via backward chaining), then the query is true. \n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",   \n",
        "\"Definite clause\" : \"disjunction of literals where exactly one is positive\",\n",
        "\"Horn clause\" : \"disjunction of literals where at most one is positive\" ,\n",
        "\"Forward Chaining(data-driven)\" : \" start with known data, adding premises as new percepts come in, and then incrementally derive new conclusions. no query\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 946
        },
        "outputId": "bd48b70b-9e89-4aef-e215-b4ab52e7f2ed"
      },
      "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": 47,
      "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 (α ⋀ β) ≡ (β ⋀ α) Commutativity of ⋀\n<br> (α ⋁ β) ≡ (β ⋁ α) Commutativity of ⋁\n<br> ((α ⋀ β) ⋀ ɣ) ≡ (α ⋀ (β ⋀ ɣ)) Associativity of ⋀\n<br> ((α ⋁ β) ⋁ ɣ) ≡ (α ⋁ (β ⋁ ɣ)) Associativity of ⋁\n<br> ¬ (¬ α) ≡ α Double-negation elimination\n<br> (α ⟹ β) ≡ (¬β ⟹ ¬α) Contraposition\n<br> (α ⟹ β) ≡ (¬α ⋁ β) Implication elimination\n<br> (α ⇔ β) ≡ ((α ⟹ β) ⋀ (β ⟹α)) Biconditional elimination\n<br> ¬(α ⋀ β) ≡ (¬α ⋁ ¬β) De Morgan\n<br> ¬(α ⋁ β) ≡ (¬α ⋀ ¬β) De Morgan\n<br> ((α ⋀ β) ⋁ ɣ) ≡ ((α ⋀ β) ⋁ (α ⋀ ɣ))) Distributivity of ⋀ over ⋁\n<br> ((α ⋁ β) ⋀ ɣ) ≡ ((α ⋁ β) ⋀ (α ⋁ ɣ))) Distributivity of ⋁ over ⋀ \n>\n<br> Two sentences α and β are logically equivalent if they are true in the same set of models. (α ≡ β)\n<br> two sentences α and β are logically equivalent if any only if they entail each other. (α ≡ β if and only if α⊨β and β⊨α.)\n<br> **Monotonicity**: if KB⊨α then KB ⋀ β ⊨α We can safely add to the KB, without invalidating anything else that we inferred. \n<br> If l_i and m are complementary literals, which means that one is the negation of another, then we can eliminate them via **unit resolution**.\n<br> **CNF**: Every sentence of propositional logic is logically equivalent to a conjunction of clauses. Clauses are disjunctions of literals.\n<br> The resolution algorithm is **complete**.\n<br> Backward chaining(goal-directed) works backwards from a query. If query = true, then stop. Otherwise, the algorithm finds implications in the KB whose conclusions is the query. If all the premises of one of those can be proved to be true (via backward chaining), then the query is true. \n\n\n## Module 7 Definitions\n* **Concept** - definition\n* **Definite clause** - disjunction of literals where exactly one is positive\n* **Horn clause** - disjunction of literals where at most one is positive\n* **Forward chaining(data-driven)** -  start with known data, adding premises as new percepts come in, and then incrementally derive new conclusions. no query\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": "8b23962f-134b-44e6-839c-0a8b1d53a9cf"
      },
      "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": 48,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Rene Descartes: Principle of dualism – the mind or thinking self is essentially incorporeal or spiritual – that the mind exists separately from the body \\ The Turing test, computer passes the test if a human interrogator, after posing some written questions, cannot tell whether the written responses come from a person or from a computer. \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 An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.\npercept - A percept is the agent’s perceptual inputs at any given instance. agent = architecture + program \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence and whatever built-in knowledge the agent has. \n\n\n## AIMA 2.3 The Nature of Environments\n task environment: Performance, Environment, Actuators, Sensors \n\n## AIMA 2.4 The Structure of Agents\n A simple reflex agent is one that selects an action based on the current percept, and ignores the rest of the percept history \\ \nA problem-solving agent must plan ahead. It will consider a sequence of actions that form a path to a goal state. \n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - your definitions here\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n All data treated as objects\n<br> **Strong Typing**: Every object has a fixed type, interpreter doesn’t allow things incompatible with that type (eg. “foo” + 2) \n<br> **dynamic typing**: Variables come into existence when first assigned\n<br> r’\n’: raw\n<br> Tuple : A simple immutable ordered sequence of items, Immutable: a tuple cannot be modified once created, Items can be of mixed types, including collection types\n<br> Strings: Immutable Regular strings are Unicode and use 2-byte characters \n<br> List : Mutable ordered sequence of items of mixed types\n<br> Slicing: Return Copy of a Subsequence\n\n\n## Module 2 Definitions\n* **Mutability** - your definition here\n* **String formating** - print(\"%s can speak %d languages\" % (\"C3PO\", 6000000))\n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n **informed algorithms** : the agent can estimate how far it is from the goal, and uninformed algorithms, where no such estimate is available. <br>\n**search problem** : state space, initial state, goal states, actions, transition model, action cost function. A sequence of actions forms a path, and a solution is a path from the initial state to a goal state.<br>\n**optimal solution** has the lowest path cost among all solutions.\n\n## AIMA Chapter 3.2 Example Problems\n A standardized problem is intended to illustrate or exercise various problem-solving methods. <br> \n\n## AIMA Chapter 3.3 Search Algorithms\n **A search algorithm** takes a search problem as input and returns a solution, or an indication of failure. <br>\n**State space**: the set of all states reachable from the initial state by any sequence of actions <br>\n**Path**: a sequence of actions leading from one state s_j to another state s_k <br>\n**Solution**: a path from the initial state si to a state sf that satisfies the goal test <br>\n**Search tree**: a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states <br>\n**Frontier**: those states that are available for expanding <br>\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n**Uninformed search**: All non-goal nodes in frontier look equally good; **Informed search**: Some non-goal nodes can be ranked above others <br>\nb: maximum branching factor of search tree , d: depth of the least cost solution, m: maximum depth of the state space (∞) <br>\n**BFS** : Expand shallowest unexpanded node, frontier is FIFO (First-In-First-Out) Queue. <br> Complete if b is finite, optimal if cost = 1 per step, time = O(b^d), space = O(b^d) <br>\n**DFS** : Expand deepest unexpanded node, frontier is LIFO (Last-In-First-Out) Queue. <br> not complete, not optimal, time = O(b^m), space = O(b * m) <br>\nUse depth-first if • Space is restricted • There are many possible solutions with long paths and wrong paths are usually terminated quickly • Search can be fine-tuned quickly <br>\nUse breadth-first if • Possible infinite paths • Some solutions have short paths • Can quickly discard unlikely paths <br>\n**Depth-limited search** : if l < d iincomplete, l > d not optimal, **iterative deepening search** : complete and optimal, time = O(b^d), space = O(bd)\n\n\n## Module 3 Lecture Notes\n Your summary here \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n**Uniform Cost Search**: it expand mode with lowest path cost，frontier = priority queue ordered by g(n)<br>\nTests if a node is a goal state when it is selected for expansion, not when it is added to the frontier. So always enqueues a node before checking whether it is a goal<br>\n**Greedy best-first search**: f(n) = h(n) expands first the node with the lowest h(n) value - the node that appears to be closest to the goal. **not optimal, not complete** <br>\n**A* search**: uses the evaluation function f(n) = g(n) + h(n) where g(n) is the path cost from the initial state to node n and h(n) is the estimated cost of the shortest path from n to a goal state. It is **complete** and **cost-optimal** if heuristic is admissible.<br>\nA heuristic h(n) is **admissible** if it never overestimates the cost to reach the goal; <br>\nA problem with fewer restrictions on the actions than the original is called a **relaxed problem**; The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem\n\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n **admissible** : \"A heuristic h(n) is admissible if it never overestimates the cost to reach the goal. h(n) <=h*(n) where h*(n) is the true cost from n; h(n) >= 0.<br>\", \n<br>**inadmissible** : \"Inadmissible (pessimistic) heuristics break optimality by pushing good plans too far back on the frontier, which means they may never get expanded.\", \n\n## Module 4 Definitions\n* **Dominate** - A* using h2 will never expand more nodes than A* using h1 if h2(n)>=h1(n) -> h2 dominates h1\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Game environment: **Multiagent**\n<br> **Static**: No change while an agent is deliberating.\n<br> **Discrete**: A finite set of percepts and actions.\n<br> **Fully observable**: An agent's sensors give it the complete state of the environment.\n<br> **Strategic**: The next state is determined by the current state and the action executed by the agent and the actions of one other agent. \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n **Game Tree**: Represent the game problem space by a tree: Nodes represent ‘board positions’; edges represent legal moves. Root node is the first position in which a decision must be made.\n<br> **Evaluation function** f assigns real-number scores to `board positions’ without reference to path\n<br> **Terminal nodes** represent ways the game could end, labeled with the\ndesirability of that ending (e.g. win/lose/draw or a numerical score)\n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n **minmax**: Make the best move for MAX assuming that MIN always replies with the best move for MIN \n<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n<br> For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX)\n```\ndef max-value(state):\n  if the state is a terminal state:\n    return the state’s utility\n  initialize v = -∞\n  for each successor of state:\n    v = max(v, min-value(successor))\n  return v\n```\n\n\n## AIMA Chapter 5.5 Stochastic Games\n **Alpha-Beta Pruning**: During Minimax, keep track of two additional values: α: MAX’s current lower bound on MAX’s outcome / MAX’s best already explored option on path to root\n β: MIN’s current upper bound on MIN’s outcome / MIN’s best already explored option on path to root\n<br>Therefore, stop evaluating a branch whenever:\n<br> When evaluating a MAX node: a value v ≥ β is backed-up\n• MIN will never select that MAX node\n<br>When evaluating a MIN node: a value v ≤ α is found\n• MAX will never select that MIN node\n<br> **Expectimax search**: compute the average score under optimal play\n```\ndef value(state):\n  if the state is a terminal state: return the state’s utility\n  if the next agent is MAX: return max-value(state)\n  if the next agent is EXP: return exp-value(state)\n\ndef max-value(state):\n  initialize v = -∞\n  for each successor of state:\n    v = max(v, value(successor))\n  return v\n\ndef exp-value(state):\n  initialize v = 0\n  for each successor of state:\n    p = probability(successor)\n    v += p * value(successor)\n  return v\n```\nA **random variable** represents an event whose outcome is unknown\n\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 minimax: O(b^m), alpha-beta pruning with optimal order: O(b^(m/2)), worst order: O(b^m) \n<br> Heuristic alpha-beta search replaces the utility function with an evaluation function (estimates the value of non-terminal nodes)\n<br> In heuristic alpha-beta pruning, the terminal test is replaced with a cutoff test\n<br> The evaluation function should be applied only to positions that are quiescent (there is no pending move that would wildly swing the valuation)\n<br> The horizon effect is when an agent try to erroneously delay the inevitable\n<br> forward pruning prunes moves that appear to be bad moves (beam search)\n<br> MCTS evaluate an action by repeatedly play the game from that state and take the average of the results\n\n## Module 5 Definitions\n* **Type a strategy** - proposed by Claude Shannon, explores a wide but shallow portion of the tree\n* **Type b strategy** - explores a deep but narrow portion of the tree\n* **Mcts** - Monte Carlo tree search, playing the game to the end while randomly selecting moves\n* **Expectiminimax** - Expectiminimax uses expected value at chance nodes\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Represent the constraints that solutions must satisfy in a uniform declarative language. Find solutions by GENERAL PURPOSE search algorithms with no changes from problem to problem \n<br> A CSP consists of: 1.Finite set of variables, 2.Nonempty domain of possible values for each variable, 3.Finite set of constraints\n<br> A **consistent** assignment does not violate the constraints.\n<br> An assignment is **complete** when every variable is assigned a value.\n<br> A solution to a CSP is a complete, consistent assignment.\n<br> Higher-order constraints involve 3 or more variables\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 Depth-first search for CSPs with single-variable assignments is called **backtracking** (uninformed) search\n<br> General-purpose methods & general-purpose heuristics can give huge gains in speed, on average: Most constrained variable (minimum remaining values (MRV))\n\n## AIMA Chapter 6.4 Local Search for CSPs\n Constraint propagation (inference): Eliminates possible values for a variable if the value would violate local consistency \n<br> X-Y is consistent iff for every value x of X there is some allowed y\n<br> **Arc Consistency**: 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, given d values: time to check = O(d^2)\n.\n\n## AIMA Chapter 6.5 The Structure of Problems\n **ac3**: \n<br> 1.At each iteration, we only need to examine those Xi where at least one neighbor of Xi has lost a value in the previous iteration.\n<br>2. If Xi loses a value only because of arc inconsistencies with Yj, we don’t need to check Yj on the next iteration.\n<br>3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only need to check that (j,i) is still arc-consistent.\n<br> time: If there are d values, n^2 arcs, checking arc (i,j) takes O(d2 ) time, Each arc (i,j) can only be inserted into the queue d times, Worst case complexity: O(n^2d^3)\n<br> CSPs can rule out variable assignments using **search** and **inference**\n<br> A CSP is k-consistent if, for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable\n<br> Constraint learning records the conflicts as they are encountered in the search in order to avoid the same conflict later\n<br> Cutset conditioning is used to reduce a general CSP to a tree structured one (exponential -> linear time). Cutset conditioning is efficient if a small cutset can be found.\n<br> Tree decomposition techniques transform the CSP into a tree of subproblems. efficient if the tree width of the constraint graph is small.\n<br> Whenever you have a cycle-cutset of size c, there is also a tree of width w<c+1, and it may be far smaller in some cases. Cutset conditioning can be executed in linear memory, while tree decomposition requries memory exponential in the tree width w,\n<br> MAC is a way of interleaving search and inference. AC-3 is pure inference.\n\n\n## Module 6 Lecture Notes\n Tree decomposition. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. \n\n## Module 6 Definitions\n* **Concept** - definition\n* **Node consistency** - k-consistency for k=1\n* **Arc consistency** - k = 2\n* **Path consistency** - k = 3\n* **Stringly k-consistent** - if a CSP is k-consistent, k-1-consistent, ..., 1-consistent\n* **Mrv heuristic** - stands for Minimum Remaining Value, chooses the variable with the fewest 'legal' values\n* **Degree heuristic** - chooses the variable with the largest number of constraints\n* **Least constraining value heuristic** - chooses the value that rules out the fewest values for neighboring variables\n* **Mac** - Maintaing Arc Consistency, MAC recursively propogrates constraints, whereas forward checking does not.\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 (α ⋀ β) ≡ (β ⋀ α) Commutativity of ⋀\n<br> (α ⋁ β) ≡ (β ⋁ α) Commutativity of ⋁\n<br> ((α ⋀ β) ⋀ ɣ) ≡ (α ⋀ (β ⋀ ɣ)) Associativity of ⋀\n<br> ((α ⋁ β) ⋁ ɣ) ≡ (α ⋁ (β ⋁ ɣ)) Associativity of ⋁\n<br> ¬ (¬ α) ≡ α Double-negation elimination\n<br> (α ⟹ β) ≡ (¬β ⟹ ¬α) Contraposition\n<br> (α ⟹ β) ≡ (¬α ⋁ β) Implication elimination\n<br> (α ⇔ β) ≡ ((α ⟹ β) ⋀ (β ⟹α)) Biconditional elimination\n<br> ¬(α ⋀ β) ≡ (¬α ⋁ ¬β) De Morgan\n<br> ¬(α ⋁ β) ≡ (¬α ⋀ ¬β) De Morgan\n<br> ((α ⋀ β) ⋁ ɣ) ≡ ((α ⋀ β) ⋁ (α ⋀ ɣ))) Distributivity of ⋀ over ⋁\n<br> ((α ⋁ β) ⋀ ɣ) ≡ ((α ⋁ β) ⋀ (α ⋁ ɣ))) Distributivity of ⋁ over ⋀ \n>\n<br> Two sentences α and β are logically equivalent if they are true in the same set of models. (α ≡ β)\n<br> two sentences α and β are logically equivalent if any only if they entail each other. (α ≡ β if and only if α⊨β and β⊨α.)\n<br> **Monotonicity**: if KB⊨α then KB ⋀ β ⊨α We can safely add to the KB, without invalidating anything else that we inferred. \n<br> If l_i and m are complementary literals, which means that one is the negation of another, then we can eliminate them via **unit resolution**.\n<br> **CNF**: Every sentence of propositional logic is logically equivalent to a conjunction of clauses. Clauses are disjunctions of literals.\n<br> The resolution algorithm is **complete**.\n<br> Backward chaining(goal-directed) works backwards from a query. If query = true, then stop. Otherwise, the algorithm finds implications in the KB whose conclusions is the query. If all the premises of one of those can be proved to be true (via backward chaining), then the query is true. \n\n\n## Module 7 Definitions\n* **Concept** - definition\n* **Definite clause** - disjunction of literals where exactly one is positive\n* **Horn clause** - disjunction of literals where at most one is positive\n* **Forward chaining(data-driven)** -  start with known data, adding premises as new percepts come in, and then incrementally derive new conclusions. no query\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}