{
  "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": "12472b49-02f4-498a-ce45-b23c6aa24c13"
      },
      "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": 14,
      "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": "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": 15,
      "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",
        "value alignment and provably beneficial to humans desired \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 = \"\"\" \n",
        "performance measures in place to deal with consequentialism, only depends on \n",
        "percept sequence to date, not omniscience.\n",
        " \"\"\"\n",
        "chapter2_3 = \"\"\" \n",
        "static vs dynamic: whethe env changing while agent is deciding\n",
        "episodic vs sequential: need to think ahead or not\n",
        "known vs unknown: how much of laws of env do we know\n",
        " \"\"\"\n",
        "chapter2_4 = \"\"\" \n",
        "factored rep (attributes to things) vs atomic rep vs structured rep (rrelations)\n",
        " \"\"\"\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\" : \"stuff agent's sensors are perceivnig\",\n",
        "\"other concept\" : \"your definitions here\",\n",
        "\"etc.\": \"your definitions here\",\n",
        "\"task environment\" : \"the problem to which the ratonial agent is the solution\", \n",
        "\"fully observable\" : \"environment that can have all relevant aspects of current state be fully perceived\", \n",
        "\"agent architecture\" : \"computing device + actuators + sensors\", \n",
        "\"reflex agent\" : \"responds to current precept\", \n",
        "\"model based agent\": \"uses sensor model and transition model to understand and act\", \n",
        "\"learning agent\" : \"learning el + performance el + critic + prob gen\", \n",
        "\"localist rep\" : \"one to one map from concept to mem location\", \n",
        "\"distrib rep\" : \"concetp mapped in many diff locations\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 16,
      "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": 878
        },
        "cellView": "form",
        "outputId": "2d6db37b-2e53-4c47-def0-c3538bd7678b"
      },
      "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": 17,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nvalue alignment and provably beneficial to humans desired \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 \nperformance measures in place to deal with consequentialism, only depends on \npercept sequence to date, not omniscience.\n \n\n## AIMA 2.3 The Nature of Environments\n \nstatic vs dynamic: whethe env changing while agent is deciding\nepisodic vs sequential: need to think ahead or not\nknown vs unknown: how much of laws of env do we know\n \n\n## AIMA 2.4 The Structure of Agents\n \nfactored rep (attributes to things) vs atomic rep vs structured rep (rrelations)\n \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** - stuff agent's sensors are perceivnig\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\n* **Task environment** - the problem to which the ratonial agent is the solution\n* **Fully observable** - environment that can have all relevant aspects of current state be fully perceived\n* **Agent architecture** - computing device + actuators + sensors\n* **Reflex agent** - responds to current precept\n* **Model based agent** - uses sensor model and transition model to understand and act\n* **Learning agent** - learning el + performance el + critic + prob gen\n* **Localist rep** - one to one map from concept to mem location\n* **Distrib rep** - concetp mapped in many diff locations\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\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 209
        },
        "outputId": "50125071-b05f-4070-bba1-f472f0bfb1bb"
      },
      "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": 19,
      "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** - your definition here\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",
        "goal formulation, problem formulation, search, execution\n",
        "problem has: \n",
        "state space/graph, initial states, goal states, actions, transition models, cost function\n",
        " \"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\" \n",
        "best first search is BFS and pick node with min val in eval function, late goal test \n",
        "of only checking goal state when popped off queue.\n",
        "sometimes check for cycles in constant time by seeing if one of ancestors is the \n",
        "node repeated.  \n",
        "\n",
        " \"\"\"\n",
        "chapter3_4 = \"\"\" \n",
        "time and space of BFS is O(b^d). \n",
        "dijstrkas/unif cost search is best first search with path cost as eval function\n",
        "bidirectional clutch (O^(d/2))\n",
        " \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",   \n",
        "\"open loop\" : \"doesn't use percepts carrying out solution, ok for perfect info\" \n",
        "}\n",
        "\n"
      ],
      "execution_count": 20,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 508
        },
        "outputId": "d4904f27-1245-4477-eeb6-e461446036cb"
      },
      "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": 21,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n \ngoal formulation, problem formulation, search, execution\nproblem has: \nstate space/graph, initial states, goal states, actions, transition models, cost function\n \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n \nbest first search is BFS and pick node with min val in eval function, late goal test \nof only checking goal state when popped off queue.\nsometimes check for cycles in constant time by seeing if one of ancestors is the \nnode repeated.  \n\n \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n \ntime and space of BFS is O(b^d). \ndijstrkas/unif cost search is best first search with path cost as eval function\nbidirectional clutch (O^(d/2))\n \n\n## Module 3 Lecture Notes\n Your summary here \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Open loop** - doesn't use percepts carrying out solution, ok for perfect info\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 is best first search that expands based on lowest h(n)\n",
        "\n",
        "A* uses h(n) + g(n) as eval function to expand. can also have weghted A*. \n",
        "itterative depth A*: , each iteration exhaustively searches an f-contour, \n",
        "finds a node just beyond that contour, and uses that node’s f-cost as the next contour. \n",
        "Recursive Best FS: \n",
        "As the recursion unwinds, RBFS replaces the f-value of each node along the \n",
        "path with a backed-up value—the best -value of its children. \n",
        "In this way, RBFS remembers the -value of the best leaf in the forgotten \n",
        "subtree and can therefore decide whether it’s worth reexpanding the subtree \n",
        "at some later time. Similar concept to alpha beta \n",
        "\n",
        "SMA* is A* up until run out of memory, then get rid of worst leaf. \n",
        "deletes oldest leaf tiebreaker\n",
        "\n",
        "Birectional heuristic search: \n",
        "f2(n) = max(2g(n), g(n) + h(n))\n",
        " \"\"\"\n",
        "chapter3_6 = \"\"\" \n",
        "precomputation of some optimal cos\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"admissible heuristic\" : \"never overestimates\",    \n",
        "\"consistency\" : \"h(n) <= c(n, a, n') + h(n')\", \n",
        "\"optimally efficient\" : \"expandas all nodes surely expanded by A* (could be in optmial solutioin)\",\n",
        "\"satisficing solutoi\" : \"inadmissable heurstic to prune more and be more efficent\", \n",
        "\"unbounded cost search\" : \"find any cost solutoin as long as fast\", \n",
        "\"bounded cost search\" : \"find solution with cost less than C\", \n",
        "\"bounded supoptimal search\" : \"solution guaranteed to be within constant factor of opt cost\", \n",
        "\"pattern database\" : \"stores solutioin costs for varety of states\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 22,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 580
        },
        "cellView": "form",
        "outputId": "62e8443c-2b1c-46cf-d879-d7708a5cdc38"
      },
      "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": 23,
      "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 is best first search that expands based on lowest h(n)\n\nA* uses h(n) + g(n) as eval function to expand. can also have weghted A*. \nitterative depth A*: , each iteration exhaustively searches an f-contour, \nfinds a node just beyond that contour, and uses that node’s f-cost as the next contour. \nRecursive Best FS: \nAs the recursion unwinds, RBFS replaces the f-value of each node along the \npath with a backed-up value—the best -value of its children. \nIn this way, RBFS remembers the -value of the best leaf in the forgotten \nsubtree and can therefore decide whether it’s worth reexpanding the subtree \nat some later time. Similar concept to alpha beta \n\nSMA* is A* up until run out of memory, then get rid of worst leaf. \ndeletes oldest leaf tiebreaker\n\nBirectional heuristic search: \nf2(n) = max(2g(n), g(n) + h(n))\n \n\n## AIMA Chapter 3.6 Heuristic Functions\n \nprecomputation of some optimal cos\n\n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Admissible heuristic** - never overestimates\n* **Consistency** - h(n) <= c(n, a, n') + h(n')\n* **Optimally efficient** - expandas all nodes surely expanded by A* (could be in optmial solutioin)\n* **Satisficing solutoi** - inadmissable heurstic to prune more and be more efficent\n* **Unbounded cost search** - find any cost solutoin as long as fast\n* **Bounded cost search** - find solution with cost less than C\n* **Bounded supoptimal search** - solution guaranteed to be within constant factor of opt cost\n* **Pattern database** - stores solutioin costs for varety of states\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 = \"\"\" \n",
        "perfect info, zero-sum, deterministic games. invovles initial state, \n",
        "goal state, actions, transistion model\n",
        "\n",
        " \"\"\"\n",
        "chapter5_2 = \"\"\"\n",
        "minmax performs depth first exploration of game tree. O(b^m) and space compl\n",
        "is O(bm) for gen actions all at once and O(m) for actions one at a time. \n",
        "alpha = min value up until so far. b = value of lowest value we have found at any \n",
        "choice point along path for min\n",
        "\n",
        "func alpha_beta: \n",
        "  player <= game.tomove(state)\n",
        "  value, move <0 maxvalue(game, state, -inf, +inf)\n",
        "  return move\n",
        "\n",
        "func max-value(game, state, alpha, beta)\n",
        "  if game.isterminal(state) then return game.utilit(state, plkyaer)\n",
        "  v <- -inf\n",
        "  for each a in game.actions(state) do\n",
        "  v2, a2 <- min-value(game, game.result(state, a), alpha, beta)\n",
        "  if v2 > v then\n",
        "    v, move <- v2, a\n",
        "    alpha <- max(alpha, v) (min(beta, v) for min)\n",
        "  if v >= beta (<= alpha for min), return v, move\n",
        "return v, move \n",
        "\n",
        "optimal O(b^(m/2))\n",
        " \"\"\"\n",
        "chapter5_3 = \"\"\" \n",
        "heuristic alpha beta cuts off early by treating some nodes as terminal \n",
        "by heuristic eval function which returns estimate of expected utility of a state. \n",
        "Should only be applied to quiescent states (no pending move that would swing\n",
        "value of state alot). quiscence search restricted to only consider some scenarios. \n",
        "horizon effect happens when facing opponents move that has serious damage but can\n",
        "temp be avoided w delay (but shouldn't neccessarily be delay!!). singular extension\n",
        "allow to extend search every now and then to avoid this to get moves clearly better\n",
        "\n",
        "\"\"\"\n",
        "chapter5_5 = \"\"\" \n",
        "Expectimax takes O(b^m n^m) time, n number of dice rolls. Can get bounds on \n",
        "averages if utility is bounded. \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 = \"\"\"\n",
        "orderability, transitivity, continuty \n",
        "\"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"game tree\" : \"search tree that follows all sequences of moves to ending states\", \n",
        "\"type a strategy\" : \"wide but shallow portion of game tree explored\", \n",
        "\"type b strat\" : \"deep but narrow portion of tree explored\" , \n",
        "\"beam search\" : \"consider only beam of n best moves on a ply during forward pruning\", \n",
        "\"late move reduction\" : \"reduce depth of search for late moves if moves ordering done well\", \n",
        "\"substitutabilty\" : \": If an agent is indifferent between two lotteries and , then is indifferent between two more complex lotteries are the same except that B is substituted for A in one\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 24,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 990
        },
        "outputId": "3f002d67-76b8-486a-f447-25117a204f75"
      },
      "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": 25,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'substitutabilty' is too long!\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n \nperfect info, zero-sum, deterministic games. invovles initial state, \ngoal state, actions, transistion model\n\n \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n\nminmax performs depth first exploration of game tree. O(b^m) and space compl\nis O(bm) for gen actions all at once and O(m) for actions one at a time. \nalpha = min value up until so far. b = value of lowest value we have found at any \nchoice point along path for min\n\nfunc alpha_beta: \n  player <= game.tomove(state)\n  value, move <0 maxvalue(game, state, -inf, +inf)\n  return move\n\nfunc max-value(game, state, alpha, beta)\n  if game.isterminal(state) then return game.utilit(state, plkyaer)\n  v <- -inf\n  for each a in game.actions(state) do\n  v2, a2 <- min-value(game, game.result(state, a), alpha, beta)\n  if v2 > v then\n    v, move <- v2, a\n    alpha <- max(alpha, v) (min(beta, v) for min)\n  if v >= beta (<= alpha for min), return v, move\nreturn v, move \n\noptimal O(b^(m/2))\n \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n \nheuristic alpha beta cuts off early by treating some nodes as terminal \nby heuristic eval function which returns estimate of expected utility of a state. \nShould only be applied to quiescent states (no pending move that would swing\nvalue of state alot). quiscence search restricted to only consider some scenarios. \nhorizon effect happens when facing opponents move that has serious damage but can\ntemp be avoided w delay (but shouldn't neccessarily be delay!!). singular extension\nallow to extend search every now and then to avoid this to get moves clearly better\n\n\n\n## AIMA Chapter 5.5 Stochastic Games\n \nExpectimax takes O(b^m n^m) time, n number of dice rolls. Can get bounds on \naverages if utility is bounded. \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\norderability, transitivity, continuty \n\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* **Game tree** - search tree that follows all sequences of moves to ending states\n* **Type a strategy** - wide but shallow portion of game tree explored\n* **Type b strat** - deep but narrow portion of tree explored\n* **Beam search** - consider only beam of n best moves on a ply during forward pruning\n* **Late move reduction** - reduce depth of search for late moves if moves ordering done well\n* **Substitutabilty** - : If an agent is indifferent between two lotteries and , then is indifferent between two more complex lotteries are the same except that B is substituted for A in one\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qVSQhTVSyYYO"
      },
      "source": [
        "#Module 6 - \"Constraint Satisfaction Problems\""
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wm4mfW82yaRH"
      },
      "source": [
        "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
        "chapter6_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_5 = \"\"\" \n",
        "Tree with topo sort takes O(nd^2)\n",
        "\n",
        "Cutset conditioning: \n",
        "- remove and assign S (cycle cuset) such that remaining tree\n",
        "- do for all values of s and solve tree until consistent overall\n",
        "O(d^c (n-c)d^2) if cycle cutset has size c\n",
        "\n",
        "Tree decomp O(nd^{w+1}) but now domain is tuples \n",
        "must satisfy: \n",
        "- every var in org prob appears >0 of tree nodes\n",
        "0 two vars connect by constraint in org, must appear toegerh in >0 tree nodes\n",
        "- varible in two nodes in tree, must appear in every node along path connecting thos nodes\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\"\n",
        "\n",
        "Problem structure: \n",
        " Suppose each\n",
        "Then there are subproblems, each of which takes at most work to solve, where is the size of the domain. Hence, the total work is \n",
        "\n",
        "AC-3: O(cd^3)\n",
        "\n",
        "while queue is not empty do: \n",
        "  (Xi, Xj) <- pop(queue)\n",
        "  if revise(csp, xi, xj) then (revise reduces domain of xi)\n",
        "    if size Di = 0 return false\n",
        "    for each xk in xi.neighbors - xj do\n",
        "      add (xk, xi) to queue\n",
        "\n",
        "\n",
        "The algorithm called MAC (for Maintaining Arc Consistency) \n",
        "detects inconsistencies like this. After a variable Xi is assigned a value, calls AC-3, but instead of a queue of all arcs  in the CSP, \n",
        "we start with only the arcs (Xi, Xj) for all Xj that are unassigned variables that are neighbors of \n",
        "Xi. \n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"parital assignment\" : \"leave some variables unassigned\", \n",
        "\"partial solution\" : \"partial assignemnt that is consistent\" ,\n",
        "\"global constraint\" : \"involves arbitrary number of elements\", \n",
        "\"node consistent\" : \"variable domain satisfies all unary cocnstraints\", \n",
        "\"arc constraint\" :\"domain satisfies all binary constaints of variable\", \n",
        "\"path consistency\" : \"xi and xj consistent and an assigment to xm that satisfies xi,xm and xm,xj (m middle)\", \n",
        "\"k-consistency\" : \"any set of k-1 variables and any consistent assignemnt, any kth variale can be assigneed\", \n",
        "\"degree heurisitc\" : \"pick variable to guess involves in most constraints\", \n",
        "\"MVR\" : \"pick variable to guess with smallest domain\", \n",
        "\"forward checking\" : \"establish arc consistency with neighbors of assigned variable\", \n",
        "\"tree width\" : \"one less than size of largest node in tree decomp. min width along all tree decomp\", \n",
        "\"symmetry-breaking constraint\" : \"constraint to get rid of value symmetry\"\n",
        "}\n"
      ],
      "execution_count": 26,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 957
        },
        "outputId": "4aba5ff1-7b94-4e31-fcd5-42074706e986"
      },
      "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": 27,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n \nTree with topo sort takes O(nd^2)\n\nCutset conditioning: \n- remove and assign S (cycle cuset) such that remaining tree\n- do for all values of s and solve tree until consistent overall\nO(d^c (n-c)d^2) if cycle cutset has size c\n\nTree decomp O(nd^{w+1}) but now domain is tuples \nmust satisfy: \n- every var in org prob appears >0 of tree nodes\n0 two vars connect by constraint in org, must appear toegerh in >0 tree nodes\n- varible in two nodes in tree, must appear in every node along path connecting thos nodes\n\n\n\n## Module 6 Lecture Notes\n\n\nProblem structure: \n Suppose each\nThen there are subproblems, each of which takes at most work to solve, where is the size of the domain. Hence, the total work is \n\nAC-3: O(cd^3)\n\nwhile queue is not empty do: \n  (Xi, Xj) <- pop(queue)\n  if revise(csp, xi, xj) then (revise reduces domain of xi)\n    if size Di = 0 return false\n    for each xk in xi.neighbors - xj do\n      add (xk, xi) to queue\n\n\nThe algorithm called MAC (for Maintaining Arc Consistency) \ndetects inconsistencies like this. After a variable Xi is assigned a value, calls AC-3, but instead of a queue of all arcs  in the CSP, \nwe start with only the arcs (Xi, Xj) for all Xj that are unassigned variables that are neighbors of \nXi. \n\n \n\n## Module 6 Definitions\n* **Parital assignment** - leave some variables unassigned\n* **Partial solution** - partial assignemnt that is consistent\n* **Global constraint** - involves arbitrary number of elements\n* **Node consistent** - variable domain satisfies all unary cocnstraints\n* **Arc constraint** - domain satisfies all binary constaints of variable\n* **Path consistency** - xi and xj consistent and an assigment to xm that satisfies xi,xm and xm,xj (m middle)\n* **K-consistency** - any set of k-1 variables and any consistent assignemnt, any kth variale can be assigneed\n* **Degree heurisitc** - pick variable to guess involves in most constraints\n* **Mvr** - pick variable to guess with smallest domain\n* **Forward checking** - establish arc consistency with neighbors of assigned variable\n* **Tree width** - one less than size of largest node in tree decomp. min width along all tree decomp\n* **Symmetry-breaking constraint** - constraint to get rid of value symmetry\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\"\n",
        "while queue is not empty do \n",
        "  p <- pop(queue)\n",
        "  if p = q then return true\n",
        "  if inferredd[p] = false then \n",
        "    inferred[p] = true \n",
        "    for each clause c in KB where p is in c.premise do \n",
        "      decrement count[c]\n",
        "      if count[c] = 0 then add c.conclusion to queue\n",
        "return false \n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" \n",
        "knowledge diff than prob solve agents bc more depth in rep of states. Prob \n",
        "agents only have atomic states \"navigate to kassel\" vs \"take to habitable planet w \n",
        "water\". M(a) set of all models of a (a is true in model m). a entails b iff \n",
        "M(a) is a subset of M(b). Entailment can be used to derive conclusions. KB |-i a \n",
        "means a is derived from KB by algorithm i. \n",
        "\n",
        "Propositional logic: \n",
        "Complex sentences from simpler ones using prens and logical connecives of \n",
        "propositional symbols. \n",
        "\n",
        "Logical equiv: \n",
        "a implies b = not a or b\n",
        "(a and b) or y = (a and b) or (a and y)\n",
        "(a or b) and y = (a or b) and (a or y)\n",
        "\n",
        "monotoncity implies soundness\n",
        "\n",
        "CNF: \n",
        "- elmnate birectional\n",
        "- elinimate imlies\n",
        "- move negation inwards\n",
        "- distribute ors and ands\n",
        "\n",
        "\n",
        "Resoluion algo: \n",
        "To show KB entails a, show KB and not a is unsatisfiable. \n",
        "- convert KB nd not a into CNF\n",
        "- apply reso rule to esulting clauses\n",
        "- resoluve pair \n",
        "Continue until\n",
        "- no new claue added, KB not entail a\n",
        "- two caluess yeidl empty clause, KB does entail a \n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"knowledge based agent\" : \"use process of reasoning over internal rep of world/knowledge to decide\", \n",
        "\"knowledge base\" : \"set of sentences that contain facts abt world in some rep language\",\n",
        "\"axiom\" : \"given sentence in knowledge base\", \n",
        "\"derived sentence\" : \"new sentence derived from axioms/otherr sentences via INFERENCE\", \n",
        "\"model\" :  \"rep of world have set of truth values where each sentence true/false \", \n",
        "\"model checking\" : \"process of checking all possible models comp with current KB\", \n",
        "\"propositional symbols\" : \"state for statements that can be true or false\", \n",
        "\"soundness\" : \"inference algo derives only entailed sentences\", \n",
        "\"complete\" : \"derive all sentences that are entailed\", \n",
        "\"unit resolution\" : \"have disjunction and not one of them so disjunction of rest can be inferred\", \n",
        "\"definte clause\" : \"disjuncctioin wherre exactly one positve\", \n",
        "\"horn clause\" : \"at most one positve in a disjunction\", \n",
        "\"forward chaning\" : \"data driven reasoning: add premses and apply algo to get new conclusoins\", \n",
        "\"backward chaning\" : \"goal reasoning: backwarrd from query, if find implication ttrue then q true \"\n",
        "\"\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 28,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "9f4e79d8-9fb4-40b0-a77c-be9312906638"
      },
      "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": 29,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n\nwhile queue is not empty do \n  p <- pop(queue)\n  if p = q then return true\n  if inferredd[p] = false then \n    inferred[p] = true \n    for each clause c in KB where p is in c.premise do \n      decrement count[c]\n      if count[c] = 0 then add c.conclusion to queue\nreturn false \n\n\n\n## Module 7 Lecture Notes\n \nknowledge diff than prob solve agents bc more depth in rep of states. Prob \nagents only have atomic states \"navigate to kassel\" vs \"take to habitable planet w \nwater\". M(a) set of all models of a (a is true in model m). a entails b iff \nM(a) is a subset of M(b). Entailment can be used to derive conclusions. KB |-i a \nmeans a is derived from KB by algorithm i. \n\nPropositional logic: \nComplex sentences from simpler ones using prens and logical connecives of \npropositional symbols. \n\nLogical equiv: \na implies b = not a or b\n(a and b) or y = (a and b) or (a and y)\n(a or b) and y = (a or b) and (a or y)\n\nmonotoncity implies soundness\n\nCNF: \n- elmnate birectional\n- elinimate imlies\n- move negation inwards\n- distribute ors and ands\n\n\nResoluion algo: \nTo show KB entails a, show KB and not a is unsatisfiable. \n- convert KB nd not a into CNF\n- apply reso rule to esulting clauses\n- resoluve pair \nContinue until\n- no new claue added, KB not entail a\n- two caluess yeidl empty clause, KB does entail a \n\n \n\n## Module 7 Definitions\n* **Knowledge based agent** - use process of reasoning over internal rep of world/knowledge to decide\n* **Knowledge base** - set of sentences that contain facts abt world in some rep language\n* **Axiom** - given sentence in knowledge base\n* **Derived sentence** - new sentence derived from axioms/otherr sentences via INFERENCE\n* **Model** - rep of world have set of truth values where each sentence true/false \n* **Model checking** - process of checking all possible models comp with current KB\n* **Propositional symbols** - state for statements that can be true or false\n* **Soundness** - inference algo derives only entailed sentences\n* **Complete** - derive all sentences that are entailed\n* **Unit resolution** - have disjunction and not one of them so disjunction of rest can be inferred\n* **Definte clause** - disjuncctioin wherre exactly one positve\n* **Horn clause** - at most one positve in a disjunction\n* **Forward chaning** - data driven reasoning: add premses and apply algo to get new conclusoins\n* **Backward chaning** - goal reasoning: backwarrd from query, if find implication ttrue then q true \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": "79c1fb7e-26d7-42c0-e212-befe96c6c9b1"
      },
      "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": 30,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nvalue alignment and provably beneficial to humans desired \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 \nperformance measures in place to deal with consequentialism, only depends on \npercept sequence to date, not omniscience.\n \n\n## AIMA 2.3 The Nature of Environments\n \nstatic vs dynamic: whethe env changing while agent is deciding\nepisodic vs sequential: need to think ahead or not\nknown vs unknown: how much of laws of env do we know\n \n\n## AIMA 2.4 The Structure of Agents\n \nfactored rep (attributes to things) vs atomic rep vs structured rep (rrelations)\n \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** - stuff agent's sensors are perceivnig\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\n* **Task environment** - the problem to which the ratonial agent is the solution\n* **Fully observable** - environment that can have all relevant aspects of current state be fully perceived\n* **Agent architecture** - computing device + actuators + sensors\n* **Reflex agent** - responds to current precept\n* **Model based agent** - uses sensor model and transition model to understand and act\n* **Learning agent** - learning el + performance el + critic + prob gen\n* **Localist rep** - one to one map from concept to mem location\n* **Distrib rep** - concetp mapped in many diff locations\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Your summary here \n\n## Module 2 Definitions\n* **Mutability** - your definition here\n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n \ngoal formulation, problem formulation, search, execution\nproblem has: \nstate space/graph, initial states, goal states, actions, transition models, cost function\n \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n \nbest first search is BFS and pick node with min val in eval function, late goal test \nof only checking goal state when popped off queue.\nsometimes check for cycles in constant time by seeing if one of ancestors is the \nnode repeated.  \n\n \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n \ntime and space of BFS is O(b^d). \ndijstrkas/unif cost search is best first search with path cost as eval function\nbidirectional clutch (O^(d/2))\n \n\n## Module 3 Lecture Notes\n Your summary here \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Open loop** - doesn't use percepts carrying out solution, ok for perfect info\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n \ngreedy best first search is best first search that expands based on lowest h(n)\n\nA* uses h(n) + g(n) as eval function to expand. can also have weghted A*. \nitterative depth A*: , each iteration exhaustively searches an f-contour, \nfinds a node just beyond that contour, and uses that node’s f-cost as the next contour. \nRecursive Best FS: \nAs the recursion unwinds, RBFS replaces the f-value of each node along the \npath with a backed-up value—the best -value of its children. \nIn this way, RBFS remembers the -value of the best leaf in the forgotten \nsubtree and can therefore decide whether it’s worth reexpanding the subtree \nat some later time. Similar concept to alpha beta \n\nSMA* is A* up until run out of memory, then get rid of worst leaf. \ndeletes oldest leaf tiebreaker\n\nBirectional heuristic search: \nf2(n) = max(2g(n), g(n) + h(n))\n \n\n## AIMA Chapter 3.6 Heuristic Functions\n \nprecomputation of some optimal cos\n\n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Admissible heuristic** - never overestimates\n* **Consistency** - h(n) <= c(n, a, n') + h(n')\n* **Optimally efficient** - expandas all nodes surely expanded by A* (could be in optmial solutioin)\n* **Satisficing solutoi** - inadmissable heurstic to prune more and be more efficent\n* **Unbounded cost search** - find any cost solutoin as long as fast\n* **Bounded cost search** - find solution with cost less than C\n* **Bounded supoptimal search** - solution guaranteed to be within constant factor of opt cost\n* **Pattern database** - stores solutioin costs for varety of states\n\n\n## WARNING: Your definition of 'substitutabilty' is too long!\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n \nperfect info, zero-sum, deterministic games. invovles initial state, \ngoal state, actions, transistion model\n\n \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n\nminmax performs depth first exploration of game tree. O(b^m) and space compl\nis O(bm) for gen actions all at once and O(m) for actions one at a time. \nalpha = min value up until so far. b = value of lowest value we have found at any \nchoice point along path for min\n\nfunc alpha_beta: \n  player <= game.tomove(state)\n  value, move <0 maxvalue(game, state, -inf, +inf)\n  return move\n\nfunc max-value(game, state, alpha, beta)\n  if game.isterminal(state) then return game.utilit(state, plkyaer)\n  v <- -inf\n  for each a in game.actions(state) do\n  v2, a2 <- min-value(game, game.result(state, a), alpha, beta)\n  if v2 > v then\n    v, move <- v2, a\n    alpha <- max(alpha, v) (min(beta, v) for min)\n  if v >= beta (<= alpha for min), return v, move\nreturn v, move \n\noptimal O(b^(m/2))\n \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n \nheuristic alpha beta cuts off early by treating some nodes as terminal \nby heuristic eval function which returns estimate of expected utility of a state. \nShould only be applied to quiescent states (no pending move that would swing\nvalue of state alot). quiscence search restricted to only consider some scenarios. \nhorizon effect happens when facing opponents move that has serious damage but can\ntemp be avoided w delay (but shouldn't neccessarily be delay!!). singular extension\nallow to extend search every now and then to avoid this to get moves clearly better\n\n\n\n## AIMA Chapter 5.5 Stochastic Games\n \nExpectimax takes O(b^m n^m) time, n number of dice rolls. Can get bounds on \naverages if utility is bounded. \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\norderability, transitivity, continuty \n\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* **Game tree** - search tree that follows all sequences of moves to ending states\n* **Type a strategy** - wide but shallow portion of game tree explored\n* **Type b strat** - deep but narrow portion of tree explored\n* **Beam search** - consider only beam of n best moves on a ply during forward pruning\n* **Late move reduction** - reduce depth of search for late moves if moves ordering done well\n* **Substitutabilty** - : If an agent is indifferent between two lotteries and , then is indifferent between two more complex lotteries are the same except that B is substituted for A in one\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n \nTree with topo sort takes O(nd^2)\n\nCutset conditioning: \n- remove and assign S (cycle cuset) such that remaining tree\n- do for all values of s and solve tree until consistent overall\nO(d^c (n-c)d^2) if cycle cutset has size c\n\nTree decomp O(nd^{w+1}) but now domain is tuples \nmust satisfy: \n- every var in org prob appears >0 of tree nodes\n0 two vars connect by constraint in org, must appear toegerh in >0 tree nodes\n- varible in two nodes in tree, must appear in every node along path connecting thos nodes\n\n\n\n## Module 6 Lecture Notes\n\n\nProblem structure: \n Suppose each\nThen there are subproblems, each of which takes at most work to solve, where is the size of the domain. Hence, the total work is \n\nAC-3: O(cd^3)\n\nwhile queue is not empty do: \n  (Xi, Xj) <- pop(queue)\n  if revise(csp, xi, xj) then (revise reduces domain of xi)\n    if size Di = 0 return false\n    for each xk in xi.neighbors - xj do\n      add (xk, xi) to queue\n\n\nThe algorithm called MAC (for Maintaining Arc Consistency) \ndetects inconsistencies like this. After a variable Xi is assigned a value, calls AC-3, but instead of a queue of all arcs  in the CSP, \nwe start with only the arcs (Xi, Xj) for all Xj that are unassigned variables that are neighbors of \nXi. \n\n \n\n## Module 6 Definitions\n* **Parital assignment** - leave some variables unassigned\n* **Partial solution** - partial assignemnt that is consistent\n* **Global constraint** - involves arbitrary number of elements\n* **Node consistent** - variable domain satisfies all unary cocnstraints\n* **Arc constraint** - domain satisfies all binary constaints of variable\n* **Path consistency** - xi and xj consistent and an assigment to xm that satisfies xi,xm and xm,xj (m middle)\n* **K-consistency** - any set of k-1 variables and any consistent assignemnt, any kth variale can be assigneed\n* **Degree heurisitc** - pick variable to guess involves in most constraints\n* **Mvr** - pick variable to guess with smallest domain\n* **Forward checking** - establish arc consistency with neighbors of assigned variable\n* **Tree width** - one less than size of largest node in tree decomp. min width along all tree decomp\n* **Symmetry-breaking constraint** - constraint to get rid of value symmetry\n\n\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n\nwhile queue is not empty do \n  p <- pop(queue)\n  if p = q then return true\n  if inferredd[p] = false then \n    inferred[p] = true \n    for each clause c in KB where p is in c.premise do \n      decrement count[c]\n      if count[c] = 0 then add c.conclusion to queue\nreturn false \n\n\n\n## Module 7 Lecture Notes\n \nknowledge diff than prob solve agents bc more depth in rep of states. Prob \nagents only have atomic states \"navigate to kassel\" vs \"take to habitable planet w \nwater\". M(a) set of all models of a (a is true in model m). a entails b iff \nM(a) is a subset of M(b). Entailment can be used to derive conclusions. KB |-i a \nmeans a is derived from KB by algorithm i. \n\nPropositional logic: \nComplex sentences from simpler ones using prens and logical connecives of \npropositional symbols. \n\nLogical equiv: \na implies b = not a or b\n(a and b) or y = (a and b) or (a and y)\n(a or b) and y = (a or b) and (a or y)\n\nmonotoncity implies soundness\n\nCNF: \n- elmnate birectional\n- elinimate imlies\n- move negation inwards\n- distribute ors and ands\n\n\nResoluion algo: \nTo show KB entails a, show KB and not a is unsatisfiable. \n- convert KB nd not a into CNF\n- apply reso rule to esulting clauses\n- resoluve pair \nContinue until\n- no new claue added, KB not entail a\n- two caluess yeidl empty clause, KB does entail a \n\n \n\n## Module 7 Definitions\n* **Knowledge based agent** - use process of reasoning over internal rep of world/knowledge to decide\n* **Knowledge base** - set of sentences that contain facts abt world in some rep language\n* **Axiom** - given sentence in knowledge base\n* **Derived sentence** - new sentence derived from axioms/otherr sentences via INFERENCE\n* **Model** - rep of world have set of truth values where each sentence true/false \n* **Model checking** - process of checking all possible models comp with current KB\n* **Propositional symbols** - state for statements that can be true or false\n* **Soundness** - inference algo derives only entailed sentences\n* **Complete** - derive all sentences that are entailed\n* **Unit resolution** - have disjunction and not one of them so disjunction of rest can be inferred\n* **Definte clause** - disjuncctioin wherre exactly one positve\n* **Horn clause** - at most one positve in a disjunction\n* **Forward chaning** - data driven reasoning: add premses and apply algo to get new conclusoins\n* **Backward chaning** - goal reasoning: backwarrd from query, if find implication ttrue then q true \n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}