{
  "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": "456f3804-b2f7-4d8a-c207-ac106dce0126"
      },
      "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": null,
      "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": "7a042941-b6a9-41c7-dd0b-b3ab16f1302e"
      },
      "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": null,
      "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": null,
      "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 = \"\"\" 1.formal definition of intelligence called rationality (human vs rational, thought vs behavior).\\n\n",
        "2.Turing test: acting humanly, capabilities: (natural language processing, knowledge representation,automated reasoning,machine learning )\n",
        "total turing test: + (computer vision, robotics) . \\n 3. thinking humanly, three ways to learn about human thought: (introspection, psychological experiments, brain imaging)\\n\n",
        "4. thinking rationally. 5. 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 = \"\"\"1. weak AI VS strong AI (human-level AI).\\n 2. possible objections to AI: The argument from informality, the argument from disability, the mathematical objection \"\"\"\n",
        "chapter27_2 = \"\"\" 1. chinese room problem: computer can generate symbol, but no understanding \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" 1. agent, sensors, actuators-->environment.\\n 2. an agent’s choice of action at any given instant can depend on its built-in knowledge and\\\n",
        "on the entire percept sequence observed to date, but not on anything it hasn’t perceived. \\n 3. The agent function is an abstract mathematical description; the agent program is a concrete\\\n",
        "implementation, running within some physical system.\"\"\"\n",
        "chapter2_2 = \"\"\"1. rationality: consequentialism (结果主义),agent's action casue a desirable environment state, captured by performance measure.\\n\n",
        "2. rational agent: For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence and\\\n",
        "whatever built-in knowledge the agent has. \\n 3. rationality is different from omniscience.3. a rational agent should be autonomous (自主性) \"\"\"\n",
        "chapter2_3 = \"\"\"1.PEAS (performance, environment, actuators, sensors). \\n 2. fully observable VS partially observable, single-agent VS multiagent, competitive VS cooperative, Deterministic VS nondeterministic\\\n",
        "episodic-the next episode does not depend on the actions in previous episode, VS sequential（连续的), static VS dynamic,  discrete VS continuous, known VS unknown,  \"\"\"\n",
        "chapter2_4 = \"\"\" 1. agent=architecture+program. \\n 2. simple reflex agents, model-based reflex agents--> transition model: next state depends on the current state and action, sensor model-->the current world state reflected in agent's percepts,\\\n",
        "goal-based agents, utility-based agents. \\n 2. In single-agent environments, randomization is usually not rational. \\n3. learning agents,learning element->make improvements, performance element->select external actions. learning element use feedback\\\n",
        "from the critic on the peformance and trigger the performance element; problem generator: suggesting actions that will lead to new and informative experience. \\n 4. how the components of agent programs work:atomic->indivisible world;factored->fixed set of variable\\\n",
        "structured representation\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" An agent is anything that can be viewed as  perceiving its environment through sensors and acting upon that environment through actuators\\ \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 (ganzhi) and act in an environment\",\n",
        "\"percept\" : \"ganzhi, use sensor to perceive information from environment\",\n",
        "\"rational agent\" : \"agent to achiever best expected outcome\",\n",
        "\"value alignment problem\": \"value of machine must be aligned with human's\",\n",
        "\"consciousness\" : \"awareness of the outside world, self, experience of living\",\n",
        "\"agent function\":\"map any given percept sequence to an action\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "elCCgY64spuq"
      },
      "source": [
        "## Preview of your notes for Module 1\n",
        "\n",
        "Here's a preview of your how your notes will be displayed.  At the end of this Python notebook, we'll aggregate your notes for all modules together into a single display.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gYYeNcdM_maE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "3e7d30f0-6ef3-4d75-b9db-33ddd9693404"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n 1.formal definition of intelligence called rationality (human vs rational, thought vs behavior).\n\n2.Turing test: acting humanly, capabilities: (natural language processing, knowledge representation,automated reasoning,machine learning )\ntotal turing test: + (computer vision, robotics) . \n 3. thinking humanly, three ways to learn about human thought: (introspection, psychological experiments, brain imaging)\n\n4. thinking rationally. 5. acting rationally. \n\n## AIMA Chapter 27.1 The Limits of AI\n1. weak AI VS strong AI (human-level AI).\n 2. possible objections to AI: The argument from informality, the argument from disability, the mathematical objection \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n 1. chinese room problem: computer can generate symbol, but no understanding \n\n## AIMA 2.1 Agents and Environments\n 1. agent, sensors, actuators-->environment.\n 2. an agent’s choice of action at any given instant can depend on its built-in knowledge andon the entire percept sequence observed to date, but not on anything it hasn’t perceived. \n 3. The agent function is an abstract mathematical description; the agent program is a concreteimplementation, running within some physical system.\n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n1. rationality: consequentialism (结果主义),agent's action casue a desirable environment state, captured by performance measure.\n\n2. rational agent: For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence andwhatever built-in knowledge the agent has. \n 3. rationality is different from omniscience.3. a rational agent should be autonomous (自主性) \n\n## AIMA 2.3 The Nature of Environments\n1.PEAS (performance, environment, actuators, sensors). \n 2. fully observable VS partially observable, single-agent VS multiagent, competitive VS cooperative, Deterministic VS nondeterministicepisodic-the next episode does not depend on the actions in previous episode, VS sequential（连续的), static VS dynamic,  discrete VS continuous, known VS unknown,  \n\n## AIMA 2.4 The Structure of Agents\n 1. agent=architecture+program. \n 2. simple reflex agents, model-based reflex agents--> transition model: next state depends on the current state and action, sensor model-->the current world state reflected in agent's percepts,goal-based agents, utility-based agents. \n 2. In single-agent environments, randomization is usually not rational. \n3. learning agents,learning element->make improvements, performance element->select external actions. learning element use feedbackfrom the critic on the peformance and trigger the performance element; problem generator: suggesting actions that will lead to new and informative experience. \n 4. how the components of agent programs work:atomic->indivisible world;factored->fixed set of variablestructured representation\n\n## Module 1 Lecture Notes\n An agent is anything that can be viewed as  perceiving its environment through sensors and acting upon that environment through actuators\\ \n \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (ganzhi) and act in an environment\n* **Percept** - ganzhi, use sensor to perceive information from environment\n* **Rational agent** - agent to achiever best expected outcome\n* **Value alignment problem** - value of machine must be aligned with human's\n* **Consciousness** - awareness of the outside world, self, experience of living\n* **Agent function** - map any given percept sequence to an action\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 = \"\"\" 1. All data treated as objects.\\n 2.dynamic typing:Variables come into existence when first assigned. \\n 3. string is immutable. 4. use y = x[:] to get a (shallow) copy of\\\n",
        "any sequence. \\n 5.Tuple:  immutable ordered sequence of items; List:Mutable ordered sequence of items of mixed types. \\n 6. t = (23, 'abc', 4.56, (2,3), 'def'),  t[1:4]=('abc', 4.56, (2,3))\\\n",
        " t[1:-1]=('abc', 4.56, (2,3)),t[1:-1:2]=('abc', (2,3)). \\n 7. operations on lists: li.append('a'), li.insert(2, 'i') ,li.index('b'), li.count('b'), li.remove('b'), li.reverse(), li.sort()\\\n",
        "  \\n 8. string: words = s.split(\" \"),\"_\".join(words), s.capitalize(),s.upper(),  ' hi --'.strip(' –') 9. tuple: a = [1, 2, 3],b = ['a', 'b', 'c', 'd'], list(zip(a, b))= [(1, 'a'), (2, 'b'), (3, 'c')]\\\n",
        "  \\n 9. dict: d={}, d = {'user':'R2D2', 'p':1234, 'i':34}, d.keys(), d.items() , \\n 10. function: def myfun(b, c=3, d=\"hello\"); def print_everything(\\*args):. print_everything('a', 'b', 'c’)\\\n",
        " lst = ['a', 'b', 'c’], print_everything(\\*lst). def print_keyword_args(\\*\\*kwargs): print_keyword_args(first_name=\"John\", last_name=\"Doe\"), my_dict = {'first_name': 'Wei', 'last_name': 'Xu’}\\\n",
        " print_keyword_args(\\*\\*my_dict).  \\n 11.def fib(n, fibs={}):\\n\n",
        "if n in fibs:\\n\n",
        "print('n = %d exists' % n)\\n\n",
        "return fibs[n]\\n\n",
        "if n <= 1:\\n\n",
        "fibs[n] = n # Changes fibs!!\\n\n",
        "else:\\n\n",
        "fibs[n] = fib(n-1) + fib(n-2)\\n\n",
        "return fibs[n]\\n\n",
        " 12. def compose(f, g, x): return f(g(x)). 13.[i for i in [1, 2, 3, 4, 5] if is_even(i)], list(filter(lambda x: x%2==0, [1, 2, 3, 4, 5]))\\n\n",
        " 14. class:  class Student:\\n\n",
        "univ = \"upenn\" \\# class attribute\\n\n",
        "def \\_\\_init\\_\\_(self, name, dept):\\n\n",
        "self.student_name = \"\"\n",
        "self.student_dept = dept\\n\n",
        "def print_details(self):\\n\n",
        "print(\"Name: \" + self.student_name)\\n\n",
        "print(\"Dept: \" + self.student_dept)\\n\n",
        "15. if \\_\\_name\\_\\_ == '\\_\\_main\\_\\_':\\n\n",
        "\\# code block to be executed \\n\n",
        "16. generators: def merge(l, r):\\n\n",
        "llen = len(l)\\n\n",
        "rlen = len(r)\\n\n",
        "i = 0\\n\n",
        "j = 0\\n\n",
        "while i < llen or j < rlen:\\n\n",
        "if j == rlen or (i < llen and l[i] < r[j]):\\n\n",
        "yield l[i]\\n\n",
        "i += 1\\n\n",
        "else:\\n\n",
        "yield r[j]\\n\n",
        "j += 1\\n \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "020bbb0e-c70c-4285-ec40-d85fdadcc6d5"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n 1. All data treated as objects.\n 2.dynamic typing:Variables come into existence when first assigned. \n 3. string is immutable. 4. use y = x[:] to get a (shallow) copy ofany sequence. \n 5.Tuple:  immutable ordered sequence of items; List:Mutable ordered sequence of items of mixed types. \n 6. t = (23, 'abc', 4.56, (2,3), 'def'),  t[1:4]=('abc', 4.56, (2,3)) t[1:-1]=('abc', 4.56, (2,3)),t[1:-1:2]=('abc', (2,3)). \n 7. operations on lists: li.append('a'), li.insert(2, 'i') ,li.index('b'), li.count('b'), li.remove('b'), li.reverse(), li.sort()  \n 8. string: words = s.split(\" \"),\"_\".join(words), s.capitalize(),s.upper(),  ' hi --'.strip(' –') 9. tuple: a = [1, 2, 3],b = ['a', 'b', 'c', 'd'], list(zip(a, b))= [(1, 'a'), (2, 'b'), (3, 'c')]  \n 9. dict: d={}, d = {'user':'R2D2', 'p':1234, 'i':34}, d.keys(), d.items() , \n 10. function: def myfun(b, c=3, d=\"hello\"); def print_everything(\\*args):. print_everything('a', 'b', 'c’) lst = ['a', 'b', 'c’], print_everything(\\*lst). def print_keyword_args(\\*\\*kwargs): print_keyword_args(first_name=\"John\", last_name=\"Doe\"), my_dict = {'first_name': 'Wei', 'last_name': 'Xu’} print_keyword_args(\\*\\*my_dict).  \n 11.def fib(n, fibs={}):\n\nif n in fibs:\n\nprint('n = %d exists' % n)\n\nreturn fibs[n]\n\nif n <= 1:\n\nfibs[n] = n # Changes fibs!!\n\nelse:\n\nfibs[n] = fib(n-1) + fib(n-2)\n\nreturn fibs[n]\n\n 12. def compose(f, g, x): return f(g(x)). 13.[i for i in [1, 2, 3, 4, 5] if is_even(i)], list(filter(lambda x: x%2==0, [1, 2, 3, 4, 5]))\n\n 14. class:  class Student:\n\nuniv = \"upenn\" \\# class attribute\n\ndef \\_\\_init\\_\\_(self, name, dept):\n\nself.student_name = \"\"\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 = \"\"\" 1.STATES, Initial state, actions, transition model, goal states, action cost.  \"\"\"\n",
        "chapter3_2 = \"\"\" examples: grid world, sliding-tile puzzle, routing finding problem, traveling salesperson problem(TSP), robot navigation, automatic assembly sequencing \"\"\"\n",
        "chapter3_3 = \"\"\" 1. search tree. \\n 2. parent node-> child node (successor node), frontier. \\n 3. best-first search, choose a node based on minimum value of some evaluation function f(n)\\\n",
        " \\n 4. priority queue(pop node with minimum cost), FIFO queue, LIFO queue,. 5. problem solving performance evaluation: completeness, cost optimality, time complexity, space complexity.\"\"\"\n",
        "chapter3_4 = \"\"\" 1.\tBFS, breadth-first search, complete and cost optimal, time=O(b^d), space=O(b^d) \\n 2. DFS, depth-first search,not complete, not optimal cost, time=O(b^m),space=O(bm) \\\n",
        "it is effcient for finite state space, backtracking search -> only one successor generated at a time \\n\n",
        " 3.Dijkstra’s algorithm or uniform-cost search, is complete and cost-optimal,O(b^(1+c/e))  \\n 4. depth-limited and iterative deepening search.complete and cost optimal, time=O(b^d), space=O(bd)  \\n 5. bidirectional search, complete and cost optimal, O(b^(d/2))\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\"1. A problem-solving agent must plan ahead. The computational process that it undertakes is called search.It will consider a sequence of actions that form a path to a goal state. Such a sequence is called a solution.\n",
        " \\n 2.Optimal Solution: A solution is optimal if no solution has a lower path cost. \\n 3. frontier: those states that are available for expanding. \"\"\"\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",
        "\"transition model\":\"describe what each action does\",  \n",
        "\"completeness\" : \"guaranteed to find a solution in #finite time if there is one\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 764
        },
        "outputId": "598a8c25-01df-4f34-cdd3-3bc6c05b1d02"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n 1.STATES, Initial state, actions, transition model, goal states, action cost.  \n\n## AIMA Chapter 3.2 Example Problems\n examples: grid world, sliding-tile puzzle, routing finding problem, traveling salesperson problem(TSP), robot navigation, automatic assembly sequencing \n\n## AIMA Chapter 3.3 Search Algorithms\n 1. search tree. \n 2. parent node-> child node (successor node), frontier. \n 3. best-first search, choose a node based on minimum value of some evaluation function f(n) \n 4. priority queue(pop node with minimum cost), FIFO queue, LIFO queue,. 5. problem solving performance evaluation: completeness, cost optimality, time complexity, space complexity.\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n 1.\tBFS, breadth-first search, complete and cost optimal, time=O(b^d), space=O(b^d) \n 2. DFS, depth-first search,not complete, not optimal cost, time=O(b^m),space=O(bm) it is effcient for finite state space, backtracking search -> only one successor generated at a time \n\n 3.Dijkstra’s algorithm or uniform-cost search, is complete and cost-optimal,O(b^(1+c/e))  \n 4. depth-limited and iterative deepening search.complete and cost optimal, time=O(b^d), space=O(bd)  \n 5. bidirectional search, complete and cost optimal, O(b^(d/2))\n\n## Module 3 Lecture Notes\n1. A problem-solving agent must plan ahead. The computational process that it undertakes is called search.It will consider a sequence of actions that form a path to a goal state. Such a sequence is called a solution.\n \n 2.Optimal Solution: A solution is optimal if no solution has a lower path cost. \n 3. frontier: those states that are available for expanding. \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **Transition model** - describe what each action does\n* **Completeness** - guaranteed to find a solution in #finite time if there is one\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 = \"\"\"1. Heuristic function,h(n): estimated cost of the cheapest path from the state at node n to a goal state.\\n 2. Greedy best-first search: expand first node that closest to the goal-> min(h(n))\\\n",
        " \\n 3. A* search, f(n)=g(n)+h(n), g(n) is the path cost from the initial state to node n, and h(n) is the estimated cost of the shortest path from n to a goal state. A* search is complete, cost-optimal, and optimally efficient. \\\n",
        "\\n  4. h(n) is admissible if 0<h(n)<h*(n). \\n 5.satisficing solutions, allow inadmissible heuristic, reduce the number of nodes expanded.weighted A* search, f(n)=g(n) +Wxh(n), W>1, .\\n 6. A* search: g(n)+h(n), w=1; \\\n",
        " uniform-cost search: g(n), w=0; greedy best-first search: h(n), w=0; weighted A* search: g(n)+wxh(n) ,1<w<inf..\\n 7. Memory bounded search: beam search: limits thd size of frontier, keep only the k nodes with the best f scores,\n",
        " \\n 8. Memory-bounded search: iterative-deepening A* search (IDA), recursive best-first search( RBFS): RBFS is optimal if the heuristic function is admissible, the space complexity is linear in the depth of the deepest optimal solution.\n",
        "   \\n 9. MA*(memory-bounded A*), SMA*: to determine how much memory we have available, and allow an algorithm to use all of it, SMA* is complete, is optimal.  \"\"\"\n",
        "chapter3_6 = \"\"\" 1. effective brancing factor b*, N+1=1+b*+b*^2+...b*^d, b* close to 1 is well-designed. \\n 2. h2>h1, say h2 dominates h1, A* using h2 will never expand more node than using h1,\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"manhattan distance\" : \"sum of the horzontal and vertical distances\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 586
        },
        "outputId": "5c3842c2-348d-4d6d-a19d-3d9ebaae87a2"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n1. Heuristic function,h(n): estimated cost of the cheapest path from the state at node n to a goal state.\n 2. Greedy best-first search: expand first node that closest to the goal-> min(h(n)) \n 3. A* search, f(n)=g(n)+h(n), g(n) is the path cost from the initial state to node n, and h(n) is the estimated cost of the shortest path from n to a goal state. A* search is complete, cost-optimal, and optimally efficient. \n  4. h(n) is admissible if 0<h(n)<h*(n). \n 5.satisficing solutions, allow inadmissible heuristic, reduce the number of nodes expanded.weighted A* search, f(n)=g(n) +Wxh(n), W>1, .\n 6. A* search: g(n)+h(n), w=1;  uniform-cost search: g(n), w=0; greedy best-first search: h(n), w=0; weighted A* search: g(n)+wxh(n) ,1<w<inf..\n 7. Memory bounded search: beam search: limits thd size of frontier, keep only the k nodes with the best f scores,\n \n 8. Memory-bounded search: iterative-deepening A* search (IDA), recursive best-first search( RBFS): RBFS is optimal if the heuristic function is admissible, the space complexity is linear in the depth of the deepest optimal solution.\n   \n 9. MA*(memory-bounded A*), SMA*: to determine how much memory we have available, and allow an algorithm to use all of it, SMA* is complete, is optimal.  \n\n## AIMA Chapter 3.6 Heuristic Functions\n 1. effective brancing factor b*, N+1=1+b*+b*^2+...b*^d, b* close to 1 is well-designed. \n 2. h2>h1, say h2 dominates h1, A* using h2 will never expand more node than using h1,\n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Manhattan distance** - sum of the horzontal and vertical distances\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 = \"\"\" 1. two-player (max and min, max move first), zero-sum games. \"\"\"\n",
        "chapter5_2 = \"\"\" 1.minimax search:recursive algorithm that proceeds all the way down to the leaves of the tree and then backs up the minimax values through the tree as the recursion unwinds\\n\n",
        " 2.The minimax algorithm performs a complete depth-first exploration of the game tree. time=O(b^m), space=O(bm). 3. more than 2 players game.--> involve alliances,\\n\n",
        " 3. alpha-beta pruning: in MAX-VALUE, alpha=max(alpha,v), at least value, if v>=beta, return; in MIN-VALUE,beta=min(beta, v), at most value, if v<=alpha, return\\n\n",
        " 4.move-order can influence the efficient of alpha-beta pruning, use dynamic move -ordering scheme can improve it.\"\"\"\n",
        "chapter5_3 = \"\"\" 1. add evaluation function to state, replace the terminal test by a cutoff test, EVAL replace the utility -> Heuristic alpha-beta tree search 2 evaluation function: return expected value with probability\\\n",
        "\"\"\"\n",
        "chapter5_5 = \"\"\" 1.chance nodes: use the expected value. \\n 2. expectiminimax, time= O(b^mn^m),n is the number of distinct rolls \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" expected utility : \"average utility value weighted by probability \"\"\"\n",
        "chapter16_2 = \"\"\" 1. ORDERABILITY: Given any two lotteries, a rational agent must either prefer one or else rate them as equally preferable. That is, the agent cannot avoid deciding\\ \n",
        "TRANSITIVITY, CONTINUITY,SUBSTITUTABILITY,MONOTONICITY,DECOMPOSABILITY. 2. \"\"\"\n",
        "chapter16_3 = \"\"\" Utility functions map from lotteries to real numbers.  \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" 1. key properties of games: Two players alternate moves, Zero-sum, Clear set of legal moves,Well-defined outcomes.\\n 2. game trees:Nodes represent ‘board positions’; edges represent legal moves.\\\n",
        "   Root node is the first position in which a decision must be made.\\n\n",
        "   def max-value(state):\\n\n",
        "if the state is a terminal state:\\n\n",
        "return the state’s utility\\n\n",
        "initialize v = -∞ \\n\n",
        "for each successor of state: \\n\n",
        "v = max(v, min-value(successor)) \\n\n",
        "return v\\n\n",
        "def min-value(state):\\n\n",
        "if the state is a terminal state:\\n\n",
        "return the state’s utility\\n\n",
        "initialize v = +∞\\n\n",
        "for each successor of state:\\n\n",
        "v = min(v,max-value(successor))\\n\n",
        "return v\\n\n",
        " 2. alpha=beta pruning, alpha: MAX current lower bound on MAX outcome, beta: MIN current upper bound on MIN outcome\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"utility function\" : \"player's value when game ends in terminal state\",\n",
        "\" expected utility\" : \"average utility value weighted by probability\"    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "cad7f5d1-2901-4d58-a942-fc3004af7144"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n 1. two-player (max and min, max move first), zero-sum games. \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n 1.minimax search:recursive algorithm that proceeds all the way down to the leaves of the tree and then backs up the minimax values through the tree as the recursion unwinds\n\n 2.The minimax algorithm performs a complete depth-first exploration of the game tree. time=O(b^m), space=O(bm). 3. more than 2 players game.--> involve alliances,\n\n 3. alpha-beta pruning: in MAX-VALUE, alpha=max(alpha,v), at least value, if v>=beta, return; in MIN-VALUE,beta=min(beta, v), at most value, if v<=alpha, return\n\n 4.move-order can influence the efficient of alpha-beta pruning, use dynamic move -ordering scheme can improve it.\n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n 1. add evaluation function to state, replace the terminal test by a cutoff test, EVAL replace the utility -> Heuristic alpha-beta tree search 2 evaluation function: return expected value with probability\n\n## AIMA Chapter 5.5 Stochastic Games\n 1.chance nodes: use the expected value. \n 2. expectiminimax, time= O(b^mn^m),n is the number of distinct rolls \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n expected utility : \"average utility value weighted by probability \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n 1. ORDERABILITY: Given any two lotteries, a rational agent must either prefer one or else rate them as equally preferable. That is, the agent cannot avoid deciding\\ \nTRANSITIVITY, CONTINUITY,SUBSTITUTABILITY,MONOTONICITY,DECOMPOSABILITY. 2. \n\n## AIMA Chapter 16.3 Utility Functions\n Utility functions map from lotteries to real numbers.  \n\n## Module 5 Lecture Notes\n 1. key properties of games: Two players alternate moves, Zero-sum, Clear set of legal moves,Well-defined outcomes.\n 2. game trees:Nodes represent ‘board positions’; edges represent legal moves.   Root node is the first position in which a decision must be made.\n\n   def max-value(state):\n\nif the state is a terminal state:\n\nreturn the state’s utility\n\ninitialize v = -∞ \n\nfor each successor of state: \n\nv = max(v, min-value(successor)) \n\nreturn v\n\ndef min-value(state):\n\nif the state is a terminal state:\n\nreturn the state’s utility\n\ninitialize v = +∞\n\nfor each successor of state:\n\nv = min(v,max-value(successor))\n\nreturn v\n\n 2. alpha=beta pruning, alpha: MAX current lower bound on MAX outcome, beta: MIN current upper bound on MIN outcome\n\n## Module 5 Definitions\n* **Utility function** - player's value when game ends in terminal state\n* ** expected utility** - average utility value weighted by probability\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 = \"\"\" 1. CSP, set of variables X, set of domain D (value for X), set of CSP. \\n 2. simplest CSP: discrete, finite. But it can be infinite, linear, nonlinear\\n\n",
        "3. Unary constraint (1), binary constraint (e.g SA!=NSW), HIGHER-ORDER CONSTRAINTS.  \"\"\"\n",
        "chapter6_2 = \"\"\" 1. variable in a CSP is arc-consistent ( arc(Xi,Xj), domain Di has Dj to accept it.\\n 2. AC-3: any time (Xi, Xj) Xi lost a value, then put all Xi neighbor Xk, ARC(Xk, Xi) in the check queue.\\n\n",
        " 3.  k-consistency:for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable. 4.an arbitrary number of variables is called a global constraint (e.g, ALLdiff), but need not involve all the variables.\\n\n",
        "   4. complexity of AC-3:Assume a CSP with n variables, each with domain size at most d, and with binary constraints (arcs). Each arc (Xk, Xi) can be inserted in the queue only d times because has at most values d to delete. Checking consistency of an arc can be done in O(d^2) time, so we get total worst-case O(nd^3) time.\\n\n",
        "   5. constraint satisfaction is NPC in general, strongly k-consistent O(n^2d) \"\"\"\n",
        "chapter6_3 = \"\"\" 1. backtracking search procedure, The INFERENCE function can optionally impose arc-, path-, or -consistency, as desired. \\n 2. improve of backtrack: minimum_ramaining_value (MRV), var with MRV go first; tie-breaker, most constrained variable go first—degree heuristic;\\\n",
        " Choose least_constraining-value first; inference function can improved by forward checking,Maintaining arc consistency, MAC, AC-3, but not a queue with full arcs, only the arcs (Xk,Xi).  \"\"\"\n",
        "chapter6_4 = \"\"\"  min-conflicts heuristic: select the value that results in the minimum number of conflicts with other variables \"\"\"\n",
        "chapter6_5 = \"\"\" 1. topological sort->tree structured CSP.\\n 2. Choose a subset of the CSP’s variables such that the constraint graph becomes a tree after removal of . is called a cycle cutset.\\n\n",
        "3.  tree decomposition of the constraint graph: a transformation of the original graph into a tree where each node in the tree consists of a set of variables, time=O(nd^2)   \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\" 1. Represent the constraints that solutions must satisfy in a uniform declarative language;  Find solutions by GENERAL PURPOSE search algorithms with no changes from problem to problem\\n\n",
        "2. CSP problem: A consistent assignment does not violate the constraints. 3. benifit: Clean specification of many problems, generic goal,successor function & heuristics; CSP “knows” which variables violate a constraint;\\n\n",
        " CSPs: Automatically prune off all branches that violate constraints.\\n\n",
        "  function AC-3(csp) return the CSP, possibly with reduced domains\\n\n",
        "inputs: csp, a binary csp with variables {X 1 , X 2 , …, X n }\\n\n",
        "local variables: queue, a queue of arcs initially the arcs in csp\\n\n",
        "while queue is not empty do\\n\n",
        "(X i , X j ) ← queue.pop()\\n\n",
        "if REMOVE-INCONSISTENT-VALUES(X i , X j ) then\\n\n",
        "for each X k in NEIGHBORS[X i ] – {X j } do add (X k ,X i ) to queue \\n\n",
        "function REMOVE-INCONSISTENT-VALUES(X i , X j ) return true iff we remove a value\\n\n",
        "removed ← false \\n\n",
        "for each x in DOMAIN[X i ] do \\n\n",
        "if no value y in DOMAIN[X j ] allows (x,y) to satisfy\\n\n",
        "the constraints between X i and X j\\n\n",
        "then delete x from DOMAIN[X i ]; removed ← true\\n\n",
        "return removed\\n\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"arc-consistent\" : \"CSP's value satisfies variable's binary constraints\",    \n",
        "}\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "10ebacaa-61de-4bcf-c333-b289d4c53992"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n 1. CSP, set of variables X, set of domain D (value for X), set of CSP. \n 2. simplest CSP: discrete, finite. But it can be infinite, linear, nonlinear\n\n3. Unary constraint (1), binary constraint (e.g SA!=NSW), HIGHER-ORDER CONSTRAINTS.  \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n 1. variable in a CSP is arc-consistent ( arc(Xi,Xj), domain Di has Dj to accept it.\n 2. AC-3: any time (Xi, Xj) Xi lost a value, then put all Xi neighbor Xk, ARC(Xk, Xi) in the check queue.\n\n 3.  k-consistency:for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable. 4.an arbitrary number of variables is called a global constraint (e.g, ALLdiff), but need not involve all the variables.\n\n   4. complexity of AC-3:Assume a CSP with n variables, each with domain size at most d, and with binary constraints (arcs). Each arc (Xk, Xi) can be inserted in the queue only d times because has at most values d to delete. Checking consistency of an arc can be done in O(d^2) time, so we get total worst-case O(nd^3) time.\n\n   5. constraint satisfaction is NPC in general, strongly k-consistent O(n^2d) \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n 1. backtracking search procedure, The INFERENCE function can optionally impose arc-, path-, or -consistency, as desired. \n 2. improve of backtrack: minimum_ramaining_value (MRV), var with MRV go first; tie-breaker, most constrained variable go first—degree heuristic; Choose least_constraining-value first; inference function can improved by forward checking,Maintaining arc consistency, MAC, AC-3, but not a queue with full arcs, only the arcs (Xk,Xi).  \n\n## AIMA Chapter 6.4 Local Search for CSPs\n  min-conflicts heuristic: select the value that results in the minimum number of conflicts with other variables \n\n## AIMA Chapter 6.5 The Structure of Problems\n 1. topological sort->tree structured CSP.\n 2. Choose a subset of the CSP’s variables such that the constraint graph becomes a tree after removal of . is called a cycle cutset.\n\n3.  tree decomposition of the constraint graph: a transformation of the original graph into a tree where each node in the tree consists of a set of variables, time=O(nd^2)   \n\n## Module 6 Lecture Notes\n 1. Represent the constraints that solutions must satisfy in a uniform declarative language;  Find solutions by GENERAL PURPOSE search algorithms with no changes from problem to problem\n\n2. CSP problem: A consistent assignment does not violate the constraints. 3. benifit: Clean specification of many problems, generic goal,successor function & heuristics; CSP “knows” which variables violate a constraint;\n\n CSPs: Automatically prune off all branches that violate constraints.\n\n  function AC-3(csp) return the CSP, possibly with reduced domains\n\ninputs: csp, a binary csp with variables {X 1 , X 2 , …, X n }\n\nlocal variables: queue, a queue of arcs initially the arcs in csp\n\nwhile queue is not empty do\n\n(X i , X j ) ← queue.pop()\n\nif REMOVE-INCONSISTENT-VALUES(X i , X j ) then\n\nfor each X k in NEIGHBORS[X i ] – {X j } do add (X k ,X i ) to queue \n\nfunction REMOVE-INCONSISTENT-VALUES(X i , X j ) return true iff we remove a value\n\nremoved ← false \n\nfor each x in DOMAIN[X i ] do \n\nif no value y in DOMAIN[X j ] allows (x,y) to satisfy\n\nthe constraints between X i and X j\n\nthen delete x from DOMAIN[X i ]; removed ← true\n\nreturn removed\n\n\n## Module 6 Definitions\n* **Arc-consistent** - CSP's value satisfies variable's binary constraints\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 = \"\"\" 1. knowledge base (KB): a set of sentences, each sentence is expressed in knowledge representation language. sentence can be axiom (公理) if given without being derived from other sentences.\\n\n",
        "2. KB need to have way to add or query(问询). 3. KB-Agent process: add percept to the KB; ask the KB for the action; tell KB it take the action.4. declarative approach (声明式的): KB can be empty, tell sentence one by one until the agent knows\\\n",
        "\"\"\"\n",
        "chapter7_2 = \"\"\" Wumpus World \"\"\"\n",
        "chapter7_3 = \"\"\" 1. If a A sentence is true in model , we say that M satisfies or sometimes M is a model of A. ->M(A).  \\n 2. ENTAILMENT a|=b, M(a) belong to M(b).\\n 3. logical inference:KB belong to M(a)\\n\n",
        "4. An inference algorithm that derives only entailed sentences is called sound or truth- preserving. 5.completeness: an inference algorithm is complete if it can derive any sentence that is entailed. \\\n",
        "\"\"\"\n",
        "chapter7_4 = \"\"\" 1. ¬ (not), ∧ (and) conjunction, ∨ (or) disjunction , ⇒ (implies) implication . \\n 2. truth-table enumeration algorithm \"\"\"\n",
        "chapter7_5 = \"\"\" 1. commutativity:  a∧b=b∧a, associativity: (a∧b)∧c=a∧(b∧c), contraposition: a⇒b = ¬b⇒¬a ; implication elimination:a⇒b =¬a ∨b\\\n",
        "Demorgan: ¬ (a∧b) = ¬a∨¬b, ¬ (a∨b) = ¬a∧¬b, Distributivity of ∨ over ∧: (a∧b)∨c = (avc) ∧ (b∨c), Distributivity of∧ over ∨ :(a∨b)∧c = (a∧c) ∨ (b∧c).\\n\n",
        "2. inference rules: a⇒b, if a then b, a∧b then a,  \\n 3.  monotonicity(单调性): if KB ⊨ α then KB ∧ β ⊨ α; \\n 4. resolution, that yields a complete inference algorithm when coupled with any complete search algorithm.\\n\n",
        "5. resolution, L_i and m are complementary literals, then L_1∨L_2∨L_3, ¬L_3 = L_1∨L_2, eliminate the complementary clause, \\n  6. You can resolve only one pair of complementary literals at a time. \\n\n",
        "7. CNF: conjunctive(∧) normal form, the resolution rule applies only to clauses (disjunctions (∨) of literals) , CNF requires ¬ to appear only in literals,\\n\n",
        "8.resolution algorithm:  to show that KB |=a,we show that (KB ∧ ¬α) is unsatisfied (if there are one empty, then proved) -> converted  (KB ∧ ¬α) into CNF,  apply resolution rule to th eresulting clauses, each pair contains complementary literals is resolved to produce a new clause,\\\n",
        "which is added to the set if it is not present, the process continues untile one of two things happens:  there are no new clauses that can be added, in which case KB does not entail a, or,two clauses resolve to yield the empty clause, in which case entails a\\n\n",
        "9. definite clause: which is a disjunction of literals of which exactly one is positive, (¬L  ∨ ¬Breeze ∨ B  ) ;  Horn clause, which is a disjunction of literals of which at most one is positive. \\n 10. Horn clauses are closed under resolution: if you resolve two\\\n",
        "Horn clauses, you get back a Horn clause. \\n 11. KB with only definite clauses,  ¬L 1,1 ∨ ¬Breeze ∨ B 1,1 can be written as implication (L 1,1 ∧ Breeze) ⇒ B 1,1 .  Inference with Horn clauses can be done through the forward-chaining and\\\n",
        "backward-chaining algorithms. \\n 12. forward-chaining: if L11, and Breeze are known, and (L 1,1 ∧ Breeze) ⇒ B 1,1, then B11 can be added  \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" same as book note \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"inference\" : \"deriving new sentences from old\", \n",
        "\"entailment\" : \"a sentence follows logically from another sentence\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "079fca81-381b-4543-9063-cb9eceada6f7"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n 1. knowledge base (KB): a set of sentences, each sentence is expressed in knowledge representation language. sentence can be axiom (公理) if given without being derived from other sentences.\n\n2. KB need to have way to add or query(问询). 3. KB-Agent process: add percept to the KB; ask the KB for the action; tell KB it take the action.4. declarative approach (声明式的): KB can be empty, tell sentence one by one until the agent knows\n\n## AIMA Chapter 7.2 The Wumpus World\n Wumpus World \n\n## AIMA Chapter 7.3 Logic\n 1. If a A sentence is true in model , we say that M satisfies or sometimes M is a model of A. ->M(A).  \n 2. ENTAILMENT a|=b, M(a) belong to M(b).\n 3. logical inference:KB belong to M(a)\n\n4. An inference algorithm that derives only entailed sentences is called sound or truth- preserving. 5.completeness: an inference algorithm is complete if it can derive any sentence that is entailed. \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n 1. ¬ (not), ∧ (and) conjunction, ∨ (or) disjunction , ⇒ (implies) implication . \n 2. truth-table enumeration algorithm \n\n## AIMA 7.5 Propositional Theorem Proving\n 1. commutativity:  a∧b=b∧a, associativity: (a∧b)∧c=a∧(b∧c), contraposition: a⇒b = ¬b⇒¬a ; implication elimination:a⇒b =¬a ∨bDemorgan: ¬ (a∧b) = ¬a∨¬b, ¬ (a∨b) = ¬a∧¬b, Distributivity of ∨ over ∧: (a∧b)∨c = (avc) ∧ (b∨c), Distributivity of∧ over ∨ :(a∨b)∧c = (a∧c) ∨ (b∧c).\n\n2. inference rules: a⇒b, if a then b, a∧b then a,  \n 3.  monotonicity(单调性): if KB ⊨ α then KB ∧ β ⊨ α; \n 4. resolution, that yields a complete inference algorithm when coupled with any complete search algorithm.\n\n5. resolution, L_i and m are complementary literals, then L_1∨L_2∨L_3, ¬L_3 = L_1∨L_2, eliminate the complementary clause, \n  6. You can resolve only one pair of complementary literals at a time. \n\n7. CNF: conjunctive(∧) normal form, the resolution rule applies only to clauses (disjunctions (∨) of literals) , CNF requires ¬ to appear only in literals,\n\n8.resolution algorithm:  to show that KB |=a,we show that (KB ∧ ¬α) is unsatisfied (if there are one empty, then proved) -> converted  (KB ∧ ¬α) into CNF,  apply resolution rule to th eresulting clauses, each pair contains complementary literals is resolved to produce a new clause,which is added to the set if it is not present, the process continues untile one of two things happens:  there are no new clauses that can be added, in which case KB does not entail a, or,two clauses resolve to yield the empty clause, in which case entails a\n\n9. definite clause: which is a disjunction of literals of which exactly one is positive, (¬L  ∨ ¬Breeze ∨ B  ) ;  Horn clause, which is a disjunction of literals of which at most one is positive. \n 10. Horn clauses are closed under resolution: if you resolve twoHorn clauses, you get back a Horn clause. \n 11. KB with only definite clauses,  ¬L 1,1 ∨ ¬Breeze ∨ B 1,1 can be written as implication (L 1,1 ∧ Breeze) ⇒ B 1,1 .  Inference with Horn clauses can be done through the forward-chaining andbackward-chaining algorithms. \n 12. forward-chaining: if L11, and Breeze are known, and (L 1,1 ∧ Breeze) ⇒ B 1,1, then B11 can be added  \n\n## Module 7 Lecture Notes\n same as book note \n\n## Module 7 Definitions\n* **Inference** - deriving new sentences from old\n* **Entailment** - a sentence follows logically from another sentence\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": "a431feae-6504-4c34-b27a-ea610bbbc46c"
      },
      "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": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n 1.formal definition of intelligence called rationality (human vs rational, thought vs behavior).\n\n2.Turing test: acting humanly, capabilities: (natural language processing, knowledge representation,automated reasoning,machine learning )\ntotal turing test: + (computer vision, robotics) . \n 3. thinking humanly, three ways to learn about human thought: (introspection, psychological experiments, brain imaging)\n\n4. thinking rationally. 5. acting rationally. \n\n## AIMA Chapter 27.1 The Limits of AI\n1. weak AI VS strong AI (human-level AI).\n 2. possible objections to AI: The argument from informality, the argument from disability, the mathematical objection \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n 1. chinese room problem: computer can generate symbol, but no understanding \n\n## AIMA 2.1 Agents and Environments\n 1. agent, sensors, actuators-->environment.\n 2. an agent’s choice of action at any given instant can depend on its built-in knowledge andon the entire percept sequence observed to date, but not on anything it hasn’t perceived. \n 3. The agent function is an abstract mathematical description; the agent program is a concreteimplementation, running within some physical system.\n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n1. rationality: consequentialism (结果主义),agent's action casue a desirable environment state, captured by performance measure.\n\n2. rational agent: For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence andwhatever built-in knowledge the agent has. \n 3. rationality is different from omniscience.3. a rational agent should be autonomous (自主性) \n\n## AIMA 2.3 The Nature of Environments\n1.PEAS (performance, environment, actuators, sensors). \n 2. fully observable VS partially observable, single-agent VS multiagent, competitive VS cooperative, Deterministic VS nondeterministicepisodic-the next episode does not depend on the actions in previous episode, VS sequential（连续的), static VS dynamic,  discrete VS continuous, known VS unknown,  \n\n## AIMA 2.4 The Structure of Agents\n 1. agent=architecture+program. \n 2. simple reflex agents, model-based reflex agents--> transition model: next state depends on the current state and action, sensor model-->the current world state reflected in agent's percepts,goal-based agents, utility-based agents. \n 2. In single-agent environments, randomization is usually not rational. \n3. learning agents,learning element->make improvements, performance element->select external actions. learning element use feedbackfrom the critic on the peformance and trigger the performance element; problem generator: suggesting actions that will lead to new and informative experience. \n 4. how the components of agent programs work:atomic->indivisible world;factored->fixed set of variablestructured representation\n\n## Module 1 Lecture Notes\n An agent is anything that can be viewed as  perceiving its environment through sensors and acting upon that environment through actuators\\ \n \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive (ganzhi) and act in an environment\n* **Percept** - ganzhi, use sensor to perceive information from environment\n* **Rational agent** - agent to achiever best expected outcome\n* **Value alignment problem** - value of machine must be aligned with human's\n* **Consciousness** - awareness of the outside world, self, experience of living\n* **Agent function** - map any given percept sequence to an action\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n 1. All data treated as objects.\n 2.dynamic typing:Variables come into existence when first assigned. \n 3. string is immutable. 4. use y = x[:] to get a (shallow) copy ofany sequence. \n 5.Tuple:  immutable ordered sequence of items; List:Mutable ordered sequence of items of mixed types. \n 6. t = (23, 'abc', 4.56, (2,3), 'def'),  t[1:4]=('abc', 4.56, (2,3)) t[1:-1]=('abc', 4.56, (2,3)),t[1:-1:2]=('abc', (2,3)). \n 7. operations on lists: li.append('a'), li.insert(2, 'i') ,li.index('b'), li.count('b'), li.remove('b'), li.reverse(), li.sort()  \n 8. string: words = s.split(\" \"),\"_\".join(words), s.capitalize(),s.upper(),  ' hi --'.strip(' –') 9. tuple: a = [1, 2, 3],b = ['a', 'b', 'c', 'd'], list(zip(a, b))= [(1, 'a'), (2, 'b'), (3, 'c')]  \n 9. dict: d={}, d = {'user':'R2D2', 'p':1234, 'i':34}, d.keys(), d.items() , \n 10. function: def myfun(b, c=3, d=\"hello\"); def print_everything(\\*args):. print_everything('a', 'b', 'c’) lst = ['a', 'b', 'c’], print_everything(\\*lst). def print_keyword_args(\\*\\*kwargs): print_keyword_args(first_name=\"John\", last_name=\"Doe\"), my_dict = {'first_name': 'Wei', 'last_name': 'Xu’} print_keyword_args(\\*\\*my_dict).  \n 11.def fib(n, fibs={}):\n\nif n in fibs:\n\nprint('n = %d exists' % n)\n\nreturn fibs[n]\n\nif n <= 1:\n\nfibs[n] = n # Changes fibs!!\n\nelse:\n\nfibs[n] = fib(n-1) + fib(n-2)\n\nreturn fibs[n]\n\n 12. def compose(f, g, x): return f(g(x)). 13.[i for i in [1, 2, 3, 4, 5] if is_even(i)], list(filter(lambda x: x%2==0, [1, 2, 3, 4, 5]))\n\n 14. class:  class Student:\n\nuniv = \"upenn\" \\# class attribute\n\ndef \\_\\_init\\_\\_(self, name, dept):\n\nself.student_name = \"\"\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mMVMtusH9sfr"
      },
      "source": [
        "# New Section"
      ]
    }
  ]
}