{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "brNDGX-kvzds"
      },
      "source": [
        "# Template for Notes for CIS 521 Midterm 1\n",
        "\n",
        "The midterm exam for CIS 521 will be **open notes**. No other matierals are allowed for the exam - you may not use the textbook, the internet, a Python envionement, or communicate with anyone during the exam. \n",
        "\n",
        "This python notebook is where you should save all of your notes.  It provides a structured template that allows you to add summaries for each of the textbook sections that are part of the required reading, plus room for lecture notes and definitions.\n",
        "\n",
        "Your summaries must be written in your own words.  Do not copy and paste from the textbook.  Do not share your notes with classmates, or copy any of your classmates' notes.  "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aPtM8g7R0Pds"
      },
      "source": [
        "# Instructions\n",
        "\n",
        "1. Make a copy of this Google Colab file. From the colab menu, pick **File > Save a copy in Drive**.  That will save a copy of this notebook in your Google drive.\n",
        "2. Go through each section of the notebook, and fill in all the summaries for each chapter and its corresponding sections.  Be sure to save your work frequently!\n",
        "3. Read the notes below about how you can format your summaries.\n",
        "4. In addition to these notes, you are allowed 1 page (both sides) for figures or handwritten notes.\n",
        "5. Submit your version of this notebook to Gradescope before you start the exam.\n",
        "6. If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print: \n",
        "* Run the last cell of this notebook\n",
        "* Click the \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n",
        "\n",
        "## Formatting Notes\n",
        "\n",
        "1. The max length for each section's summary is 500 words / 3000 characters.\n",
        "2. You can also write a 2000 word summary of the lectures for each module.\n",
        "3. You may also write definitions of concepts for each module.  The definitions should be written in your own words (not copy and pasted), and they should be no more than 20 words long for each concept. \n",
        "2. You can use Markdown formatting for your summaries. \n",
        "3. You can use Latex formatting for equations. Put two dollar signs before and after your equation like this: \n",
        "$$ \\epsilon = \\frac{1}{mc^2} $$\n",
        "4. When you write python code or psuedocode algorithms, you should surround it with triple backticks like this:\n",
        "```\n",
        "def function():\n",
        "      print('hello world')\n",
        "```\n",
        "5. Write \\ whenever you want to keep writing on the next line without a newline being inserted."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cw5IpDLCZa4W"
      },
      "source": [
        "## Example summary\n",
        "\n",
        "This is a sample summary of [Section 2.1.1](https://web.stanford.edu/~jurafsky/slp3/2.pdf ) of Jurfasky and Martin's Speech and Language Processing's book\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lzaavW96tcxM",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "005c16c3-622a-4176-b71d-6a0873051039"
      },
      "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": 19,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 116 words long, so you could write an additional 384 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "s3Uk9gQTevcj"
      },
      "source": [
        "## Example summary length\n",
        "\n",
        "The maximum summary length for each section is 500 words / 3000 characters.  Hopefully you'll find that to be quite generous. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8DvZ57A-djo1",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5ff37a69-f136-489c-ae50-8925dc4283c9"
      },
      "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": 20,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = True"
      ],
      "execution_count": 21,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y2NfE1CKxzS-"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
        "\n",
        "chapter1_1 = \"\"\" \n",
        "Different definition:\\n\n",
        "  two dimensions: human vs rational, and thought vs behavior\\n\n",
        "1.1.1 Acting humanly: turing test approach\\n\n",
        "    Capabilities required to pass Turing test:\\n\n",
        "    1. NLP 2. knowledge representation (storage)\\n\n",
        "    3. automated reasoning 4. machine learning (adapt)\\n\n",
        "    Capacities required to pass Total Turing test:\\n\n",
        "    All above plus 5. computer vision 6. robotics\\n\n",
        "1.1.2 Thinking humanly: cognitivve modeling approach\\n\n",
        "    Ways to learn how human think:\\n\n",
        "    1. introspection: catch our thoughts as they go by\\n\n",
        "    2. psychological experienments: observe people in action\\n\n",
        "    3. brain imaging: observe brains in action\\n\n",
        "1.1.3 Thinking rationally: \"law of thought\" approach\\n\n",
        "1.1.4 Acting rationally: rational agent approach\\n\n",
        "\"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\" \n",
        "1. Argument from informality - \n",
        "human behavior involves informal guidelines on top of formal set of rules\\\n",
        "intuitions cannot be codified into a program (quantification problem)\\n\n",
        "2. Argument from disability - machine can't do bla - proved wrong for some bla\\n\n",
        "3. Mathematical objection - Goedel's incompleteness theorem\\n\n",
        "4. Measuring AI - Turing test \"\"\"\n",
        "chapter27_2 = \"\"\" Dijkstra: can machines \"think\" is irrelevant\\n\n",
        "consciousness: aware of the environment, the self and have living experience \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" \n",
        "Agents and Environments\\n\n",
        "\n",
        " \"\"\"\n",
        "chapter2_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" \n",
        "*Rational Behaviors*\\n\n",
        "Rule of thumb for performance measures:\\n\n",
        "  Do: waht you want to be achieved\\n\n",
        "  Dont: how you think the agent should behave.\\n\n",
        "Rationality of agent does not guarantee success.\\n\n",
        "Computational limitations make complete rationality impossible.\\n\n",
        "\\n\n",
        "*Task Environment*\\n\n",
        "PEAS:\\n\n",
        "P: performance measure. -  \n",
        "  e.g. max profit, min time\\n\n",
        "E: environment\\n\n",
        "  dimensions:\\n\n",
        "    observable: fully/partial\\n\n",
        "    single/multi agents\\n\n",
        "    deterministic/stochastic/nondeterministic\\n\n",
        "    episodic/sequential\\n\n",
        "    static/semi/dynamic\\n\n",
        "    discrete/continuous\\n\n",
        "    hardest = continuous+partially observable+stochastic+multiagent\\n\n",
        "A: actuators\\n\n",
        "S: sensors\\n\n",
        "Goal of AI:\\n\n",
        "1. Construct agent function that max performance measure\\n\n",
        "2. Design agent program and implement 1 on an architecture\\n\n",
        "\\n\n",
        "*Problem solving agents & prob formulation:\\n\n",
        "1. formulate goal\\n\n",
        "2. formulate search problem:\\n\n",
        "  states, actions (successors), performance measure\\n\n",
        "3. find solution\n",
        " \"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 1.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module1_definitions = {\n",
        "\"agent\" : \"anything that can perceive (thru sensors)\\\n",
        "            and act (thru actuators) in an environment\",\n",
        "\"percept\" : \"the agent's perceptual inputs\",\n",
        "\"agent function\": \"f: percept -> action\",\n",
        "\"agent program\": \"the agent function produces f\\\n",
        "                    agent = architecture + program\",\n",
        "\"rational behavior\" : \"doing the right thing\",\n",
        "\"rationality\": \"do the right thing\\\n",
        "                  max utilization, not omniscient\\\n",
        "                  (notexpected to know the future)\",\n",
        "\"rational agent\": \"agent that perceives and acts rationally\",\n",
        "\"limited rationality\":\"do the right thing given limited computational resource\",\n",
        "\"performance measure\": \"objective criterion for success of agent's behavior\\\n",
        "                         given evidence provided by percept sequence\",\n",
        "\"task environment\": \"program specification for agent(s)\",\n",
        "\"reflex agent\": \"performs action on current percept, ignores percept history\",\n",
        "\"problem solving agent\": \"does serch and plans ahead;\\\n",
        "                          considers path to goal state\",\n",
        "\"Turing test\": \"whether human can tell response to written questions\\\n",
        "                 came from a person or a computer\",\n",
        "\"Total Turing test\": \"Turing test + \\\n",
        "                      interaction with objects and people in reality\",\n",
        "\"weak AI\": \"machines can act as if they were intelligent\",\n",
        "\"strong AI\": \"machines ARE actually thinking - general AI or human-level AI\",\n",
        "\"consciousness\": \"aware of the environment, the self and have living experience\",\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 22,
      "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": "markdown",
      "metadata": {
        "id": "GZZXyrV-xuAp"
      },
      "source": [
        "# Module 1 - Intro to AI"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gYYeNcdM_maE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "cellView": "form",
        "outputId": "5f2d7643-9f44-4c64-f73d-52550e1b0244"
      },
      "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": 23,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'agent' is too long!\nWARNING: Your definition of 'agent program' is too long!\nWARNING: Your definition of 'rationality' is too long!\nWARNING: Your definition of 'performance measure' is too long!\nWARNING: Your definition of 'problem solving agent' is too long!\nWARNING: Your definition of 'Turing test' is too long!\nWARNING: Your definition of 'Total Turing test' is too long!\n# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nDifferent definition:\n\n  two dimensions: human vs rational, and thought vs behavior\n\n1.1.1 Acting humanly: turing test approach\n\n    Capabilities required to pass Turing test:\n\n    1. NLP 2. knowledge representation (storage)\n\n    3. automated reasoning 4. machine learning (adapt)\n\n    Capacities required to pass Total Turing test:\n\n    All above plus 5. computer vision 6. robotics\n\n1.1.2 Thinking humanly: cognitivve modeling approach\n\n    Ways to learn how human think:\n\n    1. introspection: catch our thoughts as they go by\n\n    2. psychological experienments: observe people in action\n\n    3. brain imaging: observe brains in action\n\n1.1.3 Thinking rationally: \"law of thought\" approach\n\n1.1.4 Acting rationally: rational agent approach\n\n\n\n## AIMA Chapter 27.1 The Limits of AI\n \n1. Argument from informality - \nhuman behavior involves informal guidelines on top of formal set of rulesintuitions cannot be codified into a program (quantification problem)\n\n2. Argument from disability - machine can't do bla - proved wrong for some bla\n\n3. Mathematical objection - Goedel's incompleteness theorem\n\n4. Measuring AI - Turing test \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Dijkstra: can machines \"think\" is irrelevant\n\nconsciousness: aware of the environment, the self and have living experience \n\n## AIMA 2.1 Agents and Environments\n \nAgents and Environments\n\n\n \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n \n*Rational Behaviors*\n\nRule of thumb for performance measures:\n\n  Do: waht you want to be achieved\n\n  Dont: how you think the agent should behave.\n\nRationality of agent does not guarantee success.\n\nComputational limitations make complete rationality impossible.\n\n\n\n*Task Environment*\n\nPEAS:\n\nP: performance measure. -  \n  e.g. max profit, min time\n\nE: environment\n\n  dimensions:\n\n    observable: fully/partial\n\n    single/multi agents\n\n    deterministic/stochastic/nondeterministic\n\n    episodic/sequential\n\n    static/semi/dynamic\n\n    discrete/continuous\n\n    hardest = continuous+partially observable+stochastic+multiagent\n\nA: actuators\n\nS: sensors\n\nGoal of AI:\n\n1. Construct agent function that max performance measure\n\n2. Design agent program and implement 1 on an architecture\n\n\n\n*Problem solving agents & prob formulation:\n\n1. formulate goal\n\n2. formulate search problem:\n\n  states, actions (successors), performance measure\n\n3. find solution\n \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (thru sensors)            and act (thru actuators) in an environment\n* **Percept** - the agent's perceptual inputs\n* **Agent function** - f: percept -> action\n* **Agent program** - the agent function produces f                    agent = architecture + program\n* **Rational behavior** - doing the right thing\n* **Rationality** - do the right thing                  max utilization, not omniscient                  (notexpected to know the future)\n* **Rational agent** - agent that perceives and acts rationally\n* **Limited rationality** - do the right thing given limited computational resource\n* **Performance measure** - objective criterion for success of agent's behavior                         given evidence provided by percept sequence\n* **Task environment** - program specification for agent(s)\n* **Reflex agent** - performs action on current percept, ignores percept history\n* **Problem solving agent** - does serch and plans ahead;                          considers path to goal state\n* **Turing test** - whether human can tell response to written questions                 came from a person or a computer\n* **Total turing test** - Turing test +                       interaction with objects and people in reality\n* **Weak ai** - machines can act as if they were intelligent\n* **Strong ai** - machines ARE actually thinking - general AI or human-level AI\n* **Consciousness** - aware of the environment, the self and have living experience\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 = \"\"\" \n",
        "Positive features of Python:\\n\n",
        "Fast development; portable; various built-in types; libraries\\n\n",
        "Strong typing: \"foo\" + 2 is not allowed\\n\n",
        "Dynamic typing: variables can be reassigned type\\n\n",
        "string formatting using % (%s, %d)\\n\n",
        "strings are immutable\n",
        "list comprehension: [expression for element in list if filter]\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"ability to change a component\",\n",
        "\"dynamic scoping\": \"functions sees the most current value of variables\",\n",
        "\"duck typing\": \"establishes suitability of an object by determining presence\\\n",
        "                of methods\",\n",
        "\n",
        "}"
      ],
      "execution_count": 24,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 401
        },
        "outputId": "09ea944a-a82f-4f4d-f0c8-dbe567bd7091"
      },
      "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": 25,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'duck typing' is too long!\n# Module 2: Python\n## Module 2 Lecture Notes\n \nPositive features of Python:\n\nFast development; portable; various built-in types; libraries\n\nStrong typing: \"foo\" + 2 is not allowed\n\nDynamic typing: variables can be reassigned type\n\nstring formatting using % (%s, %d)\n\nstrings are immutable\nlist comprehension: [expression for element in list if filter]\n\n## Module 2 Definitions\n* **Mutability** - ability to change a component\n* **Dynamic scoping** - functions sees the most current value of variables\n* **Duck typing** - establishes suitability of an object by determining presence                of methods\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 agent follows four-phase process if environment\\\n",
        "is known: goal formulation, problem forumlation, search, execution.\\n\n",
        " \"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_4 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" \n",
        "If an environment is fully obervable + deterministic + known environment:\\n\n",
        "solution to any problem is a fixed sequence of actions.\\n\n",
        "If an environment is partially obervable OR nondeterministic:\\n\n",
        "solution must recommend different future actions depending on percepts sequence.\\n\n",
        "this could be in the form of a branching strategy\\n\n",
        "\\n\n",
        "*Tree Search*\\n\n",
        "Enumerate in some order all possible paths from the initial state.\\n\n",
        "Tree search treates different paths to the same node as distinct.\\n\n",
        "Failure to detect repeated states can get stuck in loop.\\n\n",
        "*Graph Search*\\n\n",
        "Tree saerch + checking nodes' visited status BEFORE adding to frontier\\n\n",
        "BFS is FIFO; complete + O(b^d) exponential  time and space complexity \\n\n",
        "+ optimal if cost =1 per step otherwise not optimal\\n\n",
        "DFS is LIFO; not complete + linear space complexity, not optimal,\\n\n",
        "and time complexity O(b^m): terrible if m >>d, but much faster than BFS sometimes\\n\n",
        "Use DFS is space is restricted; use BFS if possible infinite paths\\n\n",
        "Depth-limited search: NOT complete, O(b^l) time, linear space, not optimal\\n\n",
        "Iterative deepening search: same as BFS except linear space!\n",
        " \"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",\n",
        "\"solution\": \"a sequence of actions from the initial state to a goal state\",\n",
        "\"search\": \"computational process to find solution\",\n",
        "\"optimal solution\": \"minimum path cost solution\",\n",
        "\"state space\": \"set of all states reachable from initial state\\\n",
        "                 by any sequence of legal actions\",\n",
        "\"path\": \"a sequnce of actions leading from one state to another\",\n",
        "\"frontier\": \" states available for expanding (by applying legal actions to)\",\n",
        "\"uninformed search\": \"all non-goal nodes in frontier look equally good\",\n",
        "\"informed search\": \"some non-goal nodes look better than the others in frontier\",\n",
        "\"search strategy\": \"order of tree expansion\",\n",
        "\"completeness\":\"always find a solution\",\n",
        "\"optimality\": \"finds optimal solution first\",\n",
        "\"time complexity\": \"number of nodes generated in worst case\",\n",
        "\"space complexity\":\"number of nodes in memory at any given time\",\n",
        "\"open-loop system\": \"ignore percepts while executing fixed sequence solution\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 26,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "1aebb3af-f370-4c9e-eccb-ab64bc75db3e"
      },
      "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": 27,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'state space' is too long!\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Problem solving agent follows four-phase process if environmentis known: goal formulation, problem forumlation, search, execution.\n\n \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Your summary here \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n \nIf an environment is fully obervable + deterministic + known environment:\n\nsolution to any problem is a fixed sequence of actions.\n\nIf an environment is partially obervable OR nondeterministic:\n\nsolution must recommend different future actions depending on percepts sequence.\n\nthis could be in the form of a branching strategy\n\n\n\n*Tree Search*\n\nEnumerate in some order all possible paths from the initial state.\n\nTree search treates different paths to the same node as distinct.\n\nFailure to detect repeated states can get stuck in loop.\n\n*Graph Search*\n\nTree saerch + checking nodes' visited status BEFORE adding to frontier\n\nBFS is FIFO; complete + O(b^d) exponential  time and space complexity \n\n+ optimal if cost =1 per step otherwise not optimal\n\nDFS is LIFO; not complete + linear space complexity, not optimal,\n\nand time complexity O(b^m): terrible if m >>d, but much faster than BFS sometimes\n\nUse DFS is space is restricted; use BFS if possible infinite paths\n\nDepth-limited search: NOT complete, O(b^l) time, linear space, not optimal\n\nIterative deepening search: same as BFS except linear space!\n \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Solution** - a sequence of actions from the initial state to a goal state\n* **Search** - computational process to find solution\n* **Optimal solution** - minimum path cost solution\n* **State space** - set of all states reachable from initial state                 by any sequence of legal actions\n* **Path** - a sequnce of actions leading from one state to another\n* **Frontier** -  states available for expanding (by applying legal actions to)\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - some non-goal nodes look better than the others in frontier\n* **Search strategy** - order of tree expansion\n* **Completeness** - always find a solution\n* **Optimality** - finds optimal solution first\n* **Time complexity** - number of nodes generated in worst case\n* **Space complexity** - number of nodes in memory at any given time\n* **Open-loop system** - ignore percepts while executing fixed sequence solution\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WHREsHSSyA-h"
      },
      "source": [
        "#Module 4 - Informed Search"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tuFC8w7CyCns"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
        "chapter3_5 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" \n",
        "Greedy best-first search: not optimal, not complete\\n\n",
        "Heuristic is admissible if it never overestimates the cost to reach goal.\\n\n",
        "If heuristic is admissible then A* using tree search(!) is optimal.\\n\n",
        "If heuristic is consistent (stronger) then A* using graph search is optimal.\\n\n",
        "Heuristic is better if it's more accurate (optimistic but closer to actual).\\n\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"uniform-cost search\" : \"NOT all step cost=1, expand node with lowest path cost\",\n",
        "\"heuristic\": \"educated guess\",\n",
        "\"greedy best-first search\": \"f(n) = h(n)\",\n",
        "\"A* search\": \" f(n) = g(n)actual cost to curr state + h(n) estimated to goal\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 28,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 484
        },
        "cellView": "form",
        "outputId": "e32e350a-e47b-4722-8ab7-69fdb5f589b9"
      },
      "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": 29,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n \nGreedy best-first search: not optimal, not complete\n\nHeuristic is admissible if it never overestimates the cost to reach goal.\n\nIf heuristic is admissible then A* using tree search(!) is optimal.\n\nIf heuristic is consistent (stronger) then A* using graph search is optimal.\n\nHeuristic is better if it's more accurate (optimistic but closer to actual).\n\n\n\n\n## Module 4 Definitions\n* **Uniform-cost search** - NOT all step cost=1, expand node with lowest path cost\n* **Heuristic** - educated guess\n* **Greedy best-first search** - f(n) = h(n)\n* **A* search** -  f(n) = g(n)actual cost to curr state + h(n) estimated to goal\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\"\n",
        "Simplest game environment:\\n\n",
        "Multi-agent, static, discrete, fully observable, strategic\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"strategic\" : \"next state is determined by curr state, action by agent,\\\n",
        "                and action by opponent\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 30,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 740
        },
        "outputId": "d02a9d1d-5e28-47c9-b8d1-7a0b1d9b9aaf"
      },
      "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": 31,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'strategic' is too long!\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n\nSimplest game environment:\n\nMulti-agent, static, discrete, fully observable, strategic\n\n## Module 5 Definitions\n* **Strategic** - next state is determined by curr state, action by agent,                and action by opponent\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qVSQhTVSyYYO"
      },
      "source": [
        "#Module 6 - \"Constraint Satisfaction Problems\""
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wm4mfW82yaRH"
      },
      "source": [
        "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
        "chapter6_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\"\n",
        "CSP: for single agent, deterministic, fully observable and discrete environment\\n\n",
        "Represnet the constraints that solutions must satisfy\\\n",
        " in a uniform declarative language\\n\n",
        "General purpose search algorithm for all such problems\\\n",
        " (no diff heuristics or moves)\\n\n",
        "Finite set of variables and constraints; non-empty domain of possible vals\\n\n",
        "Solution to CSP is a complete, consistente assignment.\\n\n",
        "Benefits of CSP:\\n\n",
        "- Clean specification: generic goal, successor function & heuristics\\n\n",
        "- CSP knows which variables violate a constraint and where to focus the search\\n\n",
        "- CSP automatically prune off branches with violations\\n\n",
        "Types of constraints:\\n\n",
        "Unary (involving itself), Binary (itself and another var), higher-order(3+ vars)\\n\n",
        "CSP Heuristics:\\n\n",
        "- Most constrained variable (fewest legal values)\\n\n",
        "- Most constraining variable\\n\n",
        "- Least constraining value\\n\n",
        "- Forward checking\\n\n",
        "CSP process: search + infer\\n\n",
        "If a value is removed from a node, then all of this node's neighbors need to be\\\n",
        " re-examnined for arc consistency\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"complete assignment\" : \"every variable is assigned a value\",\n",
        "\"arc consistent\": \"iff for every value in X there is some allowed in Y (binary)\",\n",
        "}\n"
      ],
      "execution_count": 32,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 949
        },
        "outputId": "a8de61c6-fd7f-41fa-d744-d0b98019ff48"
      },
      "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": 33,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n\nCSP: for single agent, deterministic, fully observable and discrete environment\n\nRepresnet the constraints that solutions must satisfy in a uniform declarative language\n\nGeneral purpose search algorithm for all such problems (no diff heuristics or moves)\n\nFinite set of variables and constraints; non-empty domain of possible vals\n\nSolution to CSP is a complete, consistente assignment.\n\nBenefits of CSP:\n\n- Clean specification: generic goal, successor function & heuristics\n\n- CSP knows which variables violate a constraint and where to focus the search\n\n- CSP automatically prune off branches with violations\n\nTypes of constraints:\n\nUnary (involving itself), Binary (itself and another var), higher-order(3+ vars)\n\nCSP Heuristics:\n\n- Most constrained variable (fewest legal values)\n\n- Most constraining variable\n\n- Least constraining value\n\n- Forward checking\n\nCSP process: search + infer\n\nIf a value is removed from a node, then all of this node's neighbors need to be re-examnined for arc consistency\n\n\n## Module 6 Definitions\n* **Complete assignment** - every variable is assigned a value\n* **Arc consistent** - iff for every value in X there is some allowed in Y (binary)\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" \n",
        "Knowledge-based agent use reasoning over internal representation of knowledge\\\n",
        "to decide what actions to take.\\n\n",
        "A KB initially contain some axioms and agent adds derived knowledge to it.\n",
        "Wampa World is deterministic, discrete, static, single agent, sequential\\\n",
        "and partially observable.\\n\n",
        "CNF:\\n\n",
        "1. Eliminate IFF into A then B AND B then A\\n\n",
        "2. Eliminate then into not A or B\\n\n",
        "3. Move not inwards\\n\n",
        "4. Apply distributivity law to nested AND OR\\n\n",
        "De Morgan's law: not (A AND B) == not A OR not B\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"Knowledge Base\" : \"KB is a set of sentences written in knowledge representation\\\n",
        "                    language that contains assertion about the world\",\n",
        "\"Axioms\":\"given sentence\",\n",
        "\"derived sentences\":\"inferred sentences from axioms\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 34,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 812
        },
        "outputId": "e25f9b59-f030-4e14-d742-5e199a1d4064"
      },
      "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": 35,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'Knowledge Base' is too long!\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n \nKnowledge-based agent use reasoning over internal representation of knowledgeto decide what actions to take.\n\nA KB initially contain some axioms and agent adds derived knowledge to it.\nWampa World is deterministic, discrete, static, single agent, sequentialand partially observable.\n\nCNF:\n\n1. Eliminate IFF into A then B AND B then A\n\n2. Eliminate then into not A or B\n\n3. Move not inwards\n\n4. Apply distributivity law to nested AND OR\n\nDe Morgan's law: not (A AND B) == not A OR not B\n\n## Module 7 Definitions\n* **Knowledge base** - KB is a set of sentences written in knowledge representation                    language that contains assertion about the world\n* **Axioms** - given sentence\n* **Derived sentences** - inferred sentences from axioms\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vX7lbnJd4sT5"
      },
      "source": [
        "# Your Exam Notes\n",
        "\n",
        "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
        "\n",
        "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
        "* Run the cell below. \n",
        "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "80728623-7552-4f20-c972-6adca5c2970f"
      },
      "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": 36,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "## WARNING: Your definition of 'agent' is too long!\nWARNING: Your definition of 'agent program' is too long!\nWARNING: Your definition of 'rationality' is too long!\nWARNING: Your definition of 'performance measure' is too long!\nWARNING: Your definition of 'problem solving agent' is too long!\nWARNING: Your definition of 'Turing test' is too long!\nWARNING: Your definition of 'Total Turing test' is too long!\n# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n \nDifferent definition:\n\n  two dimensions: human vs rational, and thought vs behavior\n\n1.1.1 Acting humanly: turing test approach\n\n    Capabilities required to pass Turing test:\n\n    1. NLP 2. knowledge representation (storage)\n\n    3. automated reasoning 4. machine learning (adapt)\n\n    Capacities required to pass Total Turing test:\n\n    All above plus 5. computer vision 6. robotics\n\n1.1.2 Thinking humanly: cognitivve modeling approach\n\n    Ways to learn how human think:\n\n    1. introspection: catch our thoughts as they go by\n\n    2. psychological experienments: observe people in action\n\n    3. brain imaging: observe brains in action\n\n1.1.3 Thinking rationally: \"law of thought\" approach\n\n1.1.4 Acting rationally: rational agent approach\n\n\n\n## AIMA Chapter 27.1 The Limits of AI\n \n1. Argument from informality - \nhuman behavior involves informal guidelines on top of formal set of rulesintuitions cannot be codified into a program (quantification problem)\n\n2. Argument from disability - machine can't do bla - proved wrong for some bla\n\n3. Mathematical objection - Goedel's incompleteness theorem\n\n4. Measuring AI - Turing test \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Dijkstra: can machines \"think\" is irrelevant\n\nconsciousness: aware of the environment, the self and have living experience \n\n## AIMA 2.1 Agents and Environments\n \nAgents and Environments\n\n\n \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n Your summary here \n\n## AIMA 2.4 The Structure of Agents\n Your summary here \n\n## Module 1 Lecture Notes\n \n*Rational Behaviors*\n\nRule of thumb for performance measures:\n\n  Do: waht you want to be achieved\n\n  Dont: how you think the agent should behave.\n\nRationality of agent does not guarantee success.\n\nComputational limitations make complete rationality impossible.\n\n\n\n*Task Environment*\n\nPEAS:\n\nP: performance measure. -  \n  e.g. max profit, min time\n\nE: environment\n\n  dimensions:\n\n    observable: fully/partial\n\n    single/multi agents\n\n    deterministic/stochastic/nondeterministic\n\n    episodic/sequential\n\n    static/semi/dynamic\n\n    discrete/continuous\n\n    hardest = continuous+partially observable+stochastic+multiagent\n\nA: actuators\n\nS: sensors\n\nGoal of AI:\n\n1. Construct agent function that max performance measure\n\n2. Design agent program and implement 1 on an architecture\n\n\n\n*Problem solving agents & prob formulation:\n\n1. formulate goal\n\n2. formulate search problem:\n\n  states, actions (successors), performance measure\n\n3. find solution\n \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (thru sensors)            and act (thru actuators) in an environment\n* **Percept** - the agent's perceptual inputs\n* **Agent function** - f: percept -> action\n* **Agent program** - the agent function produces f                    agent = architecture + program\n* **Rational behavior** - doing the right thing\n* **Rationality** - do the right thing                  max utilization, not omniscient                  (notexpected to know the future)\n* **Rational agent** - agent that perceives and acts rationally\n* **Limited rationality** - do the right thing given limited computational resource\n* **Performance measure** - objective criterion for success of agent's behavior                         given evidence provided by percept sequence\n* **Task environment** - program specification for agent(s)\n* **Reflex agent** - performs action on current percept, ignores percept history\n* **Problem solving agent** - does serch and plans ahead;                          considers path to goal state\n* **Turing test** - whether human can tell response to written questions                 came from a person or a computer\n* **Total turing test** - Turing test +                       interaction with objects and people in reality\n* **Weak ai** - machines can act as if they were intelligent\n* **Strong ai** - machines ARE actually thinking - general AI or human-level AI\n* **Consciousness** - aware of the environment, the self and have living experience\n\n\n## WARNING: Your definition of 'duck typing' is too long!\n# Module 2: Python\n## Module 2 Lecture Notes\n \nPositive features of Python:\n\nFast development; portable; various built-in types; libraries\n\nStrong typing: \"foo\" + 2 is not allowed\n\nDynamic typing: variables can be reassigned type\n\nstring formatting using % (%s, %d)\n\nstrings are immutable\nlist comprehension: [expression for element in list if filter]\n\n## Module 2 Definitions\n* **Mutability** - ability to change a component\n* **Dynamic scoping** - functions sees the most current value of variables\n* **Duck typing** - establishes suitability of an object by determining presence                of methods\n\n\n## WARNING: Your definition of 'state space' is too long!\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Problem solving agent follows four-phase process if environmentis known: goal formulation, problem forumlation, search, execution.\n\n \n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Your summary here \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n Your summary here \n\n## Module 3 Lecture Notes\n \nIf an environment is fully obervable + deterministic + known environment:\n\nsolution to any problem is a fixed sequence of actions.\n\nIf an environment is partially obervable OR nondeterministic:\n\nsolution must recommend different future actions depending on percepts sequence.\n\nthis could be in the form of a branching strategy\n\n\n\n*Tree Search*\n\nEnumerate in some order all possible paths from the initial state.\n\nTree search treates different paths to the same node as distinct.\n\nFailure to detect repeated states can get stuck in loop.\n\n*Graph Search*\n\nTree saerch + checking nodes' visited status BEFORE adding to frontier\n\nBFS is FIFO; complete + O(b^d) exponential  time and space complexity \n\n+ optimal if cost =1 per step otherwise not optimal\n\nDFS is LIFO; not complete + linear space complexity, not optimal,\n\nand time complexity O(b^m): terrible if m >>d, but much faster than BFS sometimes\n\nUse DFS is space is restricted; use BFS if possible infinite paths\n\nDepth-limited search: NOT complete, O(b^l) time, linear space, not optimal\n\nIterative deepening search: same as BFS except linear space!\n \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Solution** - a sequence of actions from the initial state to a goal state\n* **Search** - computational process to find solution\n* **Optimal solution** - minimum path cost solution\n* **State space** - set of all states reachable from initial state                 by any sequence of legal actions\n* **Path** - a sequnce of actions leading from one state to another\n* **Frontier** -  states available for expanding (by applying legal actions to)\n* **Uninformed search** - all non-goal nodes in frontier look equally good\n* **Informed search** - some non-goal nodes look better than the others in frontier\n* **Search strategy** - order of tree expansion\n* **Completeness** - always find a solution\n* **Optimality** - finds optimal solution first\n* **Time complexity** - number of nodes generated in worst case\n* **Space complexity** - number of nodes in memory at any given time\n* **Open-loop system** - ignore percepts while executing fixed sequence solution\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n Your summary here \n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n \nGreedy best-first search: not optimal, not complete\n\nHeuristic is admissible if it never overestimates the cost to reach goal.\n\nIf heuristic is admissible then A* using tree search(!) is optimal.\n\nIf heuristic is consistent (stronger) then A* using graph search is optimal.\n\nHeuristic is better if it's more accurate (optimistic but closer to actual).\n\n\n\n\n## Module 4 Definitions\n* **Uniform-cost search** - NOT all step cost=1, expand node with lowest path cost\n* **Heuristic** - educated guess\n* **Greedy best-first search** - f(n) = h(n)\n* **A* search** -  f(n) = g(n)actual cost to curr state + h(n) estimated to goal\n\n\n## WARNING: Your definition of 'strategic' is too long!\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n\nSimplest game environment:\n\nMulti-agent, static, discrete, fully observable, strategic\n\n## Module 5 Definitions\n* **Strategic** - next state is determined by curr state, action by agent,                and action by opponent\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n\nCSP: for single agent, deterministic, fully observable and discrete environment\n\nRepresnet the constraints that solutions must satisfy in a uniform declarative language\n\nGeneral purpose search algorithm for all such problems (no diff heuristics or moves)\n\nFinite set of variables and constraints; non-empty domain of possible vals\n\nSolution to CSP is a complete, consistente assignment.\n\nBenefits of CSP:\n\n- Clean specification: generic goal, successor function & heuristics\n\n- CSP knows which variables violate a constraint and where to focus the search\n\n- CSP automatically prune off branches with violations\n\nTypes of constraints:\n\nUnary (involving itself), Binary (itself and another var), higher-order(3+ vars)\n\nCSP Heuristics:\n\n- Most constrained variable (fewest legal values)\n\n- Most constraining variable\n\n- Least constraining value\n\n- Forward checking\n\nCSP process: search + infer\n\nIf a value is removed from a node, then all of this node's neighbors need to be re-examnined for arc consistency\n\n\n## Module 6 Definitions\n* **Complete assignment** - every variable is assigned a value\n* **Arc consistent** - iff for every value in X there is some allowed in Y (binary)\n\n\n## WARNING: Your definition of 'Knowledge Base' is too long!\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n \nKnowledge-based agent use reasoning over internal representation of knowledgeto decide what actions to take.\n\nA KB initially contain some axioms and agent adds derived knowledge to it.\nWampa World is deterministic, discrete, static, single agent, sequentialand partially observable.\n\nCNF:\n\n1. Eliminate IFF into A then B AND B then A\n\n2. Eliminate then into not A or B\n\n3. Move not inwards\n\n4. Apply distributivity law to nested AND OR\n\nDe Morgan's law: not (A AND B) == not A OR not B\n\n## Module 7 Definitions\n* **Knowledge base** - KB is a set of sentences written in knowledge representation                    language that contains assertion about the world\n* **Axioms** - given sentence\n* **Derived sentences** - inferred sentences from axioms\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}