{
  "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": "08c38326-51c1-4a80-da51-1f0c900e1590"
      },
      "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": 184,
      "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": "35308cbf-218a-4e25-ce12-240f5ed3a7fa"
      },
      "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": 185,
      "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": 186,
      "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 = \"\"\" Performance measures should measure what you want achieved in the environment rather than how agent should behave. \"\"\"\n",
        "chapter2_2 = \"\"\" PEAS: specify task environment (performance measure, environment, actautors, sensors) \"\"\"\n",
        "chapter2_3 = \"\"\" Hardest environment is continuous, partially observable, stochastic, multiagent\"\"\"\n",
        "chapter2_4 = \"\"\" Problem solving agent plans ahead and considers sequence of actions that from path to goal state (search) \"\"\"\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\" : \"What the sensors perceive\",\n",
        "\"percept history\" : \"complete history of everything agent has ever perceived\",\n",
        "\"agent function\" : \"maps any given percept sequence to an action (ie. if square is dirty -> clean, if not -> move)\",\n",
        "\"agent program\": \"implements the agent function (concrete implementation running within some physical system)\",\n",
        "\"fully observable\": \"sensors show entire state of environment\",\n",
        "\"deterministic\": \"next state is completely determined by current state\",\n",
        "\"stochastic\": \"environment deals with probabilities (ie. 25% chance of rain tomorrow)\",\n",
        "\"non-deterministic\": \"ie. there's a chance it's gonna rain tomorrow\",\n",
        "\"episodic\": \"agent receives precept and then performs a single action\",\n",
        "\"sequential\": \"current decision could affect all future ones (taxi driver, chess)\",\n",
        "\"dynamic\": \"environment can change while agent is deliberating\",\n",
        "\"simple reflex agent\": \"act based on current percept\",\n",
        "\"model-based agent\": \"uses transition (how world works) and sensor (how world's  reflected in percept) models to keep track of world\",\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 187,
      "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": 912
        },
        "cellView": "form",
        "outputId": "7154edb5-a754-40bb-cd0e-6ac42da489f6"
      },
      "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": 188,
      "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 Performance measures should measure what you want achieved in the environment rather than how agent should behave. \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n PEAS: specify task environment (performance measure, environment, actautors, sensors) \n\n## AIMA 2.3 The Nature of Environments\n Hardest environment is continuous, partially observable, stochastic, multiagent\n\n## AIMA 2.4 The Structure of Agents\n Problem solving agent plans ahead and considers sequence of actions that from path to goal state (search) \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** - What the sensors perceive\n* **Percept history** - complete history of everything agent has ever perceived\n* **Agent function** - maps any given percept sequence to an action (ie. if square is dirty -> clean, if not -> move)\n* **Agent program** - implements the agent function (concrete implementation running within some physical system)\n* **Fully observable** - sensors show entire state of environment\n* **Deterministic** - next state is completely determined by current state\n* **Stochastic** - environment deals with probabilities (ie. 25% chance of rain tomorrow)\n* **Non-deterministic** - ie. there's a chance it's gonna rain tomorrow\n* **Episodic** - agent receives precept and then performs a single action\n* **Sequential** - current decision could affect all future ones (taxi driver, chess)\n* **Dynamic** - environment can change while agent is deliberating\n* **Simple reflex agent** - act based on current percept\n* **Model-based agent** - uses transition (how world works) and sensor (how world's  reflected in percept) models to keep track of world\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 = \"\"\" List comprehension: ```[i for i in range(0, 100)] ```.\n",
        "\n",
        "All data is treated as objects.\n",
        "\n",
        " Strings/tuples are immutable.\n",
        "\n",
        "  == checks if variables point to objects of same value. \n",
        "\n",
        "  'is' checks whether variables point to same object.\n",
        "\n",
        "Lists are mutable, y = x[:] returns shallow copy (new obj with same value).\n",
        "\n",
        "Can't add dictionaries\n",
        "\n",
        "\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "\"dynamic typing\" : \"variables come into existence when assigned and can be assigned again\",\n",
        "\"dictionary\": \"key must be immutable. \",\n",
        "\n",
        "}"
      ],
      "execution_count": 189,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 381
        },
        "outputId": "95f8ca74-7af8-4831-ade2-149c472d7422"
      },
      "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": 190,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n List comprehension: ```[i for i in range(0, 100)] ```.\n\nAll data is treated as objects.\n\n Strings/tuples are immutable.\n\n  == checks if variables point to objects of same value. \n\n  'is' checks whether variables point to same object.\n\nLists are mutable, y = x[:] returns shallow copy (new obj with same value).\n\nCan't add dictionaries\n\n\n\n\n\n## Module 2 Definitions\n* **Mutability** - your definition here\n* **Dynamic typing** - variables come into existence when assigned and can be assigned again\n* **Dictionary** - key must be immutable. \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 = \"\"\" Definition of search problems: states, initial state, actions, transition model, path cost (performance measure), goal test \"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\" Difference between state space and search tree: SP describes all the states\n",
        "                 in the world, and the actions that allow transitions between them. ST describes paths\n",
        "                 between these paths reaching towards the goal state.\n",
        "\n",
        " \"\"\"\n",
        "chapter3_4 = \"\"\" Your summary here \"\"\"\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",
        "\"open-loop system\" : \"ignore precepts\",    \n",
        "\"state space\" : \"set of possible states the environment can be in\",    \n",
        "\"transition model\" : \"describes what each action is capable of\", \n",
        "\"graph search\" : \"checks for redundant paths (basically just checks if node has been visited already)\", \n",
        "\"tree-like search\" : \"doesn't check for redundant paths (uses less memory)\", \n",
        "\"completeness\" : \"finds solution if there is one or reports failure\", \n",
        "\"cost optimality\" : \"does it find the lowest cost solution\", \n",
        "\"measuring problem solving performance\" : \"completeness, cost optimality, space/time complexity\", \n",
        "\"systematic\" : \"can explore infinite state space (ie BFS)\", \n",
        "\"branching factor\" : \"number of successors of a node\", \n",
        "\"BFS\" : \"cost optimal for uniform action cost. Memory problems bigger issue than time\", \n",
        "\"Uniform Cost Search\" : \"evaluation cost of path from root to currnode (Djikstras). Can search large trees of low action costs (bad)\", \n",
        "\"DFS\" : \"incomplete (can go down infinite path). When tree-like search is feasible dfs uses less memory: O(b * max depth)\", \n",
        "\"depth limited search\" : \"treat all nodes at limit L as if they had no successors. Time: O(b^L) Space: O(bL) \",\n",
        "\"diameter of state space\" : \"max distance between two nodes\", \n",
        "\"iterative deepening search\" : \"tries values of L until one works. Time: O(b^d) w solution, O(b^m) with none. Saves memory at cost of time.\", \n",
        "\"bi directional search\" : \"Search forward from initial state while searching back from goal\", \n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 191,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 797
        },
        "outputId": "25c7413c-258c-4607-b7f4-298fe5dfc2b2"
      },
      "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": 192,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Definition of search problems: states, initial state, actions, transition model, path cost (performance measure), goal test \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Difference between state space and search tree: SP describes all the states\n                 in the world, and the actions that allow transitions between them. ST describes paths\n                 between these paths reaching towards the goal state.\n\n \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \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* **Open-loop system** - ignore precepts\n* **State space** - set of possible states the environment can be in\n* **Transition model** - describes what each action is capable of\n* **Graph search** - checks for redundant paths (basically just checks if node has been visited already)\n* **Tree-like search** - doesn't check for redundant paths (uses less memory)\n* **Completeness** - finds solution if there is one or reports failure\n* **Cost optimality** - does it find the lowest cost solution\n* **Measuring problem solving performance** - completeness, cost optimality, space/time complexity\n* **Systematic** - can explore infinite state space (ie BFS)\n* **Branching factor** - number of successors of a node\n* **Bfs** - cost optimal for uniform action cost. Memory problems bigger issue than time\n* **Uniform cost search** - evaluation cost of path from root to currnode (Djikstras). Can search large trees of low action costs (bad)\n* **Dfs** - incomplete (can go down infinite path). When tree-like search is feasible dfs uses less memory: O(b * max depth)\n* **Depth limited search** - treat all nodes at limit L as if they had no successors. Time: O(b^L) Space: O(bL) \n* **Diameter of state space** - max distance between two nodes\n* **Iterative deepening search** - tries values of L until one works. Time: O(b^d) w solution, O(b^m) with none. Saves memory at cost of time.\n* **Bi directional search** - Search forward from initial state while searching back from goal\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 = \"\"\" Inadmissible heuristics may be more accurate. Iterative Deepening A* search is better for memory\"\"\"\n",
        "chapter3_6 = \"\"\" Quality of heuristic depends on effective branching factor b*. \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "  \"Best First Search\" : \"Expands node with lowest f(n) which includes h(n) value\",    \n",
        "\n",
        "\"greedy Best First Search\" : \"Expands node with lowest h(n) value\",    \n",
        "\"A*\" : \"evaluation function of g(n)+h(n). Is complete, and cost optimality depends on h(n). O(b^d) space\",    \n",
        "\"Admissible heuristic\" : \"never overestimates cost to reach goal (optimistic). Every consistent h(n) is admissible, but not vice versa\",    \n",
        "\"monotonic\" : \"path costs increase as you go down path (g() but not h() necessarily)\",    \n",
        "\"weighted A*\" : \"weigh h(n) more heavily\",    \n",
        "\"dominates\" : \"A dominating h(n) will never expand more nodes than another\",    \n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 193,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 443
        },
        "cellView": "form",
        "outputId": "d46452af-073a-481a-d0e8-6855a32aa9f7"
      },
      "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": 194,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Inadmissible heuristics may be more accurate. Iterative Deepening A* search is better for memory\n\n## AIMA Chapter 3.6 Heuristic Functions\n Quality of heuristic depends on effective branching factor b*. \n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Best first search** - Expands node with lowest f(n) which includes h(n) value\n* **Greedy best first search** - Expands node with lowest h(n) value\n* **A*** - evaluation function of g(n)+h(n). Is complete, and cost optimality depends on h(n). O(b^d) space\n* **Admissible heuristic** - never overestimates cost to reach goal (optimistic). Every consistent h(n) is admissible, but not vice versa\n* **Monotonic** - path costs increase as you go down path (g() but not h() necessarily)\n* **Weighted a*** - weigh h(n) more heavily\n* **Dominates** - A dominating h(n) will never expand more nodes than another\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 = \"\"\" A game is defined by initial state, To-Move(s) (defines which players turn it is)\n",
        "                 set of legal actions, transition model (defines what happens after action s), terminal test (shows when game is over),\n",
        "                 utility function  (defines numeric value to player p when game ends in terminal state s)\n",
        "\n",
        "\n",
        "\n",
        " \"\"\"\n",
        "chapter5_2 = \"\"\" Max will never allow move with worse score than alpha, min will never allow move with better score than beta.\n",
        "\n",
        "                 Alpha starts at -infinity, beta at infinity.\n",
        "\n",
        "                 Alpha and beta unique for each path\n",
        "\n",
        " \"\"\"\n",
        "chapter5_3 = \"\"\" E \"\"\"\n",
        "chapter5_5 = \"\"\" Expectiminimax for games with chance nodes. Terminal, max, and min nodes work the same as before. Max nodes -> Chance nodes -> min nodes\n",
        "\n",
        "\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"competitive environment\" : \"two or more agents have conflicting goals (adversarial search)\",  \n",
        "\"imperfect information\" : \"ie poker\", \n",
        "\"perfect information\" : \"fully observable\",    \n",
        "\"zero-sum\" : \"what is good for one person is equally bad for other\",    \n",
        "\"state-space graph\" : \"initial state, actions function. result function. Impose a search tree over part of this to decide what move to take\",    \n",
        "\"game tree\" : \"search tree that follows every sequence of moves (ply = taking one move) down to a terminal state\",   \n",
        "\"minimax algo\" : \"m = max-depth, b = legal moves. Time: O(b^m) Space: O(bm) if actions are generated at once, O(m) otherwise\",   \n",
        "\"alpha\" : \"best choice for max found so far at any choice point (max will have at least this many points)\",   \n",
        "\"beta\" : \"best choice for min found (aka lowest value) (max will have at most this many points)\",   \n",
        "\"horizon effect\" : \"delaying an inevitable disastrous move\",   \n",
        "\"singular extension\" : \"allow moves that are clearly better than others even if search would be cut off\",   \n",
        "\"forward pruning\" : \"prunes moves that appear poor but might possible be good\",   \n",
        "\"late move reduction\" : \"reduce the depth searched for later moves in list of possible moves (assume move ordering has been done well\",   \n",
        "\"stochastic\" : \"includes random element\",   \n",
        "\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 195,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "82bff28e-22bd-4cf0-d2f2-adaccc0cbda4"
      },
      "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": 196,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n A game is defined by initial state, To-Move(s) (defines which players turn it is)\n                 set of legal actions, transition model (defines what happens after action s), terminal test (shows when game is over),\n                 utility function  (defines numeric value to player p when game ends in terminal state s)\n\n\n\n \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Max will never allow move with worse score than alpha, min will never allow move with better score than beta.\n\n                 Alpha starts at -infinity, beta at infinity.\n\n                 Alpha and beta unique for each path\n\n \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n E \n\n## AIMA Chapter 5.5 Stochastic Games\n Expectiminimax for games with chance nodes. Terminal, max, and min nodes work the same as before. Max nodes -> Chance nodes -> min nodes\n\n\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 Your summary here \n\n## Module 5 Definitions\n* **Competitive environment** - two or more agents have conflicting goals (adversarial search)\n* **Imperfect information** - ie poker\n* **Perfect information** - fully observable\n* **Zero-sum** - what is good for one person is equally bad for other\n* **State-space graph** - initial state, actions function. result function. Impose a search tree over part of this to decide what move to take\n* **Game tree** - search tree that follows every sequence of moves (ply = taking one move) down to a terminal state\n* **Minimax algo** - m = max-depth, b = legal moves. Time: O(b^m) Space: O(bm) if actions are generated at once, O(m) otherwise\n* **Alpha** - best choice for max found so far at any choice point (max will have at least this many points)\n* **Beta** - best choice for min found (aka lowest value) (max will have at most this many points)\n* **Horizon effect** - delaying an inevitable disastrous move\n* **Singular extension** - allow moves that are clearly better than others even if search would be cut off\n* **Forward pruning** - prunes moves that appear poor but might possible be good\n* **Late move reduction** - reduce the depth searched for later moves in list of possible moves (assume move ordering has been done well\n* **Stochastic** - includes random element\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 = \"\"\" CSP consists of a set of variables, a set of domain for each of those variables, set of constraints\n",
        "                 that specify allowable combinations of values. Solving general nonlinear constraints on integers is undecidable.\n",
        "                 \n",
        "                 AC-3: Maintains queue of arcs (each binary constraint becomes two arcs). Pops off an arc, and make its nodes arc consistent\n",
        "                 with each other. If this changes domain of first one (Xi) then add each arc Xi is in to queue. If domain is empty, return failure.\n",
        "                 If domain didn't change, go to next arc. O(cd^3) worst case time (d = max domain size, c = # arcs)\n",
        "\n",
        "\n",
        " \"\"\"\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"constraint graph\" : \"nodes correspond to variables, edges connect nodes that participate in constraint\",\n",
        "\"unary constraint\" : \"restricts value of single variable (ie. X /= 2)\",    \n",
        "\"binary constraint\" : \"restricts value of two variables (ie. X /= Y)\",   \n",
        "\"binary csp\" : \"only has unary and binary constraints\",    \n",
        "\"global constraint\" : \"involves arbitrary number of variables\",    \n",
        "\"preference constraint\" : \"costs for certain variable assignments\",    \n",
        "\"constraint propagation\" : \"reducing number of legal values for a variable using constraints, which in turn might do the same for other variables\",    \n",
        "\"node consistency\" : \"a variable is node consistent if each value in its domain satisfy the variables' unary constraints\",    \n",
        "\"arc consistency (2 consistency)\" : \"every value in domain satisfies variables binary constraints (just has to be at least one value that satisfies)\",    \n",
        "\"path consistency (3 consistency)\" : \"(x1, x2) is pc to Xm if every (x1, x2) has a (x1, xm), (xm, x2) that's consistent\",    \n",
        "\"K-consistency\" : \"for any consistent set of k-1 variables, a consistent value can be assigned to kth variable\",    \n",
        "\"strongly K-consistent\" : \"k, k-1, k-2, etc consistent (must be all)\",    \n",
        "\"most constrained value heuristic (mrv)\" : \"choose variable with fewest allowed values as next choice\",    \n",
        "\"degree heuristic\" : \"choose variable involved in most # of constraints \",    \n",
        "\"least constraining value heuristic\" : \"assign value that rules out the least choice for neighboring values\",    \n",
        "\"forward checking\" : \"when variable is assigned, establish arc consistency for it (don't propagate)\",   \n",
        "\"MAC\" : \"propogates constraints\",    \n",
        "\n",
        "\"conflict set\" : \"variables that have conflicting values\",    \n",
        "\n",
        "\n",
        "\n",
        "}\n"
      ],
      "execution_count": 197,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 958
        },
        "outputId": "258e7829-4d5d-47d0-fa19-e4645443a65d"
      },
      "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": 198,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n CSP consists of a set of variables, a set of domain for each of those variables, set of constraints\n                 that specify allowable combinations of values. Solving general nonlinear constraints on integers is undecidable.\n                 \n                 AC-3: Maintains queue of arcs (each binary constraint becomes two arcs). Pops off an arc, and make its nodes arc consistent\n                 with each other. If this changes domain of first one (Xi) then add each arc Xi is in to queue. If domain is empty, return failure.\n                 If domain didn't change, go to next arc. O(cd^3) worst case time (d = max domain size, c = # arcs)\n\n\n \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 Your summary here \n\n## Module 6 Definitions\n* **Constraint graph** - nodes correspond to variables, edges connect nodes that participate in constraint\n* **Unary constraint** - restricts value of single variable (ie. X /= 2)\n* **Binary constraint** - restricts value of two variables (ie. X /= Y)\n* **Binary csp** - only has unary and binary constraints\n* **Global constraint** - involves arbitrary number of variables\n* **Preference constraint** - costs for certain variable assignments\n* **Constraint propagation** - reducing number of legal values for a variable using constraints, which in turn might do the same for other variables\n* **Node consistency** - a variable is node consistent if each value in its domain satisfy the variables' unary constraints\n* **Arc consistency (2 consistency)** - every value in domain satisfies variables binary constraints (just has to be at least one value that satisfies)\n* **Path consistency (3 consistency)** - (x1, x2) is pc to Xm if every (x1, x2) has a (x1, xm), (xm, x2) that's consistent\n* **K-consistency** - for any consistent set of k-1 variables, a consistent value can be assigned to kth variable\n* **Strongly k-consistent** - k, k-1, k-2, etc consistent (must be all)\n* **Most constrained value heuristic (mrv)** - choose variable with fewest allowed values as next choice\n* **Degree heuristic** - choose variable involved in most # of constraints \n* **Least constraining value heuristic** - assign value that rules out the least choice for neighboring values\n* **Forward checking** - when variable is assigned, establish arc consistency for it (don't propagate)\n* **Mac** - propogates constraints\n* **Conflict set** - variables that have conflicting values\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 = \"\"\"Back tracking: start from q until you reach set of know facts A and B \"\"\"\n",
        "chapter7_3 = \"\"\" Definite clause can be written as implication: (-L or -B or X) can be written\n",
        "                 as L and B => X\n",
        "   \"\"\"\n",
        "chapter7_4 = \"\"\" Forward chaining determines if single proposition q is in KB of definite clauses.  \n",
        "                 Write everything as implication and if all premises of implication are known add conclusion\n",
        "                 to set of known facts. Process continues until q is added or no more inferences can be made. (Linear time)\n",
        "    \"\"\"\n",
        "chapter7_5 = \"\"\" Resolution algorithm: To show KB |= a, show that KB and not a is unsatisfiable. \n",
        "                 First convert KB and not a to cnf. Then resolution rule is applied\n",
        "                 to resulting clauses. Each pair with complementary literals is resolved to \n",
        "                 make a new clause, which is added to set. Repeat this until either no new clauses\n",
        "                 can be added (KB does not entail a) or two clauses resolve and yield the empty clause \n",
        "                 (KB entails a)\n",
        "\n",
        "                 If you apply a resolution to a horn clause, you will get a horn clause\n",
        "\n",
        "\n",
        "\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"knowledge base\" : \"set of sentences (assertions about the world) (axioms are given)\",    \n",
        "\"A |= B\" : \"sentence A entails B. Models where A is true, B is true (A: x = 0, B: xy = 0)\",    \n",
        "\"sound\" : \"derives on entailed sentences\",    \n",
        "\"complete\" : \"can derive any sentence that is entailed\",    \n",
        "\"logical equivalence\" : \"two sentences are logically equivalent if they are true in same set of models\",    \n",
        "\"validity\" : \"true in all models (ie. p or not p)\",    \n",
        "\"monotonicity\" : \"set of entailed sentences can only increase as info is added\",    \n",
        "\"definite clause\" : \"disjunction of literals with exactly 1 positive\",    \n",
        "\"horn clause\" : \"disjunction where at most 1 is positive (includes definite clauses)\",    \n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 199,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 768
        },
        "outputId": "f7c988ba-813f-4cde-e714-9be868c240db"
      },
      "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": 200,
      "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\nBack tracking: start from q until you reach set of know facts A and B \n\n## AIMA Chapter 7.3 Logic\n Definite clause can be written as implication: (-L or -B or X) can be written\n                 as L and B => X\n   \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Forward chaining determines if single proposition q is in KB of definite clauses.  \n                 Write everything as implication and if all premises of implication are known add conclusion\n                 to set of known facts. Process continues until q is added or no more inferences can be made. (Linear time)\n    \n\n## AIMA 7.5 Propositional Theorem Proving\n Resolution algorithm: To show KB |= a, show that KB and not a is unsatisfiable. \n                 First convert KB and not a to cnf. Then resolution rule is applied\n                 to resulting clauses. Each pair with complementary literals is resolved to \n                 make a new clause, which is added to set. Repeat this until either no new clauses\n                 can be added (KB does not entail a) or two clauses resolve and yield the empty clause \n                 (KB entails a)\n\n                 If you apply a resolution to a horn clause, you will get a horn clause\n\n\n\n\n \n\n## Module 7 Lecture Notes\n Your summary here \n\n## Module 7 Definitions\n* **Knowledge base** - set of sentences (assertions about the world) (axioms are given)\n* **A |= b** - sentence A entails B. Models where A is true, B is true (A: x = 0, B: xy = 0)\n* **Sound** - derives on entailed sentences\n* **Complete** - can derive any sentence that is entailed\n* **Logical equivalence** - two sentences are logically equivalent if they are true in same set of models\n* **Validity** - true in all models (ie. p or not p)\n* **Monotonicity** - set of entailed sentences can only increase as info is added\n* **Definite clause** - disjunction of literals with exactly 1 positive\n* **Horn clause** - disjunction where at most 1 is positive (includes definite clauses)\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": "0408a056-c8bd-453c-d18e-f0fcfac840af"
      },
      "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": 201,
      "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 Performance measures should measure what you want achieved in the environment rather than how agent should behave. \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n PEAS: specify task environment (performance measure, environment, actautors, sensors) \n\n## AIMA 2.3 The Nature of Environments\n Hardest environment is continuous, partially observable, stochastic, multiagent\n\n## AIMA 2.4 The Structure of Agents\n Problem solving agent plans ahead and considers sequence of actions that from path to goal state (search) \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** - What the sensors perceive\n* **Percept history** - complete history of everything agent has ever perceived\n* **Agent function** - maps any given percept sequence to an action (ie. if square is dirty -> clean, if not -> move)\n* **Agent program** - implements the agent function (concrete implementation running within some physical system)\n* **Fully observable** - sensors show entire state of environment\n* **Deterministic** - next state is completely determined by current state\n* **Stochastic** - environment deals with probabilities (ie. 25% chance of rain tomorrow)\n* **Non-deterministic** - ie. there's a chance it's gonna rain tomorrow\n* **Episodic** - agent receives precept and then performs a single action\n* **Sequential** - current decision could affect all future ones (taxi driver, chess)\n* **Dynamic** - environment can change while agent is deliberating\n* **Simple reflex agent** - act based on current percept\n* **Model-based agent** - uses transition (how world works) and sensor (how world's  reflected in percept) models to keep track of world\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n List comprehension: ```[i for i in range(0, 100)] ```.\n\nAll data is treated as objects.\n\n Strings/tuples are immutable.\n\n  == checks if variables point to objects of same value. \n\n  'is' checks whether variables point to same object.\n\nLists are mutable, y = x[:] returns shallow copy (new obj with same value).\n\nCan't add dictionaries\n\n\n\n\n\n## Module 2 Definitions\n* **Mutability** - your definition here\n* **Dynamic typing** - variables come into existence when assigned and can be assigned again\n* **Dictionary** - key must be immutable. \n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Definition of search problems: states, initial state, actions, transition model, path cost (performance measure), goal test \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Difference between state space and search tree: SP describes all the states\n                 in the world, and the actions that allow transitions between them. ST describes paths\n                 between these paths reaching towards the goal state.\n\n \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \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* **Open-loop system** - ignore precepts\n* **State space** - set of possible states the environment can be in\n* **Transition model** - describes what each action is capable of\n* **Graph search** - checks for redundant paths (basically just checks if node has been visited already)\n* **Tree-like search** - doesn't check for redundant paths (uses less memory)\n* **Completeness** - finds solution if there is one or reports failure\n* **Cost optimality** - does it find the lowest cost solution\n* **Measuring problem solving performance** - completeness, cost optimality, space/time complexity\n* **Systematic** - can explore infinite state space (ie BFS)\n* **Branching factor** - number of successors of a node\n* **Bfs** - cost optimal for uniform action cost. Memory problems bigger issue than time\n* **Uniform cost search** - evaluation cost of path from root to currnode (Djikstras). Can search large trees of low action costs (bad)\n* **Dfs** - incomplete (can go down infinite path). When tree-like search is feasible dfs uses less memory: O(b * max depth)\n* **Depth limited search** - treat all nodes at limit L as if they had no successors. Time: O(b^L) Space: O(bL) \n* **Diameter of state space** - max distance between two nodes\n* **Iterative deepening search** - tries values of L until one works. Time: O(b^d) w solution, O(b^m) with none. Saves memory at cost of time.\n* **Bi directional search** - Search forward from initial state while searching back from goal\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Inadmissible heuristics may be more accurate. Iterative Deepening A* search is better for memory\n\n## AIMA Chapter 3.6 Heuristic Functions\n Quality of heuristic depends on effective branching factor b*. \n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Best first search** - Expands node with lowest f(n) which includes h(n) value\n* **Greedy best first search** - Expands node with lowest h(n) value\n* **A*** - evaluation function of g(n)+h(n). Is complete, and cost optimality depends on h(n). O(b^d) space\n* **Admissible heuristic** - never overestimates cost to reach goal (optimistic). Every consistent h(n) is admissible, but not vice versa\n* **Monotonic** - path costs increase as you go down path (g() but not h() necessarily)\n* **Weighted a*** - weigh h(n) more heavily\n* **Dominates** - A dominating h(n) will never expand more nodes than another\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n A game is defined by initial state, To-Move(s) (defines which players turn it is)\n                 set of legal actions, transition model (defines what happens after action s), terminal test (shows when game is over),\n                 utility function  (defines numeric value to player p when game ends in terminal state s)\n\n\n\n \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Max will never allow move with worse score than alpha, min will never allow move with better score than beta.\n\n                 Alpha starts at -infinity, beta at infinity.\n\n                 Alpha and beta unique for each path\n\n \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n E \n\n## AIMA Chapter 5.5 Stochastic Games\n Expectiminimax for games with chance nodes. Terminal, max, and min nodes work the same as before. Max nodes -> Chance nodes -> min nodes\n\n\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 Your summary here \n\n## Module 5 Definitions\n* **Competitive environment** - two or more agents have conflicting goals (adversarial search)\n* **Imperfect information** - ie poker\n* **Perfect information** - fully observable\n* **Zero-sum** - what is good for one person is equally bad for other\n* **State-space graph** - initial state, actions function. result function. Impose a search tree over part of this to decide what move to take\n* **Game tree** - search tree that follows every sequence of moves (ply = taking one move) down to a terminal state\n* **Minimax algo** - m = max-depth, b = legal moves. Time: O(b^m) Space: O(bm) if actions are generated at once, O(m) otherwise\n* **Alpha** - best choice for max found so far at any choice point (max will have at least this many points)\n* **Beta** - best choice for min found (aka lowest value) (max will have at most this many points)\n* **Horizon effect** - delaying an inevitable disastrous move\n* **Singular extension** - allow moves that are clearly better than others even if search would be cut off\n* **Forward pruning** - prunes moves that appear poor but might possible be good\n* **Late move reduction** - reduce the depth searched for later moves in list of possible moves (assume move ordering has been done well\n* **Stochastic** - includes random element\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n CSP consists of a set of variables, a set of domain for each of those variables, set of constraints\n                 that specify allowable combinations of values. Solving general nonlinear constraints on integers is undecidable.\n                 \n                 AC-3: Maintains queue of arcs (each binary constraint becomes two arcs). Pops off an arc, and make its nodes arc consistent\n                 with each other. If this changes domain of first one (Xi) then add each arc Xi is in to queue. If domain is empty, return failure.\n                 If domain didn't change, go to next arc. O(cd^3) worst case time (d = max domain size, c = # arcs)\n\n\n \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 Your summary here \n\n## Module 6 Definitions\n* **Constraint graph** - nodes correspond to variables, edges connect nodes that participate in constraint\n* **Unary constraint** - restricts value of single variable (ie. X /= 2)\n* **Binary constraint** - restricts value of two variables (ie. X /= Y)\n* **Binary csp** - only has unary and binary constraints\n* **Global constraint** - involves arbitrary number of variables\n* **Preference constraint** - costs for certain variable assignments\n* **Constraint propagation** - reducing number of legal values for a variable using constraints, which in turn might do the same for other variables\n* **Node consistency** - a variable is node consistent if each value in its domain satisfy the variables' unary constraints\n* **Arc consistency (2 consistency)** - every value in domain satisfies variables binary constraints (just has to be at least one value that satisfies)\n* **Path consistency (3 consistency)** - (x1, x2) is pc to Xm if every (x1, x2) has a (x1, xm), (xm, x2) that's consistent\n* **K-consistency** - for any consistent set of k-1 variables, a consistent value can be assigned to kth variable\n* **Strongly k-consistent** - k, k-1, k-2, etc consistent (must be all)\n* **Most constrained value heuristic (mrv)** - choose variable with fewest allowed values as next choice\n* **Degree heuristic** - choose variable involved in most # of constraints \n* **Least constraining value heuristic** - assign value that rules out the least choice for neighboring values\n* **Forward checking** - when variable is assigned, establish arc consistency for it (don't propagate)\n* **Mac** - propogates constraints\n* **Conflict set** - variables that have conflicting values\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\nBack tracking: start from q until you reach set of know facts A and B \n\n## AIMA Chapter 7.3 Logic\n Definite clause can be written as implication: (-L or -B or X) can be written\n                 as L and B => X\n   \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Forward chaining determines if single proposition q is in KB of definite clauses.  \n                 Write everything as implication and if all premises of implication are known add conclusion\n                 to set of known facts. Process continues until q is added or no more inferences can be made. (Linear time)\n    \n\n## AIMA 7.5 Propositional Theorem Proving\n Resolution algorithm: To show KB |= a, show that KB and not a is unsatisfiable. \n                 First convert KB and not a to cnf. Then resolution rule is applied\n                 to resulting clauses. Each pair with complementary literals is resolved to \n                 make a new clause, which is added to set. Repeat this until either no new clauses\n                 can be added (KB does not entail a) or two clauses resolve and yield the empty clause \n                 (KB entails a)\n\n                 If you apply a resolution to a horn clause, you will get a horn clause\n\n\n\n\n \n\n## Module 7 Lecture Notes\n Your summary here \n\n## Module 7 Definitions\n* **Knowledge base** - set of sentences (assertions about the world) (axioms are given)\n* **A |= b** - sentence A entails B. Models where A is true, B is true (A: x = 0, B: xy = 0)\n* **Sound** - derives on entailed sentences\n* **Complete** - can derive any sentence that is entailed\n* **Logical equivalence** - two sentences are logically equivalent if they are true in same set of models\n* **Validity** - true in all models (ie. p or not p)\n* **Monotonicity** - set of entailed sentences can only increase as info is added\n* **Definite clause** - disjunction of literals with exactly 1 positive\n* **Horn clause** - disjunction where at most 1 is positive (includes definite clauses)\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}