{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "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/",
          "height": 0
        },
        "outputId": "98ae7b73-4414-4d54-8dfe-36a6afb244bd"
      },
      "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": 26,
      "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/",
          "height": 0
        },
        "outputId": "89f49ef3-3ca1-4aa7-ccd0-7dbc44112835"
      },
      "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": 27,
      "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": 28,
      "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 = \"\"\" There are a number of ways to define AI that have changed over time. The Turing Model focuses on actring humanly. The cognitive modeling approach \n",
        "focuses on thinking humanly. The laws of thought approach focuses on thinking rationally. The rational agent approach focuses on acting rationally.  \"\"\" \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 act in environments. Agents perceive their environments through sensors. A percept is the agent's current inputs from its sensors, whereas\n",
        "its percept sequence is a complete history of everything it has perceived up until the current moment. An agent function takes a current percept and maps that on to \n",
        "an action for the agent given that percept or set of percepts. An agent program is the program that implements the agent function and allows it to act on its environment. \"\"\"\n",
        "chapter2_2 = \"\"\" We can define good behavior for agents in many ways, but the best is likely rationality - doing the right thing. We evaluate the rightness of an action by using \n",
        "a performance measure. The performance measure will evaluate how good an action is. A rational agent needs to learn as much as it can from it's percepts. \"\"\"\n",
        "chapter2_3 = \"\"\" Task environments are the environments in which rational agents operate. They are defined by a number of parameters. The first is whether the environment is fully observable \n",
        "or partially observable. Fully observable means that an agent's sensors give it access to the complete state of the environment at any given time. Anything less is a partially observable environment.\n",
        "An environment could also be unobservable (no sensors whatsoever). Single agent vs. multi-agent - single agent environments have only one agent. Multi-agent environemnts have more than one. \n",
        "A crossword puzzle solving agent would be a single-agent env, whereas a chess one would be multi-agent. Multi-agent environments can be either cooperative or competitive.\n",
        "Determinisitc vs. non-deterministic - A deterministic environment means that the next state of the environment will be fully determined by the action taken by the agent on the current environment. A non-deterministic environment\n",
        "involves many more factors. A stochastic environment is an environment that deals with probabilities - a 25% chance of one thing happening and a 75% of another given a certain action.\n",
        "Discrete vs. continuous has to do with how time functions in the environment. Continuous means that percepts and such are constantly changing.  \n",
        " \"\"\"\n",
        "chapter2_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 1.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module1_definitions = {\n",
        "\"agent\" : \"anything that can perceive (sensors) and act in an environment (actuators)\",\n",
        "\"percept\" : \"an agent's perceptual inputs at any given instance\",\n",
        "\"agent function\" : \"A function that maps a sequence of percept vectors to an action\",\n",
        "\"agent program\": \"runs on the physical archtecture -> agent = architecture + program\",\n",
        "\"performance measure\": \"an objective criterion for success of an agent's behavior - determined by a score\",\n",
        "\"expected value\": \"a rational agent tries to maximize the expected value of its performance measure\",\n",
        "\"task environment\": \"a problem specification for which the agent is a solution\",\n",
        "\"PEAS\": \"An acronym for the components of a task environment - Performance measure, environment, actuators, sensors\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 29,
      "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": 997
        },
        "cellView": "form",
        "outputId": "05bda67b-68e6-422b-88c9-2e2ec74092c2"
      },
      "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": 30,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n There are a number of ways to define AI that have changed over time. The Turing Model focuses on actring humanly. The cognitive modeling approach \nfocuses on thinking humanly. The laws of thought approach focuses on thinking rationally. The rational agent approach focuses on acting rationally.  \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 act in environments. Agents perceive their environments through sensors. A percept is the agent's current inputs from its sensors, whereas\nits percept sequence is a complete history of everything it has perceived up until the current moment. An agent function takes a current percept and maps that on to \nan action for the agent given that percept or set of percepts. An agent program is the program that implements the agent function and allows it to act on its environment. \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n We can define good behavior for agents in many ways, but the best is likely rationality - doing the right thing. We evaluate the rightness of an action by using \na performance measure. The performance measure will evaluate how good an action is. A rational agent needs to learn as much as it can from it's percepts. \n\n## AIMA 2.3 The Nature of Environments\n Task environments are the environments in which rational agents operate. They are defined by a number of parameters. The first is whether the environment is fully observable \nor partially observable. Fully observable means that an agent's sensors give it access to the complete state of the environment at any given time. Anything less is a partially observable environment.\nAn environment could also be unobservable (no sensors whatsoever). Single agent vs. multi-agent - single agent environments have only one agent. Multi-agent environemnts have more than one. \nA crossword puzzle solving agent would be a single-agent env, whereas a chess one would be multi-agent. Multi-agent environments can be either cooperative or competitive.\nDeterminisitc vs. non-deterministic - A deterministic environment means that the next state of the environment will be fully determined by the action taken by the agent on the current environment. A non-deterministic environment\ninvolves many more factors. A stochastic environment is an environment that deals with probabilities - a 25% chance of one thing happening and a 75% of another given a certain action.\nDiscrete vs. continuous has to do with how time functions in the environment. Continuous means that percepts and such are constantly changing.  \n \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (sensors) and act in an environment (actuators)\n* **Percept** - an agent's perceptual inputs at any given instance\n* **Agent function** - A function that maps a sequence of percept vectors to an action\n* **Agent program** - runs on the physical archtecture -> agent = architecture + program\n* **Performance measure** - an objective criterion for success of an agent's behavior - determined by a score\n* **Expected value** - a rational agent tries to maximize the expected value of its performance measure\n* **Task environment** - a problem specification for which the agent is a solution\n* **Peas** - An acronym for the components of a task environment - Performance measure, environment, actuators, sensors\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 = \"\"\" Slicing returns a copy of a subsequence. You can return multiple items from a python function, packed as a tuple. \n",
        "*args allows you to pass in a variable number of non-keyword arguments to a function. **kwargs allows you to pass in a variable number of keyword arguments.\n",
        "List comprehensions allow you to make lists in a single line. Can also add conditionals to list comprehensions. Iterators are objects with a \"next\" command. Iterators use memory efficiently.\n",
        "Generators allow you to use 'yield' keyword to return a generator. Each time the method is called, it runs until it encounters a yield and returns the yielded value. Then it resumes where it left off on the next pass.  \n",
        "These are crucial for infinite sequences and are good for aggregating since you only need one pass. If you need to look at individual values, they're less great. \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"objects that are mutable can be changed. Lists are mutable, tuples are not. \",\n",
        "}"
      ],
      "execution_count": 31,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 294
        },
        "outputId": "1f6bfb5b-2bc6-4cc5-85b0-3f81e81b17d5"
      },
      "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": 32,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n Slicing returns a copy of a subsequence. You can return multiple items from a python function, packed as a tuple. \n*args allows you to pass in a variable number of non-keyword arguments to a function. **kwargs allows you to pass in a variable number of keyword arguments.\nList comprehensions allow you to make lists in a single line. Can also add conditionals to list comprehensions. Iterators are objects with a \"next\" command. Iterators use memory efficiently.\nGenerators allow you to use 'yield' keyword to return a generator. Each time the method is called, it runs until it encounters a yield and returns the yielded value. Then it resumes where it left off on the next pass.  \nThese are crucial for infinite sequences and are good for aggregating since you only need one pass. If you need to look at individual values, they're less great. \n\n## Module 2 Definitions\n* **Mutability** - objects that are mutable can be changed. Lists are mutable, tuples are not. \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 = \"\"\" Problem solving agents work toward solving a problem. They begin with a goal formulation and adopt a specific goal, a problem formulation so that they understand the nature of the problem, a search of possible actions (before they even undertake one themselves), and exectue on the prior steps. \n",
        "There can be open loop or closed loop systems. Open loop the percepts can be ignored at any given stage because the correct outcome is already guaranteed by the search. A search problem consists of a set of states called the state space, an initial state for the agent, a set of goal states, actions available to the agent, a transition model that describes what each action does, and an action cost function that calculates the numeric cost of a given action. \n",
        "A solution is a path from the intial state to the goal state, an optimal one is one that can be done in the lowest path cost among all possiblities. The process of removing detail from the representaiton of the search space is called abstraction.\n",
        " \"\"\"\n",
        "chapter3_2 = \"\"\" There are several different types of search problems. Route finding problems are about navigating locations and the transitions between the steps in that process. Touring problems are problems in which several locations must be visited. VLSI layout problems require placing millions of components to minimize space. Robot navigation problems involve robots navigating in the real world. Automatic assembly sequencing problems involve the manufacturing of goods and ensuring parts are put together in the correct order. \"\"\"\n",
        "chapter3_3 = \"\"\" A search algorithm takes a search problem and returns a solution. We look at individual nodes that orrespond to a state in the state space and expand a given node to see the actions that could be taken from that particular node. There are several search algorithms we covered. Best first search is a method that looks at the children nodes and chooses one based on a given evaluation function to find the best path. We can have redundant paths in these trees, but we usually trim the \"go back\" options unless there is a reason to keep them. \"\"\"\n",
        "chapter3_4 = \"\"\" We covered a couple uninformed search strategies. Breadth First Search uses a FIFO queue and children nodes are added when they are expanded. Goal states are checked when nodes are generated. Uniform cost search uses the cost from the root to the current node as an evaluation function to determine which path should be taken and it takes the lowest cost path. Depth first search expands the deepest node of the frontier first using a LIFO queue. Iterative deepening search is a hybrid of BFS and DFS. Bidirectional search goes simultaneously from the initial state and the goal state to try and find a solution. Backtracking remembers a state and checks for solutions and goes back to that state to make another choice if there was no solution yielded.   \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" BFS is not complete, fails in infinite depth spaces, has time complexity of O(b^m) terrible if max depth (m) is larger than depth of least cost solution (d), space complexity is O(b*m), it isn't optimal. Iterative depth search is complete, time complexity is O(b^d), space complexity O(bd), and optimal if step cost is 1.  \"\"\"\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 agents\": \"don't plan ahead. Make decisions only based on current percepts\",\n",
        "\"solution\": \"a sequence of actions from the intitial state to goal\",\n",
        "\"optimal solution\": \"a solution with the lowest path cost of all possible solutions\",\n",
        "\"frontier\": \"all the nodes available for expanding\", \n",
        "\"uninformed search\": \"all non-goal nodes in frontier look equally good\",\n",
        "\"informed search\": \"some nodes get ranked above others\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 33,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 865
        },
        "outputId": "4abcea92-5597-41f1-f7cd-783b3433a21f"
      },
      "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": 34,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Problem solving agents work toward solving a problem. They begin with a goal formulation and adopt a specific goal, a problem formulation so that they understand the nature of the problem, a search of possible actions (before they even undertake one themselves), and exectue on the prior steps. \nThere can be open loop or closed loop systems. Open loop the percepts can be ignored at any given stage because the correct outcome is already guaranteed by the search. A search problem consists of a set of states called the state space, an initial state for the agent, a set of goal states, actions available to the agent, a transition model that describes what each action does, and an action cost function that calculates the numeric cost of a given action. \nA solution is a path from the intial state to the goal state, an optimal one is one that can be done in the lowest path cost among all possiblities. The process of removing detail from the representaiton of the search space is called abstraction.\n \n\n## AIMA Chapter 3.2 Example Problems\n There are several different types of search problems. Route finding problems are about navigating locations and the transitions between the steps in that process. Touring problems are problems in which several locations must be visited. VLSI layout problems require placing millions of components to minimize space. Robot navigation problems involve robots navigating in the real world. Automatic assembly sequencing problems involve the manufacturing of goods and ensuring parts are put together in the correct order. \n\n## AIMA Chapter 3.3 Search Algorithms\n A search algorithm takes a search problem and returns a solution. We look at individual nodes that orrespond to a state in the state space and expand a given node to see the actions that could be taken from that particular node. There are several search algorithms we covered. Best first search is a method that looks at the children nodes and chooses one based on a given evaluation function to find the best path. We can have redundant paths in these trees, but we usually trim the \"go back\" options unless there is a reason to keep them. \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n We covered a couple uninformed search strategies. Breadth First Search uses a FIFO queue and children nodes are added when they are expanded. Goal states are checked when nodes are generated. Uniform cost search uses the cost from the root to the current node as an evaluation function to determine which path should be taken and it takes the lowest cost path. Depth first search expands the deepest node of the frontier first using a LIFO queue. Iterative deepening search is a hybrid of BFS and DFS. Bidirectional search goes simultaneously from the initial state and the goal state to try and find a solution. Backtracking remembers a state and checks for solutions and goes back to that state to make another choice if there was no solution yielded.   \n\n## Module 3 Lecture Notes\n BFS is not complete, fails in infinite depth spaces, has time complexity of O(b^m) terrible if max depth (m) is larger than depth of least cost solution (d), space complexity is O(b*m), it isn't optimal. Iterative depth search is complete, time complexity is O(b^d), space complexity O(bd), and optimal if step cost is 1.  \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Reflex agents** - don't plan ahead. Make decisions only based on current percepts\n* **Solution** - a sequence of actions from the intitial state to goal\n* **Optimal solution** - a solution with the lowest path cost of all possible solutions\n* **Frontier** - all the nodes available for expanding\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - some nodes get ranked above others\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 = \"\"\" Informed search is able to discriminate between potential nodes that are expanded. It does this using a heuristic function (an estimate of what's best). One method is greedy best first search. It will always expand the node with the lowest heuristic cost. A* search is a best of both worlds approach whose heuristic is a combination of an estimate of the path to the goal state and the path cost so far added together. The estimate to the goal must not exceed the real cost - this is an admissible heuristic. A heuristic is consistent if for every node, when the path cost so far is increasing, the cost to go is decreasing. Pruning is a method that allows us to get rid of nodes that won't contain an optimal solution. There are several varieties of A*, including weighted A*, where we weight the heuristic value more heavily than the path cost. Beam search limits the size of the frontier to only hold the nodes with the best scores. Iterative deepening A* doesn't keep all visited states in memory. MA* and SMA* each of these will keep all prior nodes until memory is full and then start bumping a node out to make room for a new one.  \"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Inadmissible (pessimistic) heuristics break optimality by trapping good plans on the frontier. Admissible (optimistic) heuristics slow down bad plans but never outweigh true costs. A problem with fewer restrictuions on the actions than the original is a relaxed problem. The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.  \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 35,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 477
        },
        "cellView": "form",
        "outputId": "f3b24152-8e94-4bc6-847b-0bcba68b5158"
      },
      "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": 36,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Informed search is able to discriminate between potential nodes that are expanded. It does this using a heuristic function (an estimate of what's best). One method is greedy best first search. It will always expand the node with the lowest heuristic cost. A* search is a best of both worlds approach whose heuristic is a combination of an estimate of the path to the goal state and the path cost so far added together. The estimate to the goal must not exceed the real cost - this is an admissible heuristic. A heuristic is consistent if for every node, when the path cost so far is increasing, the cost to go is decreasing. Pruning is a method that allows us to get rid of nodes that won't contain an optimal solution. There are several varieties of A*, including weighted A*, where we weight the heuristic value more heavily than the path cost. Beam search limits the size of the frontier to only hold the nodes with the best scores. Iterative deepening A* doesn't keep all visited states in memory. MA* and SMA* each of these will keep all prior nodes until memory is full and then start bumping a node out to make room for a new one.  \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Inadmissible (pessimistic) heuristics break optimality by trapping good plans on the frontier. Admissible (optimistic) heuristics slow down bad plans but never outweigh true costs. A problem with fewer restrictuions on the actions than the original is a relaxed problem. The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.  \n\n## Module 4 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" In competitive environments, we use adversarial search. Adversarial search problems arise when two or more agents have conflicting goals. Pruning is the process of removing certain potential plays that we know won't lead to an optimal solution. We use a heurisitic evaluation function to determine who is winning based on a game state at any given time (remaining moves, highest score so far, etc.). For adversarial search, we have a set of the initial state, to-move player, actions available to them, result of the move (by applying the transition model), a check to see if we've reached the end of all plays or game over, and a utility function which defines the score of a player at state s. \"\"\"\n",
        "chapter5_2 = \"\"\" Minimax search divides a tree into tiers. Each tier is either the current player or their opponent. The current player is always trying to maximize their score while minimizing the score of the opponent. The algorithm consists of 3 functions, the minimax function which returns the move the player should make, a max function, which returns a utility move pair and calls the min value function in itself recursively to try and find the lowest value for it's opponent (the opponent's most optimal plays). Once it's value has been maximized and the other player's has been minimized, the result is returned to the function and the play can be executed. Alpha-beta pruning allows us to prune off branches of the minimax tree that would not lead to an optimal play for the current player. It does this by examining each tier of the minimax tree and, if a value is lower than the current max or higher than the current min, we know that player will never choose that outcome in an optimal world, so we can prune it. Even with alpha beta pruning and move ordering, minimax doesn't work for games like chess and Go because there are too many states. As such, we use either Type A or B strategy. These involve considering all possible moves to a certain depth and then using a heuristic to evaluate the utility of states at that depth. A explores wide but shallow. B ignores moves taht look bad and follows promising lines of play as far as it can. It explores a deep but narrow portion of the tree.  \"\"\"\n",
        "chapter5_3 = \"\"\" Evaluation functions allow us to treat nonterminal nodes as if they were terminal and assess the utility of the plays that led to that game state. This allows us to speed up computation vs. looking through every single game state to try and arrive at an optimal play. An evaluation function essentially lets us analyze the \"goodness\" of a board at any given point and decide if that is the most optimal position we could be in, given the limited depth we are looking into the tree (think domino game move limit). Quiescence is a state where there is no pending move that would wildly swing the evaluation function (a winning move pending). The horizon effect should also be minimized, where you can \"delay the inevitable\", but ultimately will be in a worse state than just letting the inevitable happen (a rook will get captured, but you can move it around a lot and lose the rook and 3 pawns). Forward pruning can be applied to limit the field of moves to only those moves that appear good. You may lose good moves in the pruning process, however.  \"\"\"\n",
        "chapter5_5 = \"\"\" Stochastic games introduce an element of randomness to a game, such as throwing dice. Chance nodes help us to account for possible random outcomes in stochastic games. Eval functions for games of chance must include the probablity of certain outcomes occurring.  \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" We combine the results of a utility function and get the average of that with the probability that the outcome occurs to give us the expected utility. We want to utilize the principle of maximum expected utility to choose the action that maximizes expected utility. \"\"\"\n",
        "chapter16_2 = \"\"\" There are several constraints on rational performance. Orderability means that things must be able to be ranked relative to each other. Transitivity means that if b is better than a and c is better than b, then an agent would prefer c to a. Monotonicity means that if it comes down to two equal outcomes, the agent should prefer the one with higher probability of occurring.  \"\"\"\n",
        "chapter16_3 = \"\"\" There are several problems that arise in statistical analysis of outcomes.  \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" All play is computed from Max's point of view. Even levels represent turns for max, odd represent turns for min. For alpha beta pruning, alpha is Max's current lower bound on Max's outcome (think at least) and beta is the current upper bound on min's outcome (think at most). Max will never allow a move that could lead to a worse score for max than alpha. And min will never allow a move that could lead to a better score for max than beta. In expectimax search, max nodes are treated as they are in minimax, but the min nodes are chance nodes where we calculate the expected utility (weighted average of children). Each line is a probability to the utility of reached the node. Simply multiply to get the expected utility. For example, if the utiliy of a node in the second ply is 12, but we have a 1/2 chance of getting there, then the expected utility is 6 for that branch.  \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"Ply\" : \"One level of the game. Each state will be in a play and have children nodes in the next ply\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 37,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1150
        },
        "outputId": "3a15e160-b39f-42e5-b35d-50d4d8d78e3f"
      },
      "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": 38,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n In competitive environments, we use adversarial search. Adversarial search problems arise when two or more agents have conflicting goals. Pruning is the process of removing certain potential plays that we know won't lead to an optimal solution. We use a heurisitic evaluation function to determine who is winning based on a game state at any given time (remaining moves, highest score so far, etc.). For adversarial search, we have a set of the initial state, to-move player, actions available to them, result of the move (by applying the transition model), a check to see if we've reached the end of all plays or game over, and a utility function which defines the score of a player at state s. \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Minimax search divides a tree into tiers. Each tier is either the current player or their opponent. The current player is always trying to maximize their score while minimizing the score of the opponent. The algorithm consists of 3 functions, the minimax function which returns the move the player should make, a max function, which returns a utility move pair and calls the min value function in itself recursively to try and find the lowest value for it's opponent (the opponent's most optimal plays). Once it's value has been maximized and the other player's has been minimized, the result is returned to the function and the play can be executed. Alpha-beta pruning allows us to prune off branches of the minimax tree that would not lead to an optimal play for the current player. It does this by examining each tier of the minimax tree and, if a value is lower than the current max or higher than the current min, we know that player will never choose that outcome in an optimal world, so we can prune it. Even with alpha beta pruning and move ordering, minimax doesn't work for games like chess and Go because there are too many states. As such, we use either Type A or B strategy. These involve considering all possible moves to a certain depth and then using a heuristic to evaluate the utility of states at that depth. A explores wide but shallow. B ignores moves taht look bad and follows promising lines of play as far as it can. It explores a deep but narrow portion of the tree.  \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Evaluation functions allow us to treat nonterminal nodes as if they were terminal and assess the utility of the plays that led to that game state. This allows us to speed up computation vs. looking through every single game state to try and arrive at an optimal play. An evaluation function essentially lets us analyze the \"goodness\" of a board at any given point and decide if that is the most optimal position we could be in, given the limited depth we are looking into the tree (think domino game move limit). Quiescence is a state where there is no pending move that would wildly swing the evaluation function (a winning move pending). The horizon effect should also be minimized, where you can \"delay the inevitable\", but ultimately will be in a worse state than just letting the inevitable happen (a rook will get captured, but you can move it around a lot and lose the rook and 3 pawns). Forward pruning can be applied to limit the field of moves to only those moves that appear good. You may lose good moves in the pruning process, however.  \n\n## AIMA Chapter 5.5 Stochastic Games\n Stochastic games introduce an element of randomness to a game, such as throwing dice. Chance nodes help us to account for possible random outcomes in stochastic games. Eval functions for games of chance must include the probablity of certain outcomes occurring.  \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n We combine the results of a utility function and get the average of that with the probability that the outcome occurs to give us the expected utility. We want to utilize the principle of maximum expected utility to choose the action that maximizes expected utility. \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n There are several constraints on rational performance. Orderability means that things must be able to be ranked relative to each other. Transitivity means that if b is better than a and c is better than b, then an agent would prefer c to a. Monotonicity means that if it comes down to two equal outcomes, the agent should prefer the one with higher probability of occurring.  \n\n## AIMA Chapter 16.3 Utility Functions\n There are several problems that arise in statistical analysis of outcomes.  \n\n## Module 5 Lecture Notes\n All play is computed from Max's point of view. Even levels represent turns for max, odd represent turns for min. For alpha beta pruning, alpha is Max's current lower bound on Max's outcome (think at least) and beta is the current upper bound on min's outcome (think at most). Max will never allow a move that could lead to a worse score for max than alpha. And min will never allow a move that could lead to a better score for max than beta. In expectimax search, max nodes are treated as they are in minimax, but the min nodes are chance nodes where we calculate the expected utility (weighted average of children). Each line is a probability to the utility of reached the node. Simply multiply to get the expected utility. For example, if the utiliy of a node in the second ply is 12, but we have a 1/2 chance of getting there, then the expected utility is 6 for that branch.  \n\n## Module 5 Definitions\n* **Ply** - One level of the game. Each state will be in a play and have children nodes in the next ply\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 = \"\"\" Constraint satisfaction problems consist of a set of variables, a set of domains, one for each variable, and a set of constraints of allowable combinations of values. A legal assignment of a value to a variable is called consistent. A solution is a consistent, complete assignment. A precedence constraint controls when one thing must come before another. \"\"\"\n",
        "chapter6_2 = \"\"\" Constraint propagation allows us to use the constraints to restrict the number of possible values in the domain for each variable. Node consistency refres to when all the values in teh variable's domain satisfy the variable's unary constraints (constraints that apply only to it). Arc consistency refers to when every value in a variable's domain satisfires the variable's binary constraints (constraints between it and another node). Path consistency is when triples of variables have values that are consistent. K-consistency is the same for k nodes.  \"\"\"\n",
        "chapter6_3 = \"\"\" Backtracking allows us to check the possible values for each variable. If there is no solution when we assign one of them we prune that value and pick the next one. And so on until we end up with a value that works. Choosing the node with the fewest remaining legal values is called minimum-remaining-values (MRV) heuristic. Degree heuristic tries to reduce the branching factor by picking the variable that is involved in the largest number of constraints on other assigned variables. Least constraining value looks at the value that will heave the fewest impacts on its neighbors.  \"\"\"\n",
        "chapter6_4 = \"\"\" Min conflicts heuristic allows us to look at values that resutl in the minimum number of conflicts with other nodes. Constraint weighting concentrates teh search on the important constraints by assigning constraints a numeric weight. \"\"\"\n",
        "chapter6_5 = \"\"\" We want to reduce a CSP down to a tree, eventually. Identifying independent subproblems allows us to isolate variables that will never have an impact on each other. Tree decomposition involves taking a constraint graph and structuring it as a tree where each node has a set of variables \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\" In sudoku, we can represent the puzzle as a CSP with each node being assigned a domain of possible values that could fill it. Once each node has only one associated value, the puzzle is solved. The benefits of CSP are that it is a clean specification of many problems and can be solved with a generic group of functions, CSP knows which variables violate constraints and can focus search accordingly, and CSP automatically prunes off branches that violate constraints, so no time wasted examining them. Types of constraints oinclude unary (involving a single variable, spot A can't be green), binary (involving 2 variables, A and B can't be same color), higher-order constraints (3 or more variables), preference (red is better than green, but is not required to be red). AC-3 has a Worst case complexity is O(n^2*d^3). Whenever we remove a value from a node x, all of the values on all of x's neighbors must be re-examined because removing a value from a node may result in one of the neighbors becoming arc inconsistent.  \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 39,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 813
        },
        "outputId": "73421e5a-1be9-4826-b728-3e5e0c72a739"
      },
      "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": 40,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Constraint satisfaction problems consist of a set of variables, a set of domains, one for each variable, and a set of constraints of allowable combinations of values. A legal assignment of a value to a variable is called consistent. A solution is a consistent, complete assignment. A precedence constraint controls when one thing must come before another. \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Constraint propagation allows us to use the constraints to restrict the number of possible values in the domain for each variable. Node consistency refres to when all the values in teh variable's domain satisfy the variable's unary constraints (constraints that apply only to it). Arc consistency refers to when every value in a variable's domain satisfires the variable's binary constraints (constraints between it and another node). Path consistency is when triples of variables have values that are consistent. K-consistency is the same for k nodes.  \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Backtracking allows us to check the possible values for each variable. If there is no solution when we assign one of them we prune that value and pick the next one. And so on until we end up with a value that works. Choosing the node with the fewest remaining legal values is called minimum-remaining-values (MRV) heuristic. Degree heuristic tries to reduce the branching factor by picking the variable that is involved in the largest number of constraints on other assigned variables. Least constraining value looks at the value that will heave the fewest impacts on its neighbors.  \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Min conflicts heuristic allows us to look at values that resutl in the minimum number of conflicts with other nodes. Constraint weighting concentrates teh search on the important constraints by assigning constraints a numeric weight. \n\n## AIMA Chapter 6.5 The Structure of Problems\n We want to reduce a CSP down to a tree, eventually. Identifying independent subproblems allows us to isolate variables that will never have an impact on each other. Tree decomposition involves taking a constraint graph and structuring it as a tree where each node has a set of variables \n\n## Module 6 Lecture Notes\n In sudoku, we can represent the puzzle as a CSP with each node being assigned a domain of possible values that could fill it. Once each node has only one associated value, the puzzle is solved. The benefits of CSP are that it is a clean specification of many problems and can be solved with a generic group of functions, CSP knows which variables violate constraints and can focus search accordingly, and CSP automatically prunes off branches that violate constraints, so no time wasted examining them. Types of constraints oinclude unary (involving a single variable, spot A can't be green), binary (involving 2 variables, A and B can't be same color), higher-order constraints (3 or more variables), preference (red is better than green, but is not required to be red). AC-3 has a Worst case complexity is O(n^2*d^3). Whenever we remove a value from a node x, all of the values on all of x's neighbors must be re-examined because removing a value from a node may result in one of the neighbors becoming arc inconsistent.  \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 = \"\"\" Entailment is the idea that a sentence follows logically from another sentence. Soundness is necessary for an inference algorithm, otherwise it would just make stuff up as it goes along and makes incorrect decisions. Grounding is the connection between logical reasoning processes and the real environment in which the agent exists. \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" Knowlege-based agents use a process of reasoning over an internal representation of knowledge to decide what action to take. A knowledge base contains a set of sentences that are written in a knowledge representation language to make an assertion about the world (grass is green).There are two kinds of sesntences, axioms (given), and derived (arrived at through inference based on old sentences). Remember Wampa world. R2's sensors include stench, gasp, breeze, scream, and bump. Given its inputs, R2 can navigate the world and make assumptions about which squares are safe to move to. Logical inference allows us to add to the knowledge base through derived sentences (a is derived from KB by i). Remember truth tables (confusing one is if then, outcomes are true, false, true true, think of as promise). Biconditional (iff) (true, false, false, true). An inference algorithm is sound if it only derives entailed sentences, it is complete if it can derive all sentences that are entailed. \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 41,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 677
        },
        "outputId": "fd671e08-f9d1-46df-9391-cde1dd5f9635"
      },
      "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": 42,
      "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 Entailment is the idea that a sentence follows logically from another sentence. Soundness is necessary for an inference algorithm, otherwise it would just make stuff up as it goes along and makes incorrect decisions. Grounding is the connection between logical reasoning processes and the real environment in which the agent exists. \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 Knowlege-based agents use a process of reasoning over an internal representation of knowledge to decide what action to take. A knowledge base contains a set of sentences that are written in a knowledge representation language to make an assertion about the world (grass is green).There are two kinds of sesntences, axioms (given), and derived (arrived at through inference based on old sentences). Remember Wampa world. R2's sensors include stench, gasp, breeze, scream, and bump. Given its inputs, R2 can navigate the world and make assumptions about which squares are safe to move to. Logical inference allows us to add to the knowledge base through derived sentences (a is derived from KB by i). Remember truth tables (confusing one is if then, outcomes are true, false, true true, think of as promise). Biconditional (iff) (true, false, false, true). An inference algorithm is sound if it only derives entailed sentences, it is complete if it can derive all sentences that are entailed. \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": 5134
        },
        "id": "T3cm1WV542_a",
        "outputId": "a9702de4-fc57-4786-dcec-4c7bc0945825"
      },
      "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": 43,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n There are a number of ways to define AI that have changed over time. The Turing Model focuses on actring humanly. The cognitive modeling approach \nfocuses on thinking humanly. The laws of thought approach focuses on thinking rationally. The rational agent approach focuses on acting rationally.  \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 act in environments. Agents perceive their environments through sensors. A percept is the agent's current inputs from its sensors, whereas\nits percept sequence is a complete history of everything it has perceived up until the current moment. An agent function takes a current percept and maps that on to \nan action for the agent given that percept or set of percepts. An agent program is the program that implements the agent function and allows it to act on its environment. \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n We can define good behavior for agents in many ways, but the best is likely rationality - doing the right thing. We evaluate the rightness of an action by using \na performance measure. The performance measure will evaluate how good an action is. A rational agent needs to learn as much as it can from it's percepts. \n\n## AIMA 2.3 The Nature of Environments\n Task environments are the environments in which rational agents operate. They are defined by a number of parameters. The first is whether the environment is fully observable \nor partially observable. Fully observable means that an agent's sensors give it access to the complete state of the environment at any given time. Anything less is a partially observable environment.\nAn environment could also be unobservable (no sensors whatsoever). Single agent vs. multi-agent - single agent environments have only one agent. Multi-agent environemnts have more than one. \nA crossword puzzle solving agent would be a single-agent env, whereas a chess one would be multi-agent. Multi-agent environments can be either cooperative or competitive.\nDeterminisitc vs. non-deterministic - A deterministic environment means that the next state of the environment will be fully determined by the action taken by the agent on the current environment. A non-deterministic environment\ninvolves many more factors. A stochastic environment is an environment that deals with probabilities - a 25% chance of one thing happening and a 75% of another given a certain action.\nDiscrete vs. continuous has to do with how time functions in the environment. Continuous means that percepts and such are constantly changing.  \n \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (sensors) and act in an environment (actuators)\n* **Percept** - an agent's perceptual inputs at any given instance\n* **Agent function** - A function that maps a sequence of percept vectors to an action\n* **Agent program** - runs on the physical archtecture -> agent = architecture + program\n* **Performance measure** - an objective criterion for success of an agent's behavior - determined by a score\n* **Expected value** - a rational agent tries to maximize the expected value of its performance measure\n* **Task environment** - a problem specification for which the agent is a solution\n* **Peas** - An acronym for the components of a task environment - Performance measure, environment, actuators, sensors\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Slicing returns a copy of a subsequence. You can return multiple items from a python function, packed as a tuple. \n*args allows you to pass in a variable number of non-keyword arguments to a function. **kwargs allows you to pass in a variable number of keyword arguments.\nList comprehensions allow you to make lists in a single line. Can also add conditionals to list comprehensions. Iterators are objects with a \"next\" command. Iterators use memory efficiently.\nGenerators allow you to use 'yield' keyword to return a generator. Each time the method is called, it runs until it encounters a yield and returns the yielded value. Then it resumes where it left off on the next pass.  \nThese are crucial for infinite sequences and are good for aggregating since you only need one pass. If you need to look at individual values, they're less great. \n\n## Module 2 Definitions\n* **Mutability** - objects that are mutable can be changed. Lists are mutable, tuples are not. \n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Problem solving agents work toward solving a problem. They begin with a goal formulation and adopt a specific goal, a problem formulation so that they understand the nature of the problem, a search of possible actions (before they even undertake one themselves), and exectue on the prior steps. \nThere can be open loop or closed loop systems. Open loop the percepts can be ignored at any given stage because the correct outcome is already guaranteed by the search. A search problem consists of a set of states called the state space, an initial state for the agent, a set of goal states, actions available to the agent, a transition model that describes what each action does, and an action cost function that calculates the numeric cost of a given action. \nA solution is a path from the intial state to the goal state, an optimal one is one that can be done in the lowest path cost among all possiblities. The process of removing detail from the representaiton of the search space is called abstraction.\n \n\n## AIMA Chapter 3.2 Example Problems\n There are several different types of search problems. Route finding problems are about navigating locations and the transitions between the steps in that process. Touring problems are problems in which several locations must be visited. VLSI layout problems require placing millions of components to minimize space. Robot navigation problems involve robots navigating in the real world. Automatic assembly sequencing problems involve the manufacturing of goods and ensuring parts are put together in the correct order. \n\n## AIMA Chapter 3.3 Search Algorithms\n A search algorithm takes a search problem and returns a solution. We look at individual nodes that orrespond to a state in the state space and expand a given node to see the actions that could be taken from that particular node. There are several search algorithms we covered. Best first search is a method that looks at the children nodes and chooses one based on a given evaluation function to find the best path. We can have redundant paths in these trees, but we usually trim the \"go back\" options unless there is a reason to keep them. \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n We covered a couple uninformed search strategies. Breadth First Search uses a FIFO queue and children nodes are added when they are expanded. Goal states are checked when nodes are generated. Uniform cost search uses the cost from the root to the current node as an evaluation function to determine which path should be taken and it takes the lowest cost path. Depth first search expands the deepest node of the frontier first using a LIFO queue. Iterative deepening search is a hybrid of BFS and DFS. Bidirectional search goes simultaneously from the initial state and the goal state to try and find a solution. Backtracking remembers a state and checks for solutions and goes back to that state to make another choice if there was no solution yielded.   \n\n## Module 3 Lecture Notes\n BFS is not complete, fails in infinite depth spaces, has time complexity of O(b^m) terrible if max depth (m) is larger than depth of least cost solution (d), space complexity is O(b*m), it isn't optimal. Iterative depth search is complete, time complexity is O(b^d), space complexity O(bd), and optimal if step cost is 1.  \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Reflex agents** - don't plan ahead. Make decisions only based on current percepts\n* **Solution** - a sequence of actions from the intitial state to goal\n* **Optimal solution** - a solution with the lowest path cost of all possible solutions\n* **Frontier** - all the nodes available for expanding\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - some nodes get ranked above others\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Informed search is able to discriminate between potential nodes that are expanded. It does this using a heuristic function (an estimate of what's best). One method is greedy best first search. It will always expand the node with the lowest heuristic cost. A* search is a best of both worlds approach whose heuristic is a combination of an estimate of the path to the goal state and the path cost so far added together. The estimate to the goal must not exceed the real cost - this is an admissible heuristic. A heuristic is consistent if for every node, when the path cost so far is increasing, the cost to go is decreasing. Pruning is a method that allows us to get rid of nodes that won't contain an optimal solution. There are several varieties of A*, including weighted A*, where we weight the heuristic value more heavily than the path cost. Beam search limits the size of the frontier to only hold the nodes with the best scores. Iterative deepening A* doesn't keep all visited states in memory. MA* and SMA* each of these will keep all prior nodes until memory is full and then start bumping a node out to make room for a new one.  \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Inadmissible (pessimistic) heuristics break optimality by trapping good plans on the frontier. Admissible (optimistic) heuristics slow down bad plans but never outweigh true costs. A problem with fewer restrictuions on the actions than the original is a relaxed problem. The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.  \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 In competitive environments, we use adversarial search. Adversarial search problems arise when two or more agents have conflicting goals. Pruning is the process of removing certain potential plays that we know won't lead to an optimal solution. We use a heurisitic evaluation function to determine who is winning based on a game state at any given time (remaining moves, highest score so far, etc.). For adversarial search, we have a set of the initial state, to-move player, actions available to them, result of the move (by applying the transition model), a check to see if we've reached the end of all plays or game over, and a utility function which defines the score of a player at state s. \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Minimax search divides a tree into tiers. Each tier is either the current player or their opponent. The current player is always trying to maximize their score while minimizing the score of the opponent. The algorithm consists of 3 functions, the minimax function which returns the move the player should make, a max function, which returns a utility move pair and calls the min value function in itself recursively to try and find the lowest value for it's opponent (the opponent's most optimal plays). Once it's value has been maximized and the other player's has been minimized, the result is returned to the function and the play can be executed. Alpha-beta pruning allows us to prune off branches of the minimax tree that would not lead to an optimal play for the current player. It does this by examining each tier of the minimax tree and, if a value is lower than the current max or higher than the current min, we know that player will never choose that outcome in an optimal world, so we can prune it. Even with alpha beta pruning and move ordering, minimax doesn't work for games like chess and Go because there are too many states. As such, we use either Type A or B strategy. These involve considering all possible moves to a certain depth and then using a heuristic to evaluate the utility of states at that depth. A explores wide but shallow. B ignores moves taht look bad and follows promising lines of play as far as it can. It explores a deep but narrow portion of the tree.  \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Evaluation functions allow us to treat nonterminal nodes as if they were terminal and assess the utility of the plays that led to that game state. This allows us to speed up computation vs. looking through every single game state to try and arrive at an optimal play. An evaluation function essentially lets us analyze the \"goodness\" of a board at any given point and decide if that is the most optimal position we could be in, given the limited depth we are looking into the tree (think domino game move limit). Quiescence is a state where there is no pending move that would wildly swing the evaluation function (a winning move pending). The horizon effect should also be minimized, where you can \"delay the inevitable\", but ultimately will be in a worse state than just letting the inevitable happen (a rook will get captured, but you can move it around a lot and lose the rook and 3 pawns). Forward pruning can be applied to limit the field of moves to only those moves that appear good. You may lose good moves in the pruning process, however.  \n\n## AIMA Chapter 5.5 Stochastic Games\n Stochastic games introduce an element of randomness to a game, such as throwing dice. Chance nodes help us to account for possible random outcomes in stochastic games. Eval functions for games of chance must include the probablity of certain outcomes occurring.  \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n We combine the results of a utility function and get the average of that with the probability that the outcome occurs to give us the expected utility. We want to utilize the principle of maximum expected utility to choose the action that maximizes expected utility. \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n There are several constraints on rational performance. Orderability means that things must be able to be ranked relative to each other. Transitivity means that if b is better than a and c is better than b, then an agent would prefer c to a. Monotonicity means that if it comes down to two equal outcomes, the agent should prefer the one with higher probability of occurring.  \n\n## AIMA Chapter 16.3 Utility Functions\n There are several problems that arise in statistical analysis of outcomes.  \n\n## Module 5 Lecture Notes\n All play is computed from Max's point of view. Even levels represent turns for max, odd represent turns for min. For alpha beta pruning, alpha is Max's current lower bound on Max's outcome (think at least) and beta is the current upper bound on min's outcome (think at most). Max will never allow a move that could lead to a worse score for max than alpha. And min will never allow a move that could lead to a better score for max than beta. In expectimax search, max nodes are treated as they are in minimax, but the min nodes are chance nodes where we calculate the expected utility (weighted average of children). Each line is a probability to the utility of reached the node. Simply multiply to get the expected utility. For example, if the utiliy of a node in the second ply is 12, but we have a 1/2 chance of getting there, then the expected utility is 6 for that branch.  \n\n## Module 5 Definitions\n* **Ply** - One level of the game. Each state will be in a play and have children nodes in the next ply\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Constraint satisfaction problems consist of a set of variables, a set of domains, one for each variable, and a set of constraints of allowable combinations of values. A legal assignment of a value to a variable is called consistent. A solution is a consistent, complete assignment. A precedence constraint controls when one thing must come before another. \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Constraint propagation allows us to use the constraints to restrict the number of possible values in the domain for each variable. Node consistency refres to when all the values in teh variable's domain satisfy the variable's unary constraints (constraints that apply only to it). Arc consistency refers to when every value in a variable's domain satisfires the variable's binary constraints (constraints between it and another node). Path consistency is when triples of variables have values that are consistent. K-consistency is the same for k nodes.  \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Backtracking allows us to check the possible values for each variable. If there is no solution when we assign one of them we prune that value and pick the next one. And so on until we end up with a value that works. Choosing the node with the fewest remaining legal values is called minimum-remaining-values (MRV) heuristic. Degree heuristic tries to reduce the branching factor by picking the variable that is involved in the largest number of constraints on other assigned variables. Least constraining value looks at the value that will heave the fewest impacts on its neighbors.  \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Min conflicts heuristic allows us to look at values that resutl in the minimum number of conflicts with other nodes. Constraint weighting concentrates teh search on the important constraints by assigning constraints a numeric weight. \n\n## AIMA Chapter 6.5 The Structure of Problems\n We want to reduce a CSP down to a tree, eventually. Identifying independent subproblems allows us to isolate variables that will never have an impact on each other. Tree decomposition involves taking a constraint graph and structuring it as a tree where each node has a set of variables \n\n## Module 6 Lecture Notes\n In sudoku, we can represent the puzzle as a CSP with each node being assigned a domain of possible values that could fill it. Once each node has only one associated value, the puzzle is solved. The benefits of CSP are that it is a clean specification of many problems and can be solved with a generic group of functions, CSP knows which variables violate constraints and can focus search accordingly, and CSP automatically prunes off branches that violate constraints, so no time wasted examining them. Types of constraints oinclude unary (involving a single variable, spot A can't be green), binary (involving 2 variables, A and B can't be same color), higher-order constraints (3 or more variables), preference (red is better than green, but is not required to be red). AC-3 has a Worst case complexity is O(n^2*d^3). Whenever we remove a value from a node x, all of the values on all of x's neighbors must be re-examined because removing a value from a node may result in one of the neighbors becoming arc inconsistent.  \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 Entailment is the idea that a sentence follows logically from another sentence. Soundness is necessary for an inference algorithm, otherwise it would just make stuff up as it goes along and makes incorrect decisions. Grounding is the connection between logical reasoning processes and the real environment in which the agent exists. \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 Knowlege-based agents use a process of reasoning over an internal representation of knowledge to decide what action to take. A knowledge base contains a set of sentences that are written in a knowledge representation language to make an assertion about the world (grass is green).There are two kinds of sesntences, axioms (given), and derived (arrived at through inference based on old sentences). Remember Wampa world. R2's sensors include stench, gasp, breeze, scream, and bump. Given its inputs, R2 can navigate the world and make assumptions about which squares are safe to move to. Logical inference allows us to add to the knowledge base through derived sentences (a is derived from KB by i). Remember truth tables (confusing one is if then, outcomes are true, false, true true, think of as promise). Biconditional (iff) (true, false, false, true). An inference algorithm is sound if it only derives entailed sentences, it is complete if it can derive all sentences that are entailed. \n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}