{
  "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": "cd970d4a-68e1-476a-a449-1fb7477dfa29"
      },
      "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": 1,
      "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": "70866007-600a-4acb-cc31-99db7ef9526f"
      },
      "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": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = True"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GZZXyrV-xuAp"
      },
      "source": [
        "# Module 1 - Intro to AI"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y2NfE1CKxzS-",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "137ebe12-963b-43f5-ab50-fb50e5693fdf"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
        "\n",
        "chapter1_1 = \"\"\" Chapter 1.1 summary. \"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter27_2 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\"\n",
        "We start this unit by talking about AI in Philosohpy. We talked about Rene Descartes \n",
        "(\"I think therefore I am\"), Alan Turing (the Turing Test), John Searle, Daniel Dennet \n",
        "(Brain in a Vat).\n",
        "\n",
        "There are four views of AI: to think huumanly, think rationally, act huumanly, act rationally.\n",
        "\n",
        "For an agent, the agent function takes in a sequence of percepts and outputs a sequence of actions.\n",
        "This is different from the agent program which runs on the physical architecture to \n",
        "produce the agent function. Examples of agents are humans, robots, softbots, thermostats, etc.\n",
        "\n",
        "AI is concerned with consequentialism.\n",
        "\n",
        "We then talked about rational agents, where a rational agent is one where for each \n",
        "possible percept, the agent selects the action a which maximizes its expected value of the\n",
        "performance measure since it doesnt know what the outcome will be.\n",
        "\n",
        "We continued about Task environments:\n",
        "Use PEAS ==> Performance measure, environment, actuators, sensors\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 1.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module1_definitions = {\n",
        "\"agent\" : \"anything that can perceive and act in an environment\",\n",
        "\"percept\" : \"your definitions here\",\n",
        "\"other concept\" : \"your definitions here\",\n",
        "\"etc.\": \"your definitions here\",\n",
        "}\n",
        "\n",
        "length = len(module1_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 144 words long, so you could write an additional 1856 words.\n"
          ]
        }
      ]
    },
    {
      "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": 925
        },
        "cellView": "form",
        "outputId": "045f6150-43ea-468c-cec4-14f8ba12600c"
      },
      "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": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n\nWe start this unit by talking about AI in Philosohpy. We talked about Rene Descartes \n(\"I think therefore I am\"), Alan Turing (the Turing Test), John Searle, Daniel Dennet \n(Brain in a Vat).\n\nThere are four views of AI: to think huumanly, think rationally, act huumanly, act rationally.\n\nFor an agent, the agent function takes in a sequence of percepts and outputs a sequence of actions.\nThis is different from the agent program which runs on the physical architecture to \nproduce the agent function. Examples of agents are humans, robots, softbots, thermostats, etc.\n\nAI is concerned with consequentialism.\n\nWe then talked about rational agents, where a rational agent is one where for each \npossible percept, the agent selects the action a which maximizes its expected value of the\nperformance measure since it doesnt know what the outcome will be.\n\nWe continued about Task environments:\nUse PEAS ==> Performance measure, environment, actuators, sensors\n\n\n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - your definitions here\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9xRbdqDox2zD"
      },
      "source": [
        "#Module 2 - Python"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DpBvu7EMx7sy",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b732beb1-a151-4b57-93dc-a4432e1c9932"
      },
      "source": [
        "# No readings for this module.  Instead you can summarize the lecture instead.\n",
        "\n",
        "# Lecture notes \n",
        "module2_lecture_notes = \"\"\"\n",
        "In python, all data are treated as objects. Python is also strongly typed, meaning\n",
        "every object has a fixed type. Python also has dynamic typing, meaning variable \n",
        "types are automatically assigned. Strings are immutable. Tuples are immutable. \n",
        "Lists are mutable.\n",
        "\n",
        "== checks the value\n",
        "is checks if the objects point to the same location in memory\n",
        "\n",
        "|Slicing|\n",
        "take this example: tuple_t = (1,2,3,4,5)\n",
        "tuple_t[1:4] ==> (2,3,4)\n",
        "tuple_t[1:-1] ==> (2,3,4)\n",
        "tuple_t[1:-1:2] ==> (2,4)\n",
        "tuple_t[:2] ==> (1,2)\n",
        "tuple_t[2:] ==> (3,4,5)\n",
        "\n",
        "|List Operations|\n",
        "take this example: list_li = [1,2,3,4,5]\n",
        "list_li.insert(2,6) ==> [1,2,6,3,4,5]\n",
        "list_li.index(5) ==> 4 #first occurance\n",
        "list_li.count(5) ==> 1 #num occurances\n",
        "list_li.remove(5) ==> [1,2,3,4]\n",
        "list_li.reverse() ==>  [5,4,3,2,1]\n",
        "list_li.sort() ==>  [1,2,3,4,5]\n",
        "\n",
        "|String Operations|\n",
        ".capitalize()\n",
        ".upper()\n",
        ".strip()\n",
        ".split\n",
        "\n",
        "|String Operations|\n",
        ".keys()\n",
        ".values()\n",
        ".items() #returns a list of items\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "}\n",
        "\n",
        "length = len(module2_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 99 words long, so you could write an additional 1901 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 409
        },
        "outputId": "e2f1c041-0907-4d6d-f92c-1299f48fa87b"
      },
      "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": 7,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n\nIn python, all data are treated as objects. Python is also strongly typed, meaning\nevery object has a fixed type. Python also has dynamic typing, meaning variable \ntypes are automatically assigned. Strings are immutable. Tuples are immutable. \nLists are mutable.\n\n== checks the value\nis checks if the objects point to the same location in memory\n\n|Slicing|\ntake this example: tuple_t = (1,2,3,4,5)\ntuple_t[1:4] ==> (2,3,4)\ntuple_t[1:-1] ==> (2,3,4)\ntuple_t[1:-1:2] ==> (2,4)\ntuple_t[:2] ==> (1,2)\ntuple_t[2:] ==> (3,4,5)\n\n|List Operations|\ntake this example: list_li = [1,2,3,4,5]\nlist_li.insert(2,6) ==> [1,2,6,3,4,5]\nlist_li.index(5) ==> 4 #first occurance\nlist_li.count(5) ==> 1 #num occurances\nlist_li.remove(5) ==> [1,2,3,4]\nlist_li.reverse() ==>  [5,4,3,2,1]\nlist_li.sort() ==>  [1,2,3,4,5]\n\n|String Operations|\n.capitalize()\n.upper()\n.strip()\n.split\n\n|String Operations|\n.keys()\n.values()\n.items() #returns a list of items\n\n\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",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "bbc602f6-2533-4649-d8df-6e9932adbb69"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
        "chapter3_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" \n",
        "\n",
        "The task environment can change solutions. \n",
        "A task environment that's FULLY OBSERVABLE, DETERMINISTIC, AND KNOWN ENVIRONMENT\n",
        "implies a solution is a set path of actions. The opposite of this is PARTIALLY\n",
        "OBSERVABLE AND NONDETERMINISTIC environments. \n",
        "\n",
        "A problem is defined by 6 things: a set of STATES, an INITIAL \n",
        "STATE, a set of ACTIONS, a TRANSITION MODEL, an additive PATH COST, and a \n",
        "viable GOAL TEST/STATE. The formulation of this problem greatly affects the\n",
        "speed of the search.\n",
        "\n",
        "Basic Search Algorithms:\n",
        "First we have Tree Search. In this you do not check for redundant paths. This means\n",
        "that we can have repeated stated which means the poblem becomes exponential. We\n",
        "solve this by modifying tree search into gaph search. Here, we check if a node has\n",
        "been visited (check for redundant paths).\n",
        "\n",
        "Uninformed Search Strategies:\n",
        "NO HEURISTICS. To formulate these strategies, we typically use a queue to help us \n",
        "(LIFO, FIFO, piority). How do we evaluate whether a strategy is good? We have several\n",
        "criteria for this: Complete (always finds a solution), Optimal (always finds the \n",
        "solution with lowest cost first), Time Complexity, Space Complexity. For Time and Space,\n",
        "we use these vars: b (max number of children at each node), d (shallowest goal depth),\n",
        "m (max length of path in state space), l (the depth limit of the tree).\n",
        "\n",
        "BFS: we use frontiers as FIFO queues.\n",
        "Complete ==> Yes!\n",
        "Optimal ==> Yes!\n",
        "Time ==> O(b^d)\n",
        "Space ==> O(b^d)\n",
        "\n",
        "DFS: we use frontiers as LIFO queues.\n",
        "Complete ==> No\n",
        "Optimal ==> No\n",
        "Time ==> O(b^m)\n",
        "Space ==> O(b*m)!\n",
        "\n",
        "These are not great, so we improve upon BFS and DFS with Iterative deepending search\n",
        "and Depth-Limited Search. \n",
        "\n",
        "DLS:\n",
        "Complete ==> No\n",
        "Optimal ==> No\n",
        "Time ==> O(b^l)\n",
        "Space ==> O(b*l)!\n",
        "\n",
        "IDS:\n",
        "Complete ==> YES\n",
        "Optimal ==> YES\n",
        "Time ==> O(b^d)\n",
        "Space ==> O(b*d)!\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",\n",
        "\"reflex agent\" : \"an agent that ignores the 'percept' history and only acts on what it sees at a given state\",\n",
        "\"solution\" : \"a path of actions from the start state to the goal state\",\n",
        "\"optimal solution\" : \"the solution with the lowest path cost\",\n",
        "\"state space\" : \"all states\",\n",
        "\"frontier\" : \"the next available set of 'expandable' states at the current moment in time for a search\",\n",
        "}\n",
        "\n",
        "length = len(module3_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 268 words long, so you could write an additional 1732 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 913
        },
        "outputId": "686abb09-7390-499d-8176-a2df7c0b47f4"
      },
      "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": 9,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Your summary here \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Your summary here \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n \n\nThe task environment can change solutions. \nA task environment that's FULLY OBSERVABLE, DETERMINISTIC, AND KNOWN ENVIRONMENT\nimplies a solution is a set path of actions. The opposite of this is PARTIALLY\nOBSERVABLE AND NONDETERMINISTIC environments. \n\nA problem is defined by 6 things: a set of STATES, an INITIAL \nSTATE, a set of ACTIONS, a TRANSITION MODEL, an additive PATH COST, and a \nviable GOAL TEST/STATE. The formulation of this problem greatly affects the\nspeed of the search.\n\nBasic Search Algorithms:\nFirst we have Tree Search. In this you do not check for redundant paths. This means\nthat we can have repeated stated which means the poblem becomes exponential. We\nsolve this by modifying tree search into gaph search. Here, we check if a node has\nbeen visited (check for redundant paths).\n\nUninformed Search Strategies:\nNO HEURISTICS. To formulate these strategies, we typically use a queue to help us \n(LIFO, FIFO, piority). How do we evaluate whether a strategy is good? We have several\ncriteria for this: Complete (always finds a solution), Optimal (always finds the \nsolution with lowest cost first), Time Complexity, Space Complexity. For Time and Space,\nwe use these vars: b (max number of children at each node), d (shallowest goal depth),\nm (max length of path in state space), l (the depth limit of the tree).\n\nBFS: we use frontiers as FIFO queues.\nComplete ==> Yes!\nOptimal ==> Yes!\nTime ==> O(b^d)\nSpace ==> O(b^d)\n\nDFS: we use frontiers as LIFO queues.\nComplete ==> No\nOptimal ==> No\nTime ==> O(b^m)\nSpace ==> O(b*m)!\n\nThese are not great, so we improve upon BFS and DFS with Iterative deepending search\nand Depth-Limited Search. \n\nDLS:\nComplete ==> No\nOptimal ==> No\nTime ==> O(b^l)\nSpace ==> O(b*l)!\n\nIDS:\nComplete ==> YES\nOptimal ==> YES\nTime ==> O(b^d)\nSpace ==> O(b*d)!\n\n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Reflex agent** - an agent that ignores the 'percept' history and only acts on what it sees at a given state\n* **Solution** - a path of actions from the start state to the goal state\n* **Optimal solution** - the solution with the lowest path cost\n* **State space** - all states\n* **Frontier** - the next available set of 'expandable' states at the current moment in time for a search\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WHREsHSSyA-h"
      },
      "source": [
        "#Module 4 - Informed Search"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tuFC8w7CyCns",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "95db6f5c-934f-4c97-8d81-c44bf3b7596b"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
        "chapter3_5 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\"\n",
        "\n",
        "We start with Uniform Cost Search (UCS). For clarity, g(n) is our path cost. \n",
        "The idea here is that we expand the node with the lowest path cost and use a \n",
        "priority queue ordered by g(n). h(n) is our heuristic function. Guaranteed to \n",
        "find an optimnal solution. Also basically Dijkstra's algorithm without a goal.\n",
        "\n",
        "Greedy BFS: f(n) = h(n) ==> expands node that is estimated to be closest to the\n",
        "goal. In a grid, we calculate the manhattan distance. NOT complete and NOT optimal.\n",
        "\n",
        "def Greedy-BFS:\n",
        "  frontier = PriorityQueue()\n",
        "  frontier.put(start,0)\n",
        "  came_from = {}\n",
        "  came_from[start] = None\n",
        "\n",
        "  while not frontier.empty():\n",
        "    current = frontier.get()\n",
        "\n",
        "    if current == goal:\n",
        "      break\n",
        "    \n",
        "    for next in graph.neighbors(current):\n",
        "      if next not in came_from:\n",
        "        priority = heauristic(goal,next)\n",
        "        frontier.put(next, priority)\n",
        "        came_from[next] = current\n",
        "\n",
        "An admissible heuristic never overestimates the cost to reach a goal.\n",
        "\n",
        "If h2(n) >= h1(n) for all n where both are admissible then h1 is dominated by h2\n",
        "\n",
        "In A*, we say that f(n) = g(n) + h(n) ==> a form of BFS\n",
        "\n",
        "An admissible heuristic with a smaller branching factor than the current one results \n",
        "in a more efficient algorithmic performance.\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n",
        "length = len(module4_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 228 words long, so you could write an additional 1772 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 712
        },
        "cellView": "form",
        "outputId": "d28fe9ff-223d-45a1-f7ac-7c4a8672381e"
      },
      "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": 11,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n\n\nWe start with Uniform Cost Search (UCS). For clarity, g(n) is our path cost. \nThe idea here is that we expand the node with the lowest path cost and use a \npriority queue ordered by g(n). h(n) is our heuristic function. Guaranteed to \nfind an optimnal solution. Also basically Dijkstra's algorithm without a goal.\n\nGreedy BFS: f(n) = h(n) ==> expands node that is estimated to be closest to the\ngoal. In a grid, we calculate the manhattan distance. NOT complete and NOT optimal.\n\ndef Greedy-BFS:\n  frontier = PriorityQueue()\n  frontier.put(start,0)\n  came_from = {}\n  came_from[start] = None\n\n  while not frontier.empty():\n    current = frontier.get()\n\n    if current == goal:\n      break\n    \n    for next in graph.neighbors(current):\n      if next not in came_from:\n        priority = heauristic(goal,next)\n        frontier.put(next, priority)\n        came_from[next] = current\n\nAn admissible heuristic never overestimates the cost to reach a goal.\n\nIf h2(n) >= h1(n) for all n where both are admissible then h1 is dominated by h2\n\nIn A*, we say that f(n) = g(n) + h(n) ==> a form of BFS\n\nAn admissible heuristic with a smaller branching factor than the current one results \nin a more efficient algorithmic performance.\n\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",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "283de473-67b5-42aa-8cec-2584b402498d"
      },
      "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",
        "We start with game formulation. The simplest game environment is one that \n",
        "has multiple agents, is STATIC (no change in game when an agent is making a move),\n",
        "DISCRETE (a finite set of actions), FULLY OBSERVABLE (synonomous with perfect information, \n",
        "means you are able to view the entire currentn state), and STRATEGIC (next \n",
        "state is determined by the agents, their actions, and the curent state).\n",
        "\n",
        "Much like the search problem definition, a Game is defined by 5 things: an INITIAL STATE, a set of ACTIONS (SUCCESSOR FUNCTION), \n",
        "a TRANSITION MODEL, a Utility function (numerical value of terminal states), and MAX\n",
        "uses search tree to determine next move.\n",
        "\n",
        "Next, we talked about GAME TREES, where this tree represents the game itself.\n",
        "Here, nodes are the state, edges are a move/action.\n",
        "\n",
        "Following game trees, we get into minimax. The Minimax Procedure is as follows:\n",
        "Until the game is over, 1) make the start node MAX 2) expand the game tree by a fixed \n",
        "number of ply (levels) 3) apply the evaluation function 4) calculate the back-up values\n",
        "(the values of its children) 5) pick the best move for MAX to do next 6) wait for MIN.\n",
        "\n",
        "Minimax Pseudocode:\n",
        "\n",
        "def value(current_state):\n",
        "  if the current_state is terminal then retrn the state's utility\n",
        "  if the next agent is MAX then return the max-val(current_state)\n",
        "  Else if the next agent is MIN then return the min-val(current_state)\n",
        "\n",
        "def max-val(current_state):\n",
        "  initialize node = -inf\n",
        "  for each successor:\n",
        "    node = max(node, value(successor))\n",
        "  return node\n",
        "\n",
        "def min-val(current_state):\n",
        "  initialize node = inf\n",
        "  for each successor:\n",
        "    node = min(node, value(successor))\n",
        "  return node\n",
        "\n",
        "alpha/beta: MAX's/Min's best option at a current moment in time up to the root\n",
        "\n",
        "Very hard to alpha-beta prune in expectimax!\n",
        "\n",
        "Minimax Pseudocode:\n",
        "\n",
        "def value(current_state):\n",
        "  if the current_state is terminal then retrn the state's utility\n",
        "  if the next agent is MAX then return the max-val(current_state)\n",
        "  Else if the next agent is EXP then return the exp-val(current_state)\n",
        "\n",
        "def max-val(current_state):\n",
        "  initialize node = -inf\n",
        "  for each successor:\n",
        "    node = max(node, value(successor))\n",
        "  return node\n",
        "\n",
        "def exp-val(current_state):\n",
        "  initialize node = 0\n",
        "  for each successor:\n",
        "    p = probability(succesor)\n",
        "    node += p * value(successor)\n",
        "  return node\n",
        "\n",
        "alpha/beta: MAX's/Min's best option at a current moment in time up to the root\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n",
        "length = len(module5_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 377 words long, so you could write an additional 1623 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "4826a644-949f-4a23-dd84-6defbaedd2ee"
      },
      "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": 13,
      "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\nWe start with game formulation. The simplest game environment is one that \nhas multiple agents, is STATIC (no change in game when an agent is making a move),\nDISCRETE (a finite set of actions), FULLY OBSERVABLE (synonomous with perfect information, \nmeans you are able to view the entire currentn state), and STRATEGIC (next \nstate is determined by the agents, their actions, and the curent state).\n\nMuch like the search problem definition, a Game is defined by 5 things: an INITIAL STATE, a set of ACTIONS (SUCCESSOR FUNCTION), \na TRANSITION MODEL, a Utility function (numerical value of terminal states), and MAX\nuses search tree to determine next move.\n\nNext, we talked about GAME TREES, where this tree represents the game itself.\nHere, nodes are the state, edges are a move/action.\n\nFollowing game trees, we get into minimax. The Minimax Procedure is as follows:\nUntil the game is over, 1) make the start node MAX 2) expand the game tree by a fixed \nnumber of ply (levels) 3) apply the evaluation function 4) calculate the back-up values\n(the values of its children) 5) pick the best move for MAX to do next 6) wait for MIN.\n\nMinimax Pseudocode:\n\ndef value(current_state):\n  if the current_state is terminal then retrn the state's utility\n  if the next agent is MAX then return the max-val(current_state)\n  Else if the next agent is MIN then return the min-val(current_state)\n\ndef max-val(current_state):\n  initialize node = -inf\n  for each successor:\n    node = max(node, value(successor))\n  return node\n\ndef min-val(current_state):\n  initialize node = inf\n  for each successor:\n    node = min(node, value(successor))\n  return node\n\nalpha/beta: MAX's/Min's best option at a current moment in time up to the root\n\nVery hard to alpha-beta prune in expectimax!\n\nMinimax Pseudocode:\n\ndef value(current_state):\n  if the current_state is terminal then retrn the state's utility\n  if the next agent is MAX then return the max-val(current_state)\n  Else if the next agent is EXP then return the exp-val(current_state)\n\ndef max-val(current_state):\n  initialize node = -inf\n  for each successor:\n    node = max(node, value(successor))\n  return node\n\ndef exp-val(current_state):\n  initialize node = 0\n  for each successor:\n    p = probability(succesor)\n    node += p * value(successor)\n  return node\n\nalpha/beta: MAX's/Min's best option at a current moment in time up to the root\n\n\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",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "97c2df88-fa97-43f9-f1a1-3c94ecaa07db"
      },
      "source": [
        "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
        "chapter6_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\"\n",
        "\n",
        "This module talks all about CSPs (Constraint Satisfaction Problems). A CSP is\n",
        "defined by 3 parts: a finite set of variables x1, x2, ... , xn, a nonempty domain \n",
        "of possible values for each variable D1, D2, ... , Dn where Di = {v1, ..., vk},\n",
        "and a finite set of constraints C1, C2, ... , Cm. in this case a CONSISTENT assignment \n",
        "is one that does not violate any of the constraints.\n",
        "\n",
        "An assignment is COMPLETE is every variable is assigned a value. This means that \n",
        "a solution to a CSP is COMPLETE and CONSISTENT.\n",
        "\n",
        "Benefits of CSPs:\n",
        "They give us a very concise and understanable specification of many problems, \n",
        "generic goal, successor function, and heuristifcs ==> allows us to solve generally.\n",
        "The CSP knows what violates which constaints. Additionally, CSPs prune off all \n",
        "branches which violate sch constraints.\n",
        "\n",
        "A CSP is represented in many ways:\n",
        "It can be represented as a contraint graph where the nodes are variables and arcs\n",
        "are binary constraints. It uses as a 'standard representation pattern'\n",
        "where each of the variables have values. These vaiables can be discrete or continuous.\n",
        "\n",
        "Constraints can be Unary, Binary, Higher-order (3+ vars), or preference (soft constraints)\n",
        "\n",
        "If there are n variables, with a domain of size d, then the branching factor is n*d,\n",
        "and the number of leaves is n!*d^n.\n",
        "\n",
        "Uninformed Algorithms (for CSPs):\n",
        "Backtracking search is the basic search algotihm for CSPs. The term backtracking\n",
        "is used for a DFS that selects values for variables but backtracks when a variable\n",
        "has no legal vvalues left to assign. \n",
        "\n",
        "We can further improve the backtracking efficiency by using several heuristics: \n",
        "the first is the \"Minimum remaining values (MRV)\" heuristic\n",
        "where we choose the variable with the fewest legal variables. the second is picking the\n",
        "variable with the most constraints on the remaining variables from heuristic 1. \n",
        "This is used as a tie breaker. These two combinbed eliminate the need for backtracking.\n",
        "\n",
        "The third heristic is where we choose the least constraining value. The fourth is \"forward checking\"\n",
        "where we track the remaining legals values for unassigned vars and termiante when \n",
        "any of these vars have no more legal values. Constraint propogation improves upon this\n",
        "by enforcing constraints locally\n",
        "\n",
        "AC-3 improves upon the Waltz/Mackworth constraint propogation algorithm\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n",
        "length = len(module6_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 354 words long, so you could write an additional 1646 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "a6bde220-e700-4b0b-a47e-8686732c3ee2"
      },
      "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": 15,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n\n\nThis module talks all about CSPs (Constraint Satisfaction Problems). A CSP is\ndefined by 3 parts: a finite set of variables x1, x2, ... , xn, a nonempty domain \nof possible values for each variable D1, D2, ... , Dn where Di = {v1, ..., vk},\nand a finite set of constraints C1, C2, ... , Cm. in this case a CONSISTENT assignment \nis one that does not violate any of the constraints.\n\nAn assignment is COMPLETE is every variable is assigned a value. This means that \na solution to a CSP is COMPLETE and CONSISTENT.\n\nBenefits of CSPs:\nThey give us a very concise and understanable specification of many problems, \ngeneric goal, successor function, and heuristifcs ==> allows us to solve generally.\nThe CSP knows what violates which constaints. Additionally, CSPs prune off all \nbranches which violate sch constraints.\n\nA CSP is represented in many ways:\nIt can be represented as a contraint graph where the nodes are variables and arcs\nare binary constraints. It uses as a 'standard representation pattern'\nwhere each of the variables have values. These vaiables can be discrete or continuous.\n\nConstraints can be Unary, Binary, Higher-order (3+ vars), or preference (soft constraints)\n\nIf there are n variables, with a domain of size d, then the branching factor is n*d,\nand the number of leaves is n!*d^n.\n\nUninformed Algorithms (for CSPs):\nBacktracking search is the basic search algotihm for CSPs. The term backtracking\nis used for a DFS that selects values for variables but backtracks when a variable\nhas no legal vvalues left to assign. \n\nWe can further improve the backtracking efficiency by using several heuristics: \nthe first is the \"Minimum remaining values (MRV)\" heuristic\nwhere we choose the variable with the fewest legal variables. the second is picking the\nvariable with the most constraints on the remaining variables from heuristic 1. \nThis is used as a tie breaker. These two combinbed eliminate the need for backtracking.\n\nThe third heristic is where we choose the least constraining value. The fourth is \"forward checking\"\nwhere we track the remaining legals values for unassigned vars and termiante when \nany of these vars have no more legal values. Constraint propogation improves upon this\nby enforcing constraints locally\n\nAC-3 improves upon the Waltz/Mackworth constraint propogation algorithm\n\n\n\n## Module 6 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "90d60ef0-8458-471a-829b-69a8b3568731"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\"\n",
        "An instance of a logic based agent is a knowledge based agent, wherein we \n",
        "construct a represenation of the world and use instances \n",
        "of this representation to reason through a decision.\n",
        "\n",
        "In a knowledge base, we have a set of sentences that are written in a 'knowledge \n",
        "representation language', a sort of pseudo language we define. Of these sentences,\n",
        "there are two kinds Axioms (given) and Derived (derived from others).\n",
        "\n",
        "Truth Tables:\n",
        "\n",
        "If P is T and Q is T then P ==> Q is T\n",
        "\n",
        "If P is T and Q is F then P ==> Q is F\n",
        "\n",
        "If P is F and Q is T then P ==> Q is T\n",
        "\n",
        "If P is F and Q is F then P ==> Q is T\n",
        "\n",
        "IFF is represented by <==> and is shorthand for P ==> Q and Q ==> P\n",
        "\n",
        "If P is T and Q is T then P <==> Q is T\n",
        "\n",
        "If P is T and Q is F then P <==> Q is F\n",
        "\n",
        "If P is F and Q is T then P <==> Q is F\n",
        "\n",
        "If P is F and Q is F then P <==> Q is T\n",
        "\n",
        "Entailment can be applied to derive conclusions about the knowledge base, \n",
        "which is logical inference.\n",
        "\n",
        "For inference algorithms, it should be SOUND and COMPLETE, meaning it should \n",
        "only derive entailed sentences and derive all such sentences respectively.\n",
        "\n",
        "Logical Equivalence:\n",
        "\n",
        "A ^ B = B ^ A [Communativity of ^]\n",
        "\n",
        "A V B = B V A [Communativity of V]\n",
        "\n",
        "(A ^ B) ^ C = A ^ (B ^ C) [Associativity of ^]\n",
        "\n",
        "(A V B) V C = A V (B V C) [Associativity of V]\n",
        "\n",
        "-(-A) = A [Double-negation elimination]\n",
        "\n",
        "A ==> B = -A ==> -B [Contraposition]\n",
        "\n",
        "A ==> B = -A V B [Implication elimination]\n",
        "\n",
        "A <==> B = (A ==> B) ^ (B ==> A) [biconditional elimination]\n",
        "\n",
        "-(A ^ B) = -A V -B [De Morgan]\n",
        "\n",
        "-(A V B) = -A ^ -B [De Morgan]\n",
        "\n",
        "((A ^ B) V C) = ((A ^ B) V (A ^ C)) [Distributivity of ^ over V]\n",
        "\n",
        "((A V B) ^ C) = ((A V B) V (A V C)) [Distributivity of V over ^]\n",
        "\n",
        "We also discussed CNF, the Resolution algorithm, and forward and backward chaining.\n",
        "\n",
        "Backward chaining is goal directed reasoning!\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"Logical Entailment\" : \"When one sentence is more specific than another\",    \n",
        "}\n",
        "\n",
        "length = len(module7_lecture_notes.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(2000-length)))"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 365 words long, so you could write an additional 1635 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "53f11773-8204-4304-c45a-7f450178d67b"
      },
      "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": 17,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n\nAn instance of a logic based agent is a knowledge based agent, wherein we \nconstruct a represenation of the world and use instances \nof this representation to reason through a decision.\n\nIn a knowledge base, we have a set of sentences that are written in a 'knowledge \nrepresentation language', a sort of pseudo language we define. Of these sentences,\nthere are two kinds Axioms (given) and Derived (derived from others).\n\nTruth Tables:\n\nIf P is T and Q is T then P ==> Q is T\n\nIf P is T and Q is F then P ==> Q is F\n\nIf P is F and Q is T then P ==> Q is T\n\nIf P is F and Q is F then P ==> Q is T\n\nIFF is represented by <==> and is shorthand for P ==> Q and Q ==> P\n\nIf P is T and Q is T then P <==> Q is T\n\nIf P is T and Q is F then P <==> Q is F\n\nIf P is F and Q is T then P <==> Q is F\n\nIf P is F and Q is F then P <==> Q is T\n\nEntailment can be applied to derive conclusions about the knowledge base, \nwhich is logical inference.\n\nFor inference algorithms, it should be SOUND and COMPLETE, meaning it should \nonly derive entailed sentences and derive all such sentences respectively.\n\nLogical Equivalence:\n\nA ^ B = B ^ A [Communativity of ^]\n\nA V B = B V A [Communativity of V]\n\n(A ^ B) ^ C = A ^ (B ^ C) [Associativity of ^]\n\n(A V B) V C = A V (B V C) [Associativity of V]\n\n-(-A) = A [Double-negation elimination]\n\nA ==> B = -A ==> -B [Contraposition]\n\nA ==> B = -A V B [Implication elimination]\n\nA <==> B = (A ==> B) ^ (B ==> A) [biconditional elimination]\n\n-(A ^ B) = -A V -B [De Morgan]\n\n-(A V B) = -A ^ -B [De Morgan]\n\n((A ^ B) V C) = ((A ^ B) V (A ^ C)) [Distributivity of ^ over V]\n\n((A V B) ^ C) = ((A V B) V (A V C)) [Distributivity of V over ^]\n\nWe also discussed CNF, the Resolution algorithm, and forward and backward chaining.\n\nBackward chaining is goal directed reasoning!\n\n\n\n## Module 7 Definitions\n* **Logical entailment** - When one sentence is more specific than another\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": "2287ec6e-0cfd-4169-d349-a7209e41a6af"
      },
      "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": 18,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n\nWe start this unit by talking about AI in Philosohpy. We talked about Rene Descartes \n(\"I think therefore I am\"), Alan Turing (the Turing Test), John Searle, Daniel Dennet \n(Brain in a Vat).\n\nThere are four views of AI: to think huumanly, think rationally, act huumanly, act rationally.\n\nFor an agent, the agent function takes in a sequence of percepts and outputs a sequence of actions.\nThis is different from the agent program which runs on the physical architecture to \nproduce the agent function. Examples of agents are humans, robots, softbots, thermostats, etc.\n\nAI is concerned with consequentialism.\n\nWe then talked about rational agents, where a rational agent is one where for each \npossible percept, the agent selects the action a which maximizes its expected value of the\nperformance measure since it doesnt know what the outcome will be.\n\nWe continued about Task environments:\nUse PEAS ==> Performance measure, environment, actuators, sensors\n\n\n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - your definitions here\n* **Other concept** - your definitions here\n* **Etc.** - your definitions here\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n\nIn python, all data are treated as objects. Python is also strongly typed, meaning\nevery object has a fixed type. Python also has dynamic typing, meaning variable \ntypes are automatically assigned. Strings are immutable. Tuples are immutable. \nLists are mutable.\n\n== checks the value\nis checks if the objects point to the same location in memory\n\n|Slicing|\ntake this example: tuple_t = (1,2,3,4,5)\ntuple_t[1:4] ==> (2,3,4)\ntuple_t[1:-1] ==> (2,3,4)\ntuple_t[1:-1:2] ==> (2,4)\ntuple_t[:2] ==> (1,2)\ntuple_t[2:] ==> (3,4,5)\n\n|List Operations|\ntake this example: list_li = [1,2,3,4,5]\nlist_li.insert(2,6) ==> [1,2,6,3,4,5]\nlist_li.index(5) ==> 4 #first occurance\nlist_li.count(5) ==> 1 #num occurances\nlist_li.remove(5) ==> [1,2,3,4]\nlist_li.reverse() ==>  [5,4,3,2,1]\nlist_li.sort() ==>  [1,2,3,4,5]\n\n|String Operations|\n.capitalize()\n.upper()\n.strip()\n.split\n\n|String Operations|\n.keys()\n.values()\n.items() #returns a list of items\n\n\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 Your summary here \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Your summary here \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n \n\nThe task environment can change solutions. \nA task environment that's FULLY OBSERVABLE, DETERMINISTIC, AND KNOWN ENVIRONMENT\nimplies a solution is a set path of actions. The opposite of this is PARTIALLY\nOBSERVABLE AND NONDETERMINISTIC environments. \n\nA problem is defined by 6 things: a set of STATES, an INITIAL \nSTATE, a set of ACTIONS, a TRANSITION MODEL, an additive PATH COST, and a \nviable GOAL TEST/STATE. The formulation of this problem greatly affects the\nspeed of the search.\n\nBasic Search Algorithms:\nFirst we have Tree Search. In this you do not check for redundant paths. This means\nthat we can have repeated stated which means the poblem becomes exponential. We\nsolve this by modifying tree search into gaph search. Here, we check if a node has\nbeen visited (check for redundant paths).\n\nUninformed Search Strategies:\nNO HEURISTICS. To formulate these strategies, we typically use a queue to help us \n(LIFO, FIFO, piority). How do we evaluate whether a strategy is good? We have several\ncriteria for this: Complete (always finds a solution), Optimal (always finds the \nsolution with lowest cost first), Time Complexity, Space Complexity. For Time and Space,\nwe use these vars: b (max number of children at each node), d (shallowest goal depth),\nm (max length of path in state space), l (the depth limit of the tree).\n\nBFS: we use frontiers as FIFO queues.\nComplete ==> Yes!\nOptimal ==> Yes!\nTime ==> O(b^d)\nSpace ==> O(b^d)\n\nDFS: we use frontiers as LIFO queues.\nComplete ==> No\nOptimal ==> No\nTime ==> O(b^m)\nSpace ==> O(b*m)!\n\nThese are not great, so we improve upon BFS and DFS with Iterative deepending search\nand Depth-Limited Search. \n\nDLS:\nComplete ==> No\nOptimal ==> No\nTime ==> O(b^l)\nSpace ==> O(b*l)!\n\nIDS:\nComplete ==> YES\nOptimal ==> YES\nTime ==> O(b^d)\nSpace ==> O(b*d)!\n\n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Reflex agent** - an agent that ignores the 'percept' history and only acts on what it sees at a given state\n* **Solution** - a path of actions from the start state to the goal state\n* **Optimal solution** - the solution with the lowest path cost\n* **State space** - all states\n* **Frontier** - the next available set of 'expandable' states at the current moment in time for a search\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n\n\nWe start with Uniform Cost Search (UCS). For clarity, g(n) is our path cost. \nThe idea here is that we expand the node with the lowest path cost and use a \npriority queue ordered by g(n). h(n) is our heuristic function. Guaranteed to \nfind an optimnal solution. Also basically Dijkstra's algorithm without a goal.\n\nGreedy BFS: f(n) = h(n) ==> expands node that is estimated to be closest to the\ngoal. In a grid, we calculate the manhattan distance. NOT complete and NOT optimal.\n\ndef Greedy-BFS:\n  frontier = PriorityQueue()\n  frontier.put(start,0)\n  came_from = {}\n  came_from[start] = None\n\n  while not frontier.empty():\n    current = frontier.get()\n\n    if current == goal:\n      break\n    \n    for next in graph.neighbors(current):\n      if next not in came_from:\n        priority = heauristic(goal,next)\n        frontier.put(next, priority)\n        came_from[next] = current\n\nAn admissible heuristic never overestimates the cost to reach a goal.\n\nIf h2(n) >= h1(n) for all n where both are admissible then h1 is dominated by h2\n\nIn A*, we say that f(n) = g(n) + h(n) ==> a form of BFS\n\nAn admissible heuristic with a smaller branching factor than the current one results \nin a more efficient algorithmic performance.\n\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\nWe start with game formulation. The simplest game environment is one that \nhas multiple agents, is STATIC (no change in game when an agent is making a move),\nDISCRETE (a finite set of actions), FULLY OBSERVABLE (synonomous with perfect information, \nmeans you are able to view the entire currentn state), and STRATEGIC (next \nstate is determined by the agents, their actions, and the curent state).\n\nMuch like the search problem definition, a Game is defined by 5 things: an INITIAL STATE, a set of ACTIONS (SUCCESSOR FUNCTION), \na TRANSITION MODEL, a Utility function (numerical value of terminal states), and MAX\nuses search tree to determine next move.\n\nNext, we talked about GAME TREES, where this tree represents the game itself.\nHere, nodes are the state, edges are a move/action.\n\nFollowing game trees, we get into minimax. The Minimax Procedure is as follows:\nUntil the game is over, 1) make the start node MAX 2) expand the game tree by a fixed \nnumber of ply (levels) 3) apply the evaluation function 4) calculate the back-up values\n(the values of its children) 5) pick the best move for MAX to do next 6) wait for MIN.\n\nMinimax Pseudocode:\n\ndef value(current_state):\n  if the current_state is terminal then retrn the state's utility\n  if the next agent is MAX then return the max-val(current_state)\n  Else if the next agent is MIN then return the min-val(current_state)\n\ndef max-val(current_state):\n  initialize node = -inf\n  for each successor:\n    node = max(node, value(successor))\n  return node\n\ndef min-val(current_state):\n  initialize node = inf\n  for each successor:\n    node = min(node, value(successor))\n  return node\n\nalpha/beta: MAX's/Min's best option at a current moment in time up to the root\n\nVery hard to alpha-beta prune in expectimax!\n\nMinimax Pseudocode:\n\ndef value(current_state):\n  if the current_state is terminal then retrn the state's utility\n  if the next agent is MAX then return the max-val(current_state)\n  Else if the next agent is EXP then return the exp-val(current_state)\n\ndef max-val(current_state):\n  initialize node = -inf\n  for each successor:\n    node = max(node, value(successor))\n  return node\n\ndef exp-val(current_state):\n  initialize node = 0\n  for each successor:\n    p = probability(succesor)\n    node += p * value(successor)\n  return node\n\nalpha/beta: MAX's/Min's best option at a current moment in time up to the root\n\n\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 Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n\n\nThis module talks all about CSPs (Constraint Satisfaction Problems). A CSP is\ndefined by 3 parts: a finite set of variables x1, x2, ... , xn, a nonempty domain \nof possible values for each variable D1, D2, ... , Dn where Di = {v1, ..., vk},\nand a finite set of constraints C1, C2, ... , Cm. in this case a CONSISTENT assignment \nis one that does not violate any of the constraints.\n\nAn assignment is COMPLETE is every variable is assigned a value. This means that \na solution to a CSP is COMPLETE and CONSISTENT.\n\nBenefits of CSPs:\nThey give us a very concise and understanable specification of many problems, \ngeneric goal, successor function, and heuristifcs ==> allows us to solve generally.\nThe CSP knows what violates which constaints. Additionally, CSPs prune off all \nbranches which violate sch constraints.\n\nA CSP is represented in many ways:\nIt can be represented as a contraint graph where the nodes are variables and arcs\nare binary constraints. It uses as a 'standard representation pattern'\nwhere each of the variables have values. These vaiables can be discrete or continuous.\n\nConstraints can be Unary, Binary, Higher-order (3+ vars), or preference (soft constraints)\n\nIf there are n variables, with a domain of size d, then the branching factor is n*d,\nand the number of leaves is n!*d^n.\n\nUninformed Algorithms (for CSPs):\nBacktracking search is the basic search algotihm for CSPs. The term backtracking\nis used for a DFS that selects values for variables but backtracks when a variable\nhas no legal vvalues left to assign. \n\nWe can further improve the backtracking efficiency by using several heuristics: \nthe first is the \"Minimum remaining values (MRV)\" heuristic\nwhere we choose the variable with the fewest legal variables. the second is picking the\nvariable with the most constraints on the remaining variables from heuristic 1. \nThis is used as a tie breaker. These two combinbed eliminate the need for backtracking.\n\nThe third heristic is where we choose the least constraining value. The fourth is \"forward checking\"\nwhere we track the remaining legals values for unassigned vars and termiante when \nany of these vars have no more legal values. Constraint propogation improves upon this\nby enforcing constraints locally\n\nAC-3 improves upon the Waltz/Mackworth constraint propogation algorithm\n\n\n\n## Module 6 Definitions\n* **Concept** - definition\n\n\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n\nAn instance of a logic based agent is a knowledge based agent, wherein we \nconstruct a represenation of the world and use instances \nof this representation to reason through a decision.\n\nIn a knowledge base, we have a set of sentences that are written in a 'knowledge \nrepresentation language', a sort of pseudo language we define. Of these sentences,\nthere are two kinds Axioms (given) and Derived (derived from others).\n\nTruth Tables:\n\nIf P is T and Q is T then P ==> Q is T\n\nIf P is T and Q is F then P ==> Q is F\n\nIf P is F and Q is T then P ==> Q is T\n\nIf P is F and Q is F then P ==> Q is T\n\nIFF is represented by <==> and is shorthand for P ==> Q and Q ==> P\n\nIf P is T and Q is T then P <==> Q is T\n\nIf P is T and Q is F then P <==> Q is F\n\nIf P is F and Q is T then P <==> Q is F\n\nIf P is F and Q is F then P <==> Q is T\n\nEntailment can be applied to derive conclusions about the knowledge base, \nwhich is logical inference.\n\nFor inference algorithms, it should be SOUND and COMPLETE, meaning it should \nonly derive entailed sentences and derive all such sentences respectively.\n\nLogical Equivalence:\n\nA ^ B = B ^ A [Communativity of ^]\n\nA V B = B V A [Communativity of V]\n\n(A ^ B) ^ C = A ^ (B ^ C) [Associativity of ^]\n\n(A V B) V C = A V (B V C) [Associativity of V]\n\n-(-A) = A [Double-negation elimination]\n\nA ==> B = -A ==> -B [Contraposition]\n\nA ==> B = -A V B [Implication elimination]\n\nA <==> B = (A ==> B) ^ (B ==> A) [biconditional elimination]\n\n-(A ^ B) = -A V -B [De Morgan]\n\n-(A V B) = -A ^ -B [De Morgan]\n\n((A ^ B) V C) = ((A ^ B) V (A ^ C)) [Distributivity of ^ over V]\n\n((A V B) ^ C) = ((A V B) V (A V C)) [Distributivity of V over ^]\n\nWe also discussed CNF, the Resolution algorithm, and forward and backward chaining.\n\nBackward chaining is goal directed reasoning!\n\n\n\n## Module 7 Definitions\n* **Logical entailment** - When one sentence is more specific than another\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}