{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of FINAL Template_for CIS521_midterm notes - Schwarz.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": "f26e9696-6f5f-41f2-edbc-7ffad8d00082"
      },
      "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": 2,
      "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": "f251be77-3893-4110-cab4-1e26d28f7ac9"
      },
      "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": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = False"
      ],
      "execution_count": 4,
      "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 = \"\"\" \n",
        "Definition of AI: abstract formal definition called rationality. \\\n",
        "Turing test is the thought expiriment asking if a human can tell the difference between another human agent, or a machine agent. \\\n",
        "A rational agent is one that acts so as to acieve the best (expected) outcome\n",
        "\n",
        " \"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter27_2 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_2 = \"\"\" Definies what the rational agent is. Says that the rational agent should select an action that is expected to maximize the performance mesure given what is in the precept. \\\n",
        "Highlights the difference between being rational and being omniscient. It is rational to look both ways before crossing the street. It is omniscient to know that a piano would have fallen on your head if you crossed. \"\"\"\n",
        "chapter2_3 = \"\"\" Introduces how to formulate a problem for the rational agent to solve. Gives an example of how the task environment for an automated taxi can be created. \n",
        "A single agent environamnet is one where agent B's behavior is best described as maximizing a performance value which is influenced by A's behavior\"\"\"\n",
        "chapter2_4 = \"\"\" Your summary here \"\"\"\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",
        "\"performance measure\" : \"evaluates the behavior of the agent in an environment. Rational agent will attempt to rationalize this metric\",\n",
        "\"precept\" : \"what the agents sensors are currently seeing\",\n",
        "\"actuators\": \"what the agent uses to act upon the environment that it is in\",\n",
        "\"agent function\": \"maps any given percept sequence to an action\",\n",
        "\"task environments\": \"The problems that the rational agent needs to solve.\",\n",
        "\"PEAS\": \"Performace, Environment, Actuators, Sensors\",\n",
        "\"Fully Observable\": \"Sensors give the agent access to the complete state of the environment at any given time\",\n",
        "\"Partially Observable\": \"Sensors A non fully obervable environment. Could be due to lack of sensors or noisy sensors\",\n",
        "\"Deterministic environments\": \"If the next state of the environment is determined by the current state plus the action of the agent\",\n",
        "\"Stochastic\": \"A non-deterministic where the model uses quantified probabilites for future states\"\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 5,
      "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": 921
        },
        "cellView": "form",
        "outputId": "5fc54a03-c162-459a-f576-5543702279de"
      },
      "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": 6,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nDefinition of AI: abstract formal definition called rationality. Turing test is the thought expiriment asking if a human can tell the difference between another human agent, or a machine agent. A rational agent is one that acts so as to acieve the best (expected) outcome\n\n \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Definies what the rational agent is. Says that the rational agent should select an action that is expected to maximize the performance mesure given what is in the precept. Highlights the difference between being rational and being omniscient. It is rational to look both ways before crossing the street. It is omniscient to know that a piano would have fallen on your head if you crossed. \n\n## AIMA 2.3 The Nature of Environments\n Introduces how to formulate a problem for the rational agent to solve. Gives an example of how the task environment for an automated taxi can be created. \nA single agent environamnet is one where agent B's behavior is best described as maximizing a performance value which is influenced by A's behavior\n\n## AIMA 2.4 The Structure of Agents\n Your summary here \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* **Performance measure** - evaluates the behavior of the agent in an environment. Rational agent will attempt to rationalize this metric\n* **Precept** - what the agents sensors are currently seeing\n* **Actuators** - what the agent uses to act upon the environment that it is in\n* **Agent function** - maps any given percept sequence to an action\n* **Task environments** - The problems that the rational agent needs to solve.\n* **Peas** - Performace, Environment, Actuators, Sensors\n* **Fully observable** - Sensors give the agent access to the complete state of the environment at any given time\n* **Partially observable** - Sensors A non fully obervable environment. Could be due to lack of sensors or noisy sensors\n* **Deterministic environments** - If the next state of the environment is determined by the current state plus the action of the agent\n* **Stochastic** - A non-deterministic where the model uses quantified probabilites for future states\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"the ability to change items after the initial variable assignment\",\n",
        "}"
      ],
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 210
        },
        "outputId": "d32d728b-3376-4382-c93d-dcd1092c16cf"
      },
      "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": 8,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n Your summary here \n\n## Module 2 Definitions\n* **Mutability** - the ability to change items after the initial variable assignment\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "46MQLR-Gx8dZ"
      },
      "source": [
        "#Module 3 - Search Problems"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BN0b1eVYx-nd"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
        "chapter3_1 = \"\"\" \n",
        "Search problem definition:\n",
        "1. A set of possible states that cover every state the environment can be in\n",
        "2. The initial state of the agent\n",
        "3. Goal states. Can be multiple\n",
        "4. Actions available to the agent at the current state\n",
        "5. Transition model which links the current state and next action to the next state\n",
        "6. Action cost function \"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\"\n",
        "Best First Search (Djikstras):\n",
        "  Always expand the node on the frontier that has the smallest value\n",
        "Breadth First Search:\n",
        "  Iterate over each child attached to a node. Add each child to the end of a queue. After the node has been explored, mark it as so. Explore the next node on the frontier.\n",
        "  Is complete; always finds a solution with a minimal number of actions.\n",
        "  Cost Optimal for actions with uniform cost.\n",
        "  Complete\n",
        "  O(B^d) for time and space. b = branching factor, d = depth of solution\n",
        "  Memory requirements are the limiting factor with BFS\n",
        "Depth First Search:\n",
        "  From current node, iterate over each child. For each child, recursively search the child node. If child node is goal state, return it\n",
        "  Not cost optimal. Not guaranteed to return the least expensive path\n",
        "  Incomplete as it can get stuck going down an inifinite path\n",
        "  Memory complexity of O(bm) b= branching factor, m = max depth \"\"\"\n",
        "chapter3_4 = \"\"\" Iterative deepening search. Runs DFS with a max depth of l which increments over each run of DFS\n",
        "memory: O(bm)\n",
        "time: O(b^d) \"\"\"\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",
        "\"frontier\": \"Nodes that are known to the agent but have not been expanded to yet.\",\n",
        "\"Completeness\": \"Does the algorithm find the correct solution every time. Does it know when it can't find a solution\",\n",
        "\"Cost optimality\": \"Does my solution guarantee that it is the lowest cost\",\n",
        "\"Time complexity\": \"Is my solution being found in an optimal time\",\n",
        "\"Spacial complexity\": \"Is my solution being found in optimal space\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 769
        },
        "outputId": "2d1feb90-2c3e-43a7-a8e6-e75eb431f3ed"
      },
      "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": 10,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n \nSearch problem definition:\n1. A set of possible states that cover every state the environment can be in\n2. The initial state of the agent\n3. Goal states. Can be multiple\n4. Actions available to the agent at the current state\n5. Transition model which links the current state and next action to the next state\n6. Action cost function \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n\nBest First Search (Djikstras):\n  Always expand the node on the frontier that has the smallest value\nBreadth First Search:\n  Iterate over each child attached to a node. Add each child to the end of a queue. After the node has been explored, mark it as so. Explore the next node on the frontier.\n  Is complete; always finds a solution with a minimal number of actions.\n  Cost Optimal for actions with uniform cost.\n  Complete\n  O(B^d) for time and space. b = branching factor, d = depth of solution\n  Memory requirements are the limiting factor with BFS\nDepth First Search:\n  From current node, iterate over each child. For each child, recursively search the child node. If child node is goal state, return it\n  Not cost optimal. Not guaranteed to return the least expensive path\n  Incomplete as it can get stuck going down an inifinite path\n  Memory complexity of O(bm) b= branching factor, m = max depth \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Iterative deepening search. Runs DFS with a max depth of l which increments over each run of DFS\nmemory: O(bm)\ntime: O(b^d) \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* **Frontier** - Nodes that are known to the agent but have not been expanded to yet.\n* **Completeness** - Does the algorithm find the correct solution every time. Does it know when it can't find a solution\n* **Cost optimality** - Does my solution guarantee that it is the lowest cost\n* **Time complexity** - Is my solution being found in an optimal time\n* **Spacial complexity** - Is my solution being found in optimal space\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 = \"\"\" \n",
        "Greedy Best First Search:\n",
        "  Runs on the heuristic that thebest node is the one that is closest to the goal.\n",
        "  Meaning it expands a node. Adds all children and their heuristic value to a priority queue, then selects the number on priority to expand\n",
        "  Complete in finite spaces.\n",
        "  time and space O(bm).\n",
        "  Not cost optimal\n",
        "\n",
        "A* search:\n",
        "  Similar to GBFS but the heuristic factors in the path to get the current node\n",
        "  H(n) = cost to get to current path + cost to get to goal\n",
        "  huerisitic nust be admissibile. Must not overestimate the cost to reach a goal.\n",
        "  With an admissibile heuristic, the algorithm is cost optimal\"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Characterizing effective branching factors of heuristics, b*. \n",
        "A hueristic dominates (h2 dominates h1) another when h_2(n)>=h_1(n) for all n.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 402
        },
        "cellView": "form",
        "outputId": "55832587-e240-4085-bd57-c43ae49064ce"
      },
      "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": 12,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n \nGreedy Best First Search:\n  Runs on the heuristic that thebest node is the one that is closest to the goal.\n  Meaning it expands a node. Adds all children and their heuristic value to a priority queue, then selects the number on priority to expand\n  Complete in finite spaces.\n  time and space O(bm).\n  Not cost optimal\n\nA* search:\n  Similar to GBFS but the heuristic factors in the path to get the current node\n  H(n) = cost to get to current path + cost to get to goal\n  huerisitic nust be admissibile. Must not overestimate the cost to reach a goal.\n  With an admissibile heuristic, the algorithm is cost optimal\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Characterizing effective branching factors of heuristics, b*. \nA hueristic dominates (h2 dominates h1) another when h_2(n)>=h_1(n) for all n.\n\n## Module 4 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" \n",
        "Minimax.\n",
        "2 players playing a 0 sum game. MAX is attempting to maximize the score of the board while MIN is minimizing\n",
        "MAX initializes a vairable to -inf.\n",
        "Then looks through all actions and recursively gets the MIN value of each action.\n",
        "Then MAX chooses the largest MIN value.\n",
        "MIN performs the same steps but in reverse\n",
        "\n",
        "Alpha-Beta Pruning\n",
        "A slight variation on MINIMAX\n",
        "This will remove branches of the MINIMAX tree if they are unable to be selected\n",
        "This involves max knowing the values of the steps ahead of him. For one action, MIN can produce a state of 3, 12, or 8. MIN will choose 3 because its the lowest. If MAX took another action, it could result in 2, 4, or 6. But we stop the search as soon as we see the 2 because MAX knows MIN will pick 2 and we already have another branch where MIN would pick 3.\n",
        "\n",
        "EXPECTIMINIMAX:\n",
        "MAX makes a move. Then the resulting move from min produces some set of states with a probability for each one. The value of the MAX move is the weighted sum of the utility of the probablistic states multiplied by their probability. Run it like MINIMAX \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 812
        },
        "outputId": "e5a30c2e-7269-4e74-a6f9-34a7d7220ef5"
      },
      "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": 14,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n \nMinimax.\n2 players playing a 0 sum game. MAX is attempting to maximize the score of the board while MIN is minimizing\nMAX initializes a vairable to -inf.\nThen looks through all actions and recursively gets the MIN value of each action.\nThen MAX chooses the largest MIN value.\nMIN performs the same steps but in reverse\n\nAlpha-Beta Pruning\nA slight variation on MINIMAX\nThis will remove branches of the MINIMAX tree if they are unable to be selected\nThis involves max knowing the values of the steps ahead of him. For one action, MIN can produce a state of 3, 12, or 8. MIN will choose 3 because its the lowest. If MAX took another action, it could result in 2, 4, or 6. But we stop the search as soon as we see the 2 because MAX knows MIN will pick 2 and we already have another branch where MIN would pick 3.\n\nEXPECTIMINIMAX:\nMAX makes a move. Then the resulting move from min produces some set of states with a probability for each one. The value of the MAX move is the weighted sum of the utility of the probablistic states multiplied by their probability. Run it like MINIMAX \n\n## Module 5 Definitions\n* **Concept** - definition\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 = \"\"\" \n",
        "CSP has 3 parts:\n",
        "1. X: a set of variables\n",
        "2. D: a set of domains\n",
        "3. C: a set of constraints \n",
        "CSPs are used because they are easy to formulate. The problems can easily prune large branches of the statespace resulting in an large reductions of processig time\n",
        "\n",
        "Constraing Types:\n",
        "1. Unary constraint: Restricts the value of a single variable. Ex. NSW cant be green\n",
        "2. Binary Constraint: Restricts values based on a set of 2 variables. Ex. NSW cant be the same color as Q\n",
        "3. Higher Order Constraint: Similar to Binary but involving 3 or more variables\n",
        "4. Global Constraint: Restricts an arbitrary amount of variables. Ex. All variables must be different\"\"\"\n",
        "chapter6_2 = \"\"\" \n",
        "Constraint Propagation Inference. Using the given restraints to remove illegal values for each variables. Which then reduces illegal values for other variables.\n",
        "\n",
        "A variable needs to have node consistency which means all of the values in the variables domain must satisfy its unary constraints.\n",
        "\n",
        "The connection between two variables must have arc-consistency. Every value in its domain satisfies the variables binary constraint\n",
        "\n",
        "AC-3:\n",
        "CSP algorithms for enforcing arc consistency.\n",
        "AC-3 maintains queue of initially all arcs in the CSP. It pops off the first arc of (X_i, X_j). every value in the domain of X_i is checked to see if a value in the domain of X_j would constrain it.\n",
        "\n",
        "Ex. Sudoku: X_i = {1, 3, 5}, X_j = {3}. We look through 1 and no constraint is found. Then look at 3 and see that the value in the X_j domain prevents X_i from having 3 in its domain.\n",
        "\n",
        "\n",
        "If a change was made, then add all neighbors of X_i to the queue as arcs of (X_k, X_i) \n",
        "\n",
        "time complexity = O(cd^3). c = number of arcs. d = size of domain\n",
        "\"\"\"\n",
        "chapter6_3 = \"\"\" Backtrackin algorithms. Adding a depth first search mechanic that runs an inference alogrithm. \n",
        "\n",
        "Initially the algorithm guesses a value for a variable. Then runs inference. If that inference doesnt return failure, it guesses again. If that inference returns a failure, that node becomes a leaf and the algorithm backs up to a previous state and guesses another value \"\"\"\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",
        "\"assignment\" : \"putting a value on a varaible\",\n",
        "\"consitent assignment\": \"an assignment that follows all contraints\",\n",
        "\"partial assignment\": \"an assignment that leaves some variables unassigned\",\n",
        "\"complete assignment\": \"all variables have a consistent assignment\",\n",
        "\"minimum-remaining-values(MRV)\": \"choosing the variable that has the fewest legal values\",   \n",
        "\"degree heuristic\": \"select the variable that is involved in the largest number of constraints on other unassigned variabels\",\n",
        "\"least-contraining-value\": \"select the value that provides the smallest reduction in choices for neighboring variables.\" \n",
        "}\n"
      ],
      "execution_count": 15,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "940858fa-6bf8-4e03-945a-16ffed911663"
      },
      "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": 16,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n \nCSP has 3 parts:\n1. X: a set of variables\n2. D: a set of domains\n3. C: a set of constraints \nCSPs are used because they are easy to formulate. The problems can easily prune large branches of the statespace resulting in an large reductions of processig time\n\nConstraing Types:\n1. Unary constraint: Restricts the value of a single variable. Ex. NSW cant be green\n2. Binary Constraint: Restricts values based on a set of 2 variables. Ex. NSW cant be the same color as Q\n3. Higher Order Constraint: Similar to Binary but involving 3 or more variables\n4. Global Constraint: Restricts an arbitrary amount of variables. Ex. All variables must be different\n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n \nConstraint Propagation Inference. Using the given restraints to remove illegal values for each variables. Which then reduces illegal values for other variables.\n\nA variable needs to have node consistency which means all of the values in the variables domain must satisfy its unary constraints.\n\nThe connection between two variables must have arc-consistency. Every value in its domain satisfies the variables binary constraint\n\nAC-3:\nCSP algorithms for enforcing arc consistency.\nAC-3 maintains queue of initially all arcs in the CSP. It pops off the first arc of (X_i, X_j). every value in the domain of X_i is checked to see if a value in the domain of X_j would constrain it.\n\nEx. Sudoku: X_i = {1, 3, 5}, X_j = {3}. We look through 1 and no constraint is found. Then look at 3 and see that the value in the X_j domain prevents X_i from having 3 in its domain.\n\n\nIf a change was made, then add all neighbors of X_i to the queue as arcs of (X_k, X_i) \n\ntime complexity = O(cd^3). c = number of arcs. d = size of domain\n\n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Backtrackin algorithms. Adding a depth first search mechanic that runs an inference alogrithm. \n\nInitially the algorithm guesses a value for a variable. Then runs inference. If that inference doesnt return failure, it guesses again. If that inference returns a failure, that node becomes a leaf and the algorithm backs up to a previous state and guesses another value \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* **Assignment** - putting a value on a varaible\n* **Consitent assignment** - an assignment that follows all contraints\n* **Partial assignment** - an assignment that leaves some variables unassigned\n* **Complete assignment** - all variables have a consistent assignment\n* **Minimum-remaining-values(mrv)** - choosing the variable that has the fewest legal values\n* **Degree heuristic** - select the variable that is involved in the largest number of constraints on other unassigned variabels\n* **Least-contraining-value** - select the value that provides the smallest reduction in choices for neighboring variables.\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",
        "# 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 = \"\"\" Logic:\n",
        "A model is an abstraction. If sentace a is true in model m, then m satisfies a.\n",
        " \"\"\"\n",
        "chapter7_4 = \"\"\" \n",
        "not: negation\n",
        "\n",
        "and: conjunction\n",
        "\n",
        "or: disjunction\n",
        "\n",
        "implies: if-then. antecedent and conclusion. not a or B \n",
        "\n",
        "iff: binconditional. Implies both ways\"\"\"\n",
        "chapter7_5 = \"\"\" a and b are logically equivalent if they are true in the same set of models\n",
        "\n",
        "Modus Podens: whenever a implies b, and a is given, we can infer b\n",
        "\n",
        "And Elimination: whenever we have A and B = true, we can infer A = true\n",
        "\n",
        "Resolution:\n",
        "(P_1,1 V P_2,2 V P_3,1) A not P_2,2 = P_1,1, P_3,1\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" \n",
        "CNF:\n",
        "1. Eleminate biconditional\n",
        "2. Eliminate implications\n",
        "3. Move negations inwards and apply demorgans\n",
        "4. Distribute ors\n",
        "\n",
        "\n",
        "Resolution algorithm:\n",
        "1. convert (KB and not(a)) into CNF\n",
        "2. Apply resolution rule to caluese\n",
        "3. Resolve every pair that contains complementary literals to produce new clauses\n",
        "4. If noew clause doesnt exist, add to set\n",
        "5. Continue until new new clauses can be added (KB does not entail a) or two clasuses resolve to yield the empty clause (KB does entail a)\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 17,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 924
        },
        "outputId": "c62593eb-14ef-4eca-acc7-e7dcae93caf2"
      },
      "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": 18,
      "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 Logic:\nA model is an abstraction. If sentace a is true in model m, then m satisfies a.\n \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n \nnot: negation\n\nand: conjunction\n\nor: disjunction\n\nimplies: if-then. antecedent and conclusion. not a or B \n\niff: binconditional. Implies both ways\n\n## AIMA 7.5 Propositional Theorem Proving\n a and b are logically equivalent if they are true in the same set of models\n\nModus Podens: whenever a implies b, and a is given, we can infer b\n\nAnd Elimination: whenever we have A and B = true, we can infer A = true\n\nResolution:\n(P_1,1 V P_2,2 V P_3,1) A not P_2,2 = P_1,1, P_3,1\n\n \n\n## Module 7 Lecture Notes\n \nCNF:\n1. Eleminate biconditional\n2. Eliminate implications\n3. Move negations inwards and apply demorgans\n4. Distribute ors\n\n\nResolution algorithm:\n1. convert (KB and not(a)) into CNF\n2. Apply resolution rule to caluese\n3. Resolve every pair that contains complementary literals to produce new clauses\n4. If noew clause doesnt exist, add to set\n5. Continue until new new clauses can be added (KB does not entail a) or two clasuses resolve to yield the empty clause (KB does entail a)\n\n\n## Module 7 Definitions\n* **Concept** - definition\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": "82d98860-42d2-4046-caa2-83a7dca548c6"
      },
      "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": 19,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nDefinition of AI: abstract formal definition called rationality. Turing test is the thought expiriment asking if a human can tell the difference between another human agent, or a machine agent. A rational agent is one that acts so as to acieve the best (expected) outcome\n\n \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Definies what the rational agent is. Says that the rational agent should select an action that is expected to maximize the performance mesure given what is in the precept. Highlights the difference between being rational and being omniscient. It is rational to look both ways before crossing the street. It is omniscient to know that a piano would have fallen on your head if you crossed. \n\n## AIMA 2.3 The Nature of Environments\n Introduces how to formulate a problem for the rational agent to solve. Gives an example of how the task environment for an automated taxi can be created. \nA single agent environamnet is one where agent B's behavior is best described as maximizing a performance value which is influenced by A's behavior\n\n## AIMA 2.4 The Structure of Agents\n Your summary here \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* **Performance measure** - evaluates the behavior of the agent in an environment. Rational agent will attempt to rationalize this metric\n* **Precept** - what the agents sensors are currently seeing\n* **Actuators** - what the agent uses to act upon the environment that it is in\n* **Agent function** - maps any given percept sequence to an action\n* **Task environments** - The problems that the rational agent needs to solve.\n* **Peas** - Performace, Environment, Actuators, Sensors\n* **Fully observable** - Sensors give the agent access to the complete state of the environment at any given time\n* **Partially observable** - Sensors A non fully obervable environment. Could be due to lack of sensors or noisy sensors\n* **Deterministic environments** - If the next state of the environment is determined by the current state plus the action of the agent\n* **Stochastic** - A non-deterministic where the model uses quantified probabilites for future states\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Your summary here \n\n## Module 2 Definitions\n* **Mutability** - the ability to change items after the initial variable assignment\n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n \nSearch problem definition:\n1. A set of possible states that cover every state the environment can be in\n2. The initial state of the agent\n3. Goal states. Can be multiple\n4. Actions available to the agent at the current state\n5. Transition model which links the current state and next action to the next state\n6. Action cost function \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n\nBest First Search (Djikstras):\n  Always expand the node on the frontier that has the smallest value\nBreadth First Search:\n  Iterate over each child attached to a node. Add each child to the end of a queue. After the node has been explored, mark it as so. Explore the next node on the frontier.\n  Is complete; always finds a solution with a minimal number of actions.\n  Cost Optimal for actions with uniform cost.\n  Complete\n  O(B^d) for time and space. b = branching factor, d = depth of solution\n  Memory requirements are the limiting factor with BFS\nDepth First Search:\n  From current node, iterate over each child. For each child, recursively search the child node. If child node is goal state, return it\n  Not cost optimal. Not guaranteed to return the least expensive path\n  Incomplete as it can get stuck going down an inifinite path\n  Memory complexity of O(bm) b= branching factor, m = max depth \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Iterative deepening search. Runs DFS with a max depth of l which increments over each run of DFS\nmemory: O(bm)\ntime: O(b^d) \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* **Frontier** - Nodes that are known to the agent but have not been expanded to yet.\n* **Completeness** - Does the algorithm find the correct solution every time. Does it know when it can't find a solution\n* **Cost optimality** - Does my solution guarantee that it is the lowest cost\n* **Time complexity** - Is my solution being found in an optimal time\n* **Spacial complexity** - Is my solution being found in optimal space\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n \nGreedy Best First Search:\n  Runs on the heuristic that thebest node is the one that is closest to the goal.\n  Meaning it expands a node. Adds all children and their heuristic value to a priority queue, then selects the number on priority to expand\n  Complete in finite spaces.\n  time and space O(bm).\n  Not cost optimal\n\nA* search:\n  Similar to GBFS but the heuristic factors in the path to get the current node\n  H(n) = cost to get to current path + cost to get to goal\n  huerisitic nust be admissibile. Must not overestimate the cost to reach a goal.\n  With an admissibile heuristic, the algorithm is cost optimal\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Characterizing effective branching factors of heuristics, b*. \nA hueristic dominates (h2 dominates h1) another when h_2(n)>=h_1(n) for all n.\n\n## Module 4 Definitions\n* **Concept** - definition\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n \nMinimax.\n2 players playing a 0 sum game. MAX is attempting to maximize the score of the board while MIN is minimizing\nMAX initializes a vairable to -inf.\nThen looks through all actions and recursively gets the MIN value of each action.\nThen MAX chooses the largest MIN value.\nMIN performs the same steps but in reverse\n\nAlpha-Beta Pruning\nA slight variation on MINIMAX\nThis will remove branches of the MINIMAX tree if they are unable to be selected\nThis involves max knowing the values of the steps ahead of him. For one action, MIN can produce a state of 3, 12, or 8. MIN will choose 3 because its the lowest. If MAX took another action, it could result in 2, 4, or 6. But we stop the search as soon as we see the 2 because MAX knows MIN will pick 2 and we already have another branch where MIN would pick 3.\n\nEXPECTIMINIMAX:\nMAX makes a move. Then the resulting move from min produces some set of states with a probability for each one. The value of the MAX move is the weighted sum of the utility of the probablistic states multiplied by their probability. Run it like MINIMAX \n\n## Module 5 Definitions\n* **Concept** - definition\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n \nCSP has 3 parts:\n1. X: a set of variables\n2. D: a set of domains\n3. C: a set of constraints \nCSPs are used because they are easy to formulate. The problems can easily prune large branches of the statespace resulting in an large reductions of processig time\n\nConstraing Types:\n1. Unary constraint: Restricts the value of a single variable. Ex. NSW cant be green\n2. Binary Constraint: Restricts values based on a set of 2 variables. Ex. NSW cant be the same color as Q\n3. Higher Order Constraint: Similar to Binary but involving 3 or more variables\n4. Global Constraint: Restricts an arbitrary amount of variables. Ex. All variables must be different\n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n \nConstraint Propagation Inference. Using the given restraints to remove illegal values for each variables. Which then reduces illegal values for other variables.\n\nA variable needs to have node consistency which means all of the values in the variables domain must satisfy its unary constraints.\n\nThe connection between two variables must have arc-consistency. Every value in its domain satisfies the variables binary constraint\n\nAC-3:\nCSP algorithms for enforcing arc consistency.\nAC-3 maintains queue of initially all arcs in the CSP. It pops off the first arc of (X_i, X_j). every value in the domain of X_i is checked to see if a value in the domain of X_j would constrain it.\n\nEx. Sudoku: X_i = {1, 3, 5}, X_j = {3}. We look through 1 and no constraint is found. Then look at 3 and see that the value in the X_j domain prevents X_i from having 3 in its domain.\n\n\nIf a change was made, then add all neighbors of X_i to the queue as arcs of (X_k, X_i) \n\ntime complexity = O(cd^3). c = number of arcs. d = size of domain\n\n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Backtrackin algorithms. Adding a depth first search mechanic that runs an inference alogrithm. \n\nInitially the algorithm guesses a value for a variable. Then runs inference. If that inference doesnt return failure, it guesses again. If that inference returns a failure, that node becomes a leaf and the algorithm backs up to a previous state and guesses another value \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* **Assignment** - putting a value on a varaible\n* **Consitent assignment** - an assignment that follows all contraints\n* **Partial assignment** - an assignment that leaves some variables unassigned\n* **Complete assignment** - all variables have a consistent assignment\n* **Minimum-remaining-values(mrv)** - choosing the variable that has the fewest legal values\n* **Degree heuristic** - select the variable that is involved in the largest number of constraints on other unassigned variabels\n* **Least-contraining-value** - select the value that provides the smallest reduction in choices for neighboring variables.\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 Logic:\nA model is an abstraction. If sentace a is true in model m, then m satisfies a.\n \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n \nnot: negation\n\nand: conjunction\n\nor: disjunction\n\nimplies: if-then. antecedent and conclusion. not a or B \n\niff: binconditional. Implies both ways\n\n## AIMA 7.5 Propositional Theorem Proving\n a and b are logically equivalent if they are true in the same set of models\n\nModus Podens: whenever a implies b, and a is given, we can infer b\n\nAnd Elimination: whenever we have A and B = true, we can infer A = true\n\nResolution:\n(P_1,1 V P_2,2 V P_3,1) A not P_2,2 = P_1,1, P_3,1\n\n \n\n## Module 7 Lecture Notes\n \nCNF:\n1. Eleminate biconditional\n2. Eliminate implications\n3. Move negations inwards and apply demorgans\n4. Distribute ors\n\n\nResolution algorithm:\n1. convert (KB and not(a)) into CNF\n2. Apply resolution rule to caluese\n3. Resolve every pair that contains complementary literals to produce new clauses\n4. If noew clause doesnt exist, add to set\n5. Continue until new new clauses can be added (KB does not entail a) or two clasuses resolve to yield the empty clause (KB does entail a)\n\n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}