{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "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": "d0f70e4b-7e6a-48a9-b0a0-67abc0c8c843"
      },
      "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": 39,
      "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": "b9794e0e-5c4a-4114-cbd7-2e6e9bae93f4"
      },
      "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": 40,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = False"
      ],
      "execution_count": 41,
      "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 = \"\"\" ---Turing test (Computer poses a series of questions and a person must identify if it is a computer or human asking them): Intelligent \n",
        "computer must have natural language processing to communicate in english, knowledge representation to store what it knows, automated resoning\n",
        "to use the information and draw conclusions, and machine learning to adapt to new cricumstances. \n",
        "\n",
        "\n",
        "---Cognitive approach (try to investigate \n",
        "the way humans behave to then determine how computers should behave to follow human rationality.\n",
        "\n",
        "\n",
        "---Logical (Machines should follow facts and therefore act in a \n",
        "logical way) \n",
        "\n",
        "\n",
        "---Rational agent (Intelligent systems must use information available to them to make decisions that will give them the best outcome)\"\"\" \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 = \"\"\" Agents behave based on their environments \"\"\"\n",
        "chapter2_2 = \"\"\" Rationality maximizes EXPECTED performance, not ACTUAL performance \"\"\"\n",
        "chapter2_3 = \"\"\" Task environments: Performance measure, Environment, Actuators, Sensors\"\"\"\n",
        "chapter2_4 = \"\"\" Types of agents.\n",
        "\n",
        "Agent = architecture + program\n",
        "\n",
        "program implements the agent function\n",
        "\n",
        "architecture is where the program runs \n",
        "\n",
        "Simple reflex agents might have issues of infinite loops that might be avoided through randomizing actions\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Agents, environments, etc \"\"\"\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\" : \"an agents perceptual inputs at any given instant\",\n",
        "\"rationality\" : \"a system that is rational does the right thing given what it knows\",\n",
        "\"rational agent\" : \"acts ro achieve the best outcome\",\n",
        "\"agent function\" : \"maps any percept sequence to an action\",\n",
        "\"agent program\" : \"concrete implementation of how an agent will act\",\n",
        "\"performance measure\" : \"evaluates any given sequence of environment states to determine how 'good' these are\",\n",
        "\"information gathering\": \"doing actions in order to modify future percepts\",\n",
        "\"autonomous\": \"a rational agent should learn what it can to compensate from partial knowledge\",\n",
        "\"actuator\": \"action available to the agent\",\n",
        "\"fully observable\": \"agents senseors give it access to the complete state of the environment\",\n",
        "\"partially observable\": \"cannot see the complete state of the environment\",\n",
        "\"single agent\": \"one agent\",\n",
        "\"multi agent\": \"multiple intelligent agents\",\n",
        "\"determenistic\": \"next state of the environment is completely determined by the current state\",\n",
        "\"stochastic\": \"next environment state is not certain\",\n",
        "\"episodic\": \"divided into time stamps, in each stamp agent gathers info and performs a single task. a decision ONLY affects the next state\",\n",
        "\"sequential\": \"a current decision could affect all future decisions\",\n",
        "\"dynamic\": \"environment can change while an agent is acting\",\n",
        "\"static\": \"environment cannot while an agent is acting\",\n",
        "\"discrete\": \"finite number of distinct states\",\n",
        "\"continuous\": \"a range of distinct states\",\n",
        "\"known\": \"outcomes of actions are given\",\n",
        "\"unknown\": \"outcomes of actions are not known\",\n",
        "\"simple reflix agent\": \"select actions based on the current perception, ignoring percept history\",\n",
        "\"model based agent\": \"uses current percept and old internal state (info) ro generate an updated decription of the current state\",\n",
        "\"goal based agent\": \"agent has some sort of goal the descibes situations that are desirable\",\n",
        "\"utility based agent\": \"agents have a utility function that internalizes the performance measure\",\n",
        "\"learning agent\": \"has a learning element that listens to the critic to fetermine how the performance element should me modified to improve\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": 42,
      "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": 1000
        },
        "cellView": "form",
        "outputId": "8fc952a9-3718-446e-d221-f46d5ba78d01"
      },
      "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": 43,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'episodic' is too long!\n# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n ---Turing test (Computer poses a series of questions and a person must identify if it is a computer or human asking them): Intelligent \ncomputer must have natural language processing to communicate in english, knowledge representation to store what it knows, automated resoning\nto use the information and draw conclusions, and machine learning to adapt to new cricumstances. \n\n\n---Cognitive approach (try to investigate \nthe way humans behave to then determine how computers should behave to follow human rationality.\n\n\n---Logical (Machines should follow facts and therefore act in a \nlogical way) \n\n\n---Rational agent (Intelligent systems must use information available to them to make decisions that will give them the best outcome)\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 Agents behave based on their environments \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Rationality maximizes EXPECTED performance, not ACTUAL performance \n\n## AIMA 2.3 The Nature of Environments\n Task environments: Performance measure, Environment, Actuators, Sensors\n\n## AIMA 2.4 The Structure of Agents\n Types of agents.\n\nAgent = architecture + program\n\nprogram implements the agent function\n\narchitecture is where the program runs \n\nSimple reflex agents might have issues of infinite loops that might be avoided through randomizing actions\n\n## Module 1 Lecture Notes\n Agents, environments, etc \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - an agents perceptual inputs at any given instant\n* **Rationality** - a system that is rational does the right thing given what it knows\n* **Rational agent** - acts ro achieve the best outcome\n* **Agent function** - maps any percept sequence to an action\n* **Agent program** - concrete implementation of how an agent will act\n* **Performance measure** - evaluates any given sequence of environment states to determine how 'good' these are\n* **Information gathering** - doing actions in order to modify future percepts\n* **Autonomous** - a rational agent should learn what it can to compensate from partial knowledge\n* **Actuator** - action available to the agent\n* **Fully observable** - agents senseors give it access to the complete state of the environment\n* **Partially observable** - cannot see the complete state of the environment\n* **Single agent** - one agent\n* **Multi agent** - multiple intelligent agents\n* **Determenistic** - next state of the environment is completely determined by the current state\n* **Stochastic** - next environment state is not certain\n* **Episodic** - divided into time stamps, in each stamp agent gathers info and performs a single task. a decision ONLY affects the next state\n* **Sequential** - a current decision could affect all future decisions\n* **Dynamic** - environment can change while an agent is acting\n* **Static** - environment cannot while an agent is acting\n* **Discrete** - finite number of distinct states\n* **Continuous** - a range of distinct states\n* **Known** - outcomes of actions are given\n* **Unknown** - outcomes of actions are not known\n* **Simple reflix agent** - select actions based on the current perception, ignoring percept history\n* **Model based agent** - uses current percept and old internal state (info) ro generate an updated decription of the current state\n* **Goal based agent** - agent has some sort of goal the descibes situations that are desirable\n* **Utility based agent** - agents have a utility function that internalizes the performance measure\n* **Learning agent** - has a learning element that listens to the critic to fetermine how the performance element should me modified to improve\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 = \"\"\" Python information \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 44,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 209
        },
        "outputId": "9ec3cb02-c805-4729-c4a8-b6b581a5473c"
      },
      "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": 45,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n Python information \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 = \"\"\" 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 = \"\"\" Searching \n",
        "\n",
        "Formulating a search problem:\n",
        "\n",
        "1. Decide initial state, goal state and intermediate states\n",
        "\n",
        "2. Operator set = actions and transition model\n",
        "\n",
        "3. Path cost function: which action should go next\n",
        "\n",
        "Algorithm: Tree Search\n",
        "Enumerate in some order all possible paths from the initial state\n",
        "\n",
        "\n",
        "• Here: search through explicit tree generation\n",
        "\n",
        "\n",
        "• ROOT= initial state\n",
        "\n",
        "\n",
        "• Nodes in search tree generated through transition model\n",
        "\n",
        "\n",
        "• Tree search treats different paths to the same node as distinct\n",
        "\n",
        "Algorithm: Graph Search\n",
        "\n",
        "• Simple Mod from tree search: Check to see if a node has been visited\n",
        "before adding to search queue\n",
        "\n",
        "\n",
        "• Algorithm: BFS\n",
        "\n",
        "Idea - expand shallowest unexpanded node\n",
        "\n",
        "Frontier - FIFO Queue\n",
        "\n",
        "Complete - Yes\n",
        "\n",
        "Optimal - Yes\n",
        "\n",
        "Time and space complexity - b^d (where b is maximum branching factor and d is the depth of the least cost solution)\n",
        "\n",
        "\n",
        "• Algorithm: DFS\n",
        "\n",
        "Idea - expand  deepest unexpanded node\n",
        "\n",
        "Frontier - LIFO Stack\n",
        "\n",
        "Complete - No\n",
        "\n",
        "Optimal - No\n",
        "\n",
        "Time complexity - b^m (where b is maximum branching factor and m is the max depth of the state space)\n",
        "\n",
        "Space complexity - b * m (where b is maximum branching factor and m is the max depth of the state space)\n",
        "\n",
        "\n",
        "\"\"\"\n",
        "\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 must plan ahead, it considers a sequence of actions that form a path to a goal state\",   \n",
        "\"uninformed\" : \"algos that are given ONLY the problem definition\",  \n",
        "\"informed\" : \"algos are given all info\",\n",
        "\"state\" : \"set of real world states\",\n",
        "\"action\" : \"equivalence class of combinations of actions\",\n",
        "\"state space\" : \"the set of all states reachable from the initial state by any sequence of actions\",\n",
        "\"path\" : \"a sequence of actions leading from one state sj to another state sk\",\n",
        "\"solution\" : \"a path from the initial state si to a state sf that satisfies the goal test\",\n",
        "\"search tree\" : \"a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states\",\n",
        "\"frontier\" : \"those states that are available for expanding (for applying legal actions to)\",\n",
        "\"optimal solution\": \"a solution with lowest path cost\",\n",
        "\"uninformed search\": \"all non-goal nodes in frontier look equally good\",\n",
        "\"informed search\": \"non-goal nodes in frontier are ranked\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "958ebb36-57f7-475a-cbaf-09e1f91a976d"
      },
      "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": 47,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'search tree' is too long!\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 Searching \n\nFormulating a search problem:\n\n1. Decide initial state, goal state and intermediate states\n\n2. Operator set = actions and transition model\n\n3. Path cost function: which action should go next\n\nAlgorithm: Tree Search\nEnumerate in some order all possible paths from the initial state\n\n\n• Here: search through explicit tree generation\n\n\n• ROOT= initial state\n\n\n• Nodes in search tree generated through transition model\n\n\n• Tree search treats different paths to the same node as distinct\n\nAlgorithm: Graph Search\n\n• Simple Mod from tree search: Check to see if a node has been visited\nbefore adding to search queue\n\n\n• Algorithm: BFS\n\nIdea - expand shallowest unexpanded node\n\nFrontier - FIFO Queue\n\nComplete - Yes\n\nOptimal - Yes\n\nTime and space complexity - b^d (where b is maximum branching factor and d is the depth of the least cost solution)\n\n\n• Algorithm: DFS\n\nIdea - expand  deepest unexpanded node\n\nFrontier - LIFO Stack\n\nComplete - No\n\nOptimal - No\n\nTime complexity - b^m (where b is maximum branching factor and m is the max depth of the state space)\n\nSpace complexity - b * m (where b is maximum branching factor and m is the max depth of the state space)\n\n\n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that must plan ahead, it considers a sequence of actions that form a path to a goal state\n* **Uninformed** - algos that are given ONLY the problem definition\n* **Informed** - algos are given all info\n* **State** - set of real world states\n* **Action** - equivalence class of combinations of actions\n* **State space** - the set of all states reachable from the initial state by any sequence of actions\n* **Path** - a sequence of actions leading from one state sj to another state sk\n* **Solution** - a path from the initial state si to a state sf that satisfies the goal test\n* **Search tree** - a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states\n* **Frontier** - those states that are available for expanding (for applying legal actions to)\n* **Optimal solution** - a solution with lowest path cost\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - non-goal nodes in frontier are ranked\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 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" \n",
        "• Algorithm: A*\n",
        "\n",
        "Note: Informed search\n",
        "\n",
        "Heuristic -- f(n) = actual cost so far + estimated total cost to n \n",
        "\n",
        "If the heuristic is admissible then A* is optimal\n",
        "\n",
        "Frontier is a priority queue sorted by increasing cost\n",
        "\n",
        "TODO: A* space and time complexity\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"heuristic function\" : \"takes a state n and returns the estimate to the distance from n to the goal\",   \n",
        "\"admissible\" : \"a heuristic is admissible if it never overestimated the cost to reach the goal\",\n",
        "\"relaxed problem\" : \"has fewer restrictions on the actions that the original is. Many heuristics are declared on relaxed problems\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 48,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 507
        },
        "cellView": "form",
        "outputId": "718a7193-10fa-4e59-cd54-d6239a895858"
      },
      "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": 49,
      "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• Algorithm: A*\n\nNote: Informed search\n\nHeuristic -- f(n) = actual cost so far + estimated total cost to n \n\nIf the heuristic is admissible then A* is optimal\n\nFrontier is a priority queue sorted by increasing cost\n\nTODO: A* space and time complexity\n\n## Module 4 Definitions\n* **Heuristic function** - takes a state n and returns the estimate to the distance from n to the goal\n* **Admissible** - a heuristic is admissible if it never overestimated the cost to reach the goal\n* **Relaxed problem** - has fewer restrictions on the actions that the original is. Many heuristics are declared on relaxed problems\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" Games:\n",
        "\n",
        "Formalizing:\n",
        "\n",
        "1. Two players: MAX and MIN; MAX moves first.\n",
        "2. MAX and MIN take turns until the game is over.\n",
        "3. Winner gets award, loser gets penalty.\n",
        "\n",
        "\n",
        "General Scheme\n",
        "1. Consider all legal successors to the current state (‘board position’)\n",
        "2. Evaluate each successor board position\n",
        "3. Pick the move which leads to the best board position.\n",
        "4. After your opponent moves, repeat.\n",
        "\n",
        "\n",
        "Game trees:\n",
        "Represent the game problem space by a tree:\n",
        "1. Nodes represent ‘board positions’; edges represent legal moves.\n",
        "2. Root node is the first position in which a decision must be made.\n",
        "\n",
        " Two players: MAX, MAX’s opponent MIN\n",
        "1. All play is computed from MAX’s vantage point.\n",
        "2. When MAX moves, MAX attempts to MAXimize MAX’s outcome.\n",
        "3. When MAX’s opponent moves, they attempt to MINimize MAX’s outcome.\n",
        "4. WE TYPICALLY ASSUME MAX MOVES FIRST:\n",
        "5. Label the root (level 0) MAX\n",
        "6. Alternate MAX/MIN labels at each successive tree level (ply).\n",
        "7. Even levels represent turns for MAX\n",
        "8. Odd levels represent turns for MIN\n",
        "\n",
        "Evaluation function:\n",
        "1. Evaluates how good a ‘board position’ is\n",
        "2. Based on static features of that board alone\n",
        "3. Zero-sum assumption lets us use one function to describe goodness for both players.\n",
        "4. f(n)>0 if MAX is winning in position n\n",
        "5. f(n)=0 if position n is tied\n",
        "6. f(n)<0 if MIN is winning in position n\n",
        "\n",
        "Minimax:\n",
        "1. Rule: Make the best move for MAX assuming that MIN always replies with the best\n",
        "move for MIN\n",
        "2. Easily computed by a recursive process\n",
        "3. The backed-up value of each node in the tree is determined by the values of its\n",
        "children:\n",
        "4. For a MAX node, the backed-up value is the maximum of the values of its\n",
        "children (i.e. the best for MAX)\n",
        "5. For a MIN node, the backed-up value is the minimum of the values of its\n",
        "children (i.e. the best for MIN)\n",
        "\n",
        "Alpha-beta pruning:\n",
        "1. During Minimax, keep track of two additional values:\n",
        "\n",
        "a. α: MAX’s current lower bound on MAX’s outcome\n",
        "\n",
        "b. β: MIN’s current upper bound on MIN’s outcome\n",
        "\n",
        "2. MAX will never allow a move that could lead to a worse score (for MAX) than α\n",
        "3. MIN will never allow a move that could lead to a better score (for MAX) than β\n",
        "\n",
        "1. Therefore, stop evaluating a branch whenever:\n",
        "2. When evaluating a MAX node: a value v ≥ β is backed-up\n",
        "\n",
        "a. MIN will never select that MAX node \n",
        "\n",
        "When evaluating a MIN node: a value v ≤ α is found\n",
        "\n",
        "b. MAX will never select that MIN node\n",
        "\n",
        "Expectimax Search: Uncertain results (like rolling dice)\n",
        "\n",
        "Use probabilities to determine values of nodes\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 50,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "bb4d9d9b-afa7-4ee5-9227-9b72b4c83322"
      },
      "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": 51,
      "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 Games:\n\nFormalizing:\n\n1. Two players: MAX and MIN; MAX moves first.\n2. MAX and MIN take turns until the game is over.\n3. Winner gets award, loser gets penalty.\n\n\nGeneral Scheme\n1. Consider all legal successors to the current state (‘board position’)\n2. Evaluate each successor board position\n3. Pick the move which leads to the best board position.\n4. After your opponent moves, repeat.\n\n\nGame trees:\nRepresent the game problem space by a tree:\n1. Nodes represent ‘board positions’; edges represent legal moves.\n2. Root node is the first position in which a decision must be made.\n\n Two players: MAX, MAX’s opponent MIN\n1. All play is computed from MAX’s vantage point.\n2. When MAX moves, MAX attempts to MAXimize MAX’s outcome.\n3. When MAX’s opponent moves, they attempt to MINimize MAX’s outcome.\n4. WE TYPICALLY ASSUME MAX MOVES FIRST:\n5. Label the root (level 0) MAX\n6. Alternate MAX/MIN labels at each successive tree level (ply).\n7. Even levels represent turns for MAX\n8. Odd levels represent turns for MIN\n\nEvaluation function:\n1. Evaluates how good a ‘board position’ is\n2. Based on static features of that board alone\n3. Zero-sum assumption lets us use one function to describe goodness for both players.\n4. f(n)>0 if MAX is winning in position n\n5. f(n)=0 if position n is tied\n6. f(n)<0 if MIN is winning in position n\n\nMinimax:\n1. Rule: Make the best move for MAX assuming that MIN always replies with the best\nmove for MIN\n2. Easily computed by a recursive process\n3. The backed-up value of each node in the tree is determined by the values of its\nchildren:\n4. For a MAX node, the backed-up value is the maximum of the values of its\nchildren (i.e. the best for MAX)\n5. For a MIN node, the backed-up value is the minimum of the values of its\nchildren (i.e. the best for MIN)\n\nAlpha-beta pruning:\n1. During Minimax, keep track of two additional values:\n\na. α: MAX’s current lower bound on MAX’s outcome\n\nb. β: MIN’s current upper bound on MIN’s outcome\n\n2. MAX will never allow a move that could lead to a worse score (for MAX) than α\n3. MIN will never allow a move that could lead to a better score (for MAX) than β\n\n1. Therefore, stop evaluating a branch whenever:\n2. When evaluating a MAX node: a value � ≥ � is backed-up\n\na. MIN will never select that MAX node When evaluating a MIN node: a value � ≤ � is found\n\nb. MAX will never select that MIN node\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"
      },
      "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 = \"\"\" Constrain Satisfaction Problems:\n",
        "\n",
        "Solutions must satify a set of constraints \n",
        "\n",
        "CSPs consist on:\n",
        "1. Finite set of variables\n",
        "2. Nonempty domain of possible values\n",
        "3. Finite set of constrains where each constrain limits the values that a variable can take\n",
        "\n",
        "CSPS automatically prune odd all branches that violate any constraint\n",
        "\n",
        "\n",
        "Types of constraints:\n",
        "\n",
        "1. Unary = involve one variable\n",
        "2. Binary = involve two variables\n",
        "3. Higher order = involve three or more variables\n",
        "4. Preference = soft constraints\n",
        "\n",
        "Search and backtracking\n",
        "\n",
        "1. Depth-first search for CSPs with single-variable assignments is called\n",
        "backtracking search\n",
        "2.  The term backtracking search is used for a depth-first search that chooses\n",
        "values for one variable at a time and backtracks when a variable has no legal\n",
        "values left to assign.\n",
        "3. Backtracking search is the basic uninformed algorithm for CSPs\n",
        "\n",
        "CSP Heuristics:\n",
        "\n",
        "1. Which variable should be assigned next? = most contrained variable or more constraining variable it ties\n",
        "2. In what order should that variable’s values be tried? = Least constraining value\n",
        "3.  Can we detect inevitable failure early? = Forward checking\n",
        "\n",
        "Forward checking (less expensive than actually iterating):\n",
        "1. Keep track of remaining legal values for unassigned variables\n",
        "2. Terminate search when any unassigned variable has no remaininglegal values\n",
        "\n",
        "\n",
        "CSP Procedure:\n",
        "1. Search: when assigning a value to a variable, take constraint into account\n",
        "2. Discard via arc consistency which satisfies binary constraints\n",
        "\n",
        "Arc consistency: An arc is consistent if and inly if every value v on X is consistent with some label in Y\n",
        "\n",
        "Constraint propagation algorithm\n",
        "1. Assign every node int eh constrain graph a set of ALL possible values\n",
        "2. Repeat until there is no change in the set of values associated with any node...\n",
        "3. For each node i: For each neighboring node j: remove any value from i whhich is not arc consistent with j\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"k consistency csps\" : \"if for any set of k-1 variables and for any consistent assignment to those variables\",  \n",
        "\"K consistency continued\" : \"a consistent value can always be assigned to any kth variable\",\n",
        "\"node consistency\" : \"consistency for k = 1\",\n",
        "\"arc consistency\" : \"consistency for k = 2\",\n",
        "\"path consistency\" : \"consistency for k = 3\",\n",
        "\"strongly consistent\" : \"if it is consitent for all k ... 1\"\n",
        "}\n"
      ],
      "execution_count": 52,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 541
        },
        "outputId": "1ace85c0-70df-4fd5-89ea-746f81e3c207"
      },
      "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": 53,
      "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 Your summary here \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"
      },
      "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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 54,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 541
        },
        "outputId": "2db935dc-b1f7-4212-855b-1d413feb9bad"
      },
      "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": 55,
      "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 Your summary here \n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vX7lbnJd4sT5"
      },
      "source": [
        "# Your Exam Notes\n",
        "\n",
        "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
        "\n",
        "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
        "* Run the cell below. \n",
        "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "8ada2a53-3b01-4615-b6ee-cc8979c124d3"
      },
      "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": 56,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'episodic' is too long!\n# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n ---Turing test (Computer poses a series of questions and a person must identify if it is a computer or human asking them): Intelligent \ncomputer must have natural language processing to communicate in english, knowledge representation to store what it knows, automated resoning\nto use the information and draw conclusions, and machine learning to adapt to new cricumstances. \n\n\n---Cognitive approach (try to investigate \nthe way humans behave to then determine how computers should behave to follow human rationality.\n\n\n---Logical (Machines should follow facts and therefore act in a \nlogical way) \n\n\n---Rational agent (Intelligent systems must use information available to them to make decisions that will give them the best outcome)\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 Agents behave based on their environments \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Rationality maximizes EXPECTED performance, not ACTUAL performance \n\n## AIMA 2.3 The Nature of Environments\n Task environments: Performance measure, Environment, Actuators, Sensors\n\n## AIMA 2.4 The Structure of Agents\n Types of agents.\n\nAgent = architecture + program\n\nprogram implements the agent function\n\narchitecture is where the program runs \n\nSimple reflex agents might have issues of infinite loops that might be avoided through randomizing actions\n\n## Module 1 Lecture Notes\n Agents, environments, etc \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Percept** - an agents perceptual inputs at any given instant\n* **Rationality** - a system that is rational does the right thing given what it knows\n* **Rational agent** - acts ro achieve the best outcome\n* **Agent function** - maps any percept sequence to an action\n* **Agent program** - concrete implementation of how an agent will act\n* **Performance measure** - evaluates any given sequence of environment states to determine how 'good' these are\n* **Information gathering** - doing actions in order to modify future percepts\n* **Autonomous** - a rational agent should learn what it can to compensate from partial knowledge\n* **Actuator** - action available to the agent\n* **Fully observable** - agents senseors give it access to the complete state of the environment\n* **Partially observable** - cannot see the complete state of the environment\n* **Single agent** - one agent\n* **Multi agent** - multiple intelligent agents\n* **Determenistic** - next state of the environment is completely determined by the current state\n* **Stochastic** - next environment state is not certain\n* **Episodic** - divided into time stamps, in each stamp agent gathers info and performs a single task. a decision ONLY affects the next state\n* **Sequential** - a current decision could affect all future decisions\n* **Dynamic** - environment can change while an agent is acting\n* **Static** - environment cannot while an agent is acting\n* **Discrete** - finite number of distinct states\n* **Continuous** - a range of distinct states\n* **Known** - outcomes of actions are given\n* **Unknown** - outcomes of actions are not known\n* **Simple reflix agent** - select actions based on the current perception, ignoring percept history\n* **Model based agent** - uses current percept and old internal state (info) ro generate an updated decription of the current state\n* **Goal based agent** - agent has some sort of goal the descibes situations that are desirable\n* **Utility based agent** - agents have a utility function that internalizes the performance measure\n* **Learning agent** - has a learning element that listens to the critic to fetermine how the performance element should me modified to improve\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Python information \n\n## Module 2 Definitions\n* **Mutability** - your definition here\n\n\n## WARNING: Your definition of 'search tree' is too long!\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 Searching \n\nFormulating a search problem:\n\n1. Decide initial state, goal state and intermediate states\n\n2. Operator set = actions and transition model\n\n3. Path cost function: which action should go next\n\nAlgorithm: Tree Search\nEnumerate in some order all possible paths from the initial state\n\n\n• Here: search through explicit tree generation\n\n\n• ROOT= initial state\n\n\n• Nodes in search tree generated through transition model\n\n\n• Tree search treats different paths to the same node as distinct\n\nAlgorithm: Graph Search\n\n• Simple Mod from tree search: Check to see if a node has been visited\nbefore adding to search queue\n\n\n• Algorithm: BFS\n\nIdea - expand shallowest unexpanded node\n\nFrontier - FIFO Queue\n\nComplete - Yes\n\nOptimal - Yes\n\nTime and space complexity - b^d (where b is maximum branching factor and d is the depth of the least cost solution)\n\n\n• Algorithm: DFS\n\nIdea - expand  deepest unexpanded node\n\nFrontier - LIFO Stack\n\nComplete - No\n\nOptimal - No\n\nTime complexity - b^m (where b is maximum branching factor and m is the max depth of the state space)\n\nSpace complexity - b * m (where b is maximum branching factor and m is the max depth of the state space)\n\n\n\n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that must plan ahead, it considers a sequence of actions that form a path to a goal state\n* **Uninformed** - algos that are given ONLY the problem definition\n* **Informed** - algos are given all info\n* **State** - set of real world states\n* **Action** - equivalence class of combinations of actions\n* **State space** - the set of all states reachable from the initial state by any sequence of actions\n* **Path** - a sequence of actions leading from one state sj to another state sk\n* **Solution** - a path from the initial state si to a state sf that satisfies the goal test\n* **Search tree** - a way of representing the paths that a search algorithm has explored. The root is the initial state, leaves of the tree are successor states\n* **Frontier** - those states that are available for expanding (for applying legal actions to)\n* **Optimal solution** - a solution with lowest path cost\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - non-goal nodes in frontier are ranked\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• Algorithm: A*\n\nNote: Informed search\n\nHeuristic -- f(n) = actual cost so far + estimated total cost to n \n\nIf the heuristic is admissible then A* is optimal\n\nFrontier is a priority queue sorted by increasing cost\n\nTODO: A* space and time complexity\n\n## Module 4 Definitions\n* **Heuristic function** - takes a state n and returns the estimate to the distance from n to the goal\n* **Admissible** - a heuristic is admissible if it never overestimated the cost to reach the goal\n* **Relaxed problem** - has fewer restrictions on the actions that the original is. Many heuristics are declared on relaxed problems\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 Games:\n\nFormalizing:\n\n1. Two players: MAX and MIN; MAX moves first.\n2. MAX and MIN take turns until the game is over.\n3. Winner gets award, loser gets penalty.\n\n\nGeneral Scheme\n1. Consider all legal successors to the current state (‘board position’)\n2. Evaluate each successor board position\n3. Pick the move which leads to the best board position.\n4. After your opponent moves, repeat.\n\n\nGame trees:\nRepresent the game problem space by a tree:\n1. Nodes represent ‘board positions’; edges represent legal moves.\n2. Root node is the first position in which a decision must be made.\n\n Two players: MAX, MAX’s opponent MIN\n1. All play is computed from MAX’s vantage point.\n2. When MAX moves, MAX attempts to MAXimize MAX’s outcome.\n3. When MAX’s opponent moves, they attempt to MINimize MAX’s outcome.\n4. WE TYPICALLY ASSUME MAX MOVES FIRST:\n5. Label the root (level 0) MAX\n6. Alternate MAX/MIN labels at each successive tree level (ply).\n7. Even levels represent turns for MAX\n8. Odd levels represent turns for MIN\n\nEvaluation function:\n1. Evaluates how good a ‘board position’ is\n2. Based on static features of that board alone\n3. Zero-sum assumption lets us use one function to describe goodness for both players.\n4. f(n)>0 if MAX is winning in position n\n5. f(n)=0 if position n is tied\n6. f(n)<0 if MIN is winning in position n\n\nMinimax:\n1. Rule: Make the best move for MAX assuming that MIN always replies with the best\nmove for MIN\n2. Easily computed by a recursive process\n3. The backed-up value of each node in the tree is determined by the values of its\nchildren:\n4. For a MAX node, the backed-up value is the maximum of the values of its\nchildren (i.e. the best for MAX)\n5. For a MIN node, the backed-up value is the minimum of the values of its\nchildren (i.e. the best for MIN)\n\nAlpha-beta pruning:\n1. During Minimax, keep track of two additional values:\n\na. α: MAX’s current lower bound on MAX’s outcome\n\nb. β: MIN’s current upper bound on MIN’s outcome\n\n2. MAX will never allow a move that could lead to a worse score (for MAX) than α\n3. MIN will never allow a move that could lead to a better score (for MAX) than β\n\n1. Therefore, stop evaluating a branch whenever:\n2. When evaluating a MAX node: a value � ≥ � is backed-up\n\na. MIN will never select that MAX node When evaluating a MIN node: a value � ≤ � is found\n\nb. MAX will never select that MIN node\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 Your summary here \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 Your summary here \n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}