{
  "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": "a934668e-594c-4333-b3aa-1802c417b444"
      },
      "source": [
        "chapter_2_1_example = \"\"\"\n",
        "Regular expressions are an algebraic notation for characterizing \\\n",
        "a set of strings that are useful for searching for a pattern or through a corpus.\\\n",
        "Only the first matching result will be shown. The search string is case sensitive, \\\n",
        "but it can consist of a single character or a sequence of characters. \\\n",
        "While square braces specify a disjunction of characters, the dash can more easily look \\\n",
        "for characters over a range. The caret specifies the non-existence of a character. \\\n",
        "Additionally, the (?) is used to for flexibility on a single character, meaning \\\n",
        "\"the preceding character or nothing\". More importantly, the Kleene star means zero or \\\n",
        "more occurrences of the immediately previous character or regular expression in square braces.\\\n",
        "...\n",
        "\"\"\"\n",
        "\n",
        "length = len(chapter_2_1_example.split(\" \"))\n",
        "print(\"The example summary is {len} words long, so you could write an additional \\\n",
        "{remaining} words.\".format(len=length, remaining=(500-length)))"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 116 words long, so you could write an additional 384 words.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "s3Uk9gQTevcj"
      },
      "source": [
        "## Example summary length\n",
        "\n",
        "The maximum summary length for each section is 500 words / 3000 characters.  Hopefully you'll find that to be quite generous. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8DvZ57A-djo1",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3f5b1414-037a-42f3-ee79-865bce19a835"
      },
      "source": [
        "# This is an example of a 500 word placeholder\n",
        "placeholder = \"\"\"ultrices vitae auctor eu augue ut lectus arcu bibendum at varius \\\n",
        " vel pharetra vel turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet \\\n",
        " bibendum enim facilisis gravida neque convallis a cras semper auctor neque vitae \\\n",
        " tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh \\\n",
        " venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut \\\n",
        " faucibus pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper \\ \n",
        " quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu \\\n",
        " scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque \\ \n",
        " laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt eget \\\n",
        " nullam non nisi est sit amet facilisis magna etiam tempor orci eu lobortis \\\n",
        " elementum nibh tellus molestie nunc non blandit massa enim nec dui nunc mattis \\\n",
        " enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor \\\n",
        " massa id neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus \\\n",
        " imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque \\\n",
        " penatibus et magnis dis parturient montes nascetur ridiculus mus mauris vitae \\\n",
        " ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan \\\n",
        " lacus vel facilisis volutpat est velit egestas dui id ornare arcu odio ut sem nulla \\\n",
        " pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer \\\n",
        " quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa \\\n",
        " tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc \\\n",
        " consequat interdum varius sit amet mattis vulputate enim nulla aliquet porttitor \\\n",
        " lacus luctus accumsan tortor posuere ac ut consequat semper viverra nam libero \\\n",
        " justo laoreet sit amet cursus sit amet dictum sit amet justo donec enim diam \\\n",
        " vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris \\\n",
        " pharetra et ultrices neque ornare aenean euismod elementum nisi quis eleifend quam \\\n",
        " adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque viverra justo \\\n",
        " nec ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis in \\\n",
        " eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod \\\n",
        " quis viverra nibh cras pulvinar mattis nunc sed blandit libero volutpat sed cras \\\n",
        " ornare arcu dui vivamus arcu felis bibendum ut tristique et egestas quis ipsum \\\n",
        " suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque \\\n",
        " dignissim enim sit amet venenatis urna cursus eget nunc scelerisque viverra mauris \\\n",
        " in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in \\\n",
        " pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet \\\n",
        " risus feugiat in ante metus dictum at tempor commodo ullamcorper a lacus vestibulum \\\n",
        " sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit \\\n",
        " volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in \\\n",
        " dictum non consectetur a erat nam at lectus urna\"\"\"\n",
        "\n",
        "print(\"The length in words is\", len(placeholder.split(' ')))\n",
        "print(\"The length in characters is\", len(placeholder))"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yG3-YncJfTB"
      },
      "source": [
        "# Permissions to use your summaries\n",
        "\n",
        "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
        "\n",
        "1. Please enter your name.  \n",
        "\n",
        "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
        "\n",
        "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = False"
      ],
      "execution_count": 3,
      "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 = \"\"\"AI->Science of making machines act rationally. think,act like people, think,act rationally. If AI->behaves irrationally, it is because of the objectives that were fed in. For example, if the sole purpose of the AI is to win chess, then it might hypnotize, bribe the opponent,etc.\\\n",
        "If something is wrong with the objectives, initially we used to reset but now it will have bad consequences. More Intelligence->worse consequences. Machines should satisfy our objectives not theirs. Uncertainity makes a machine act more cautiously.\\\n",
        "perfect rationallity->impossible. Doing the right thing->based on objective->minimize loss function\\\n",
        "Thinking rationally->laws of thought->correct inference\"\"\" \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 = \"\"\" Weak AI->machines act as if they are intelligent. Strong AI,human AI, general AI->Machines actually consciously think.\\\n",
        "Human behaviour too complex to be fit into formal rules. GOFAI(only rules) this has eclipsed. Qualification problem->difficulty to capture every behaviour into a set of rules. Embodied cognition approach, brain is not seperate, vision, robotics, etc become central rather than peripheral\\\n",
        "Turing machines -> infinite, computers->finite. Godel's incompleteness theorem.Humans change their minds, so do computers->upgrade hardware.\\\n",
        "Turing test->program has a conversation with an interrrogator who has to guess whether it is a computer or not. Computer has to fool I 30% of the time\"\"\"\n",
        "chapter27_2 = \"\"\" Can machines think->Djikstra->not a relevant question. Turing->yes everyone can think(flights can fly, submarines can swim).\\\n",
        "Rejected by Searle. Chinese room->human no understanding of Chinese, passed a stack of papers, rulebook in english, papers in chinese. Translate and send it back. Using the responses the system responds in chinese. Stacks of paper doesn't know chinese, human doesn't understand chinese.\\\n",
        "Therefore computers do not generate understanding.(Chinese room does the same as a computer). Biological naturalism. Critics->Humans made of cells, cell have no understanding hence humans don't either.\\\n",
        " Qualia-> subjective experience. Do machines feel sympathy? Humans have an advantage here. Want to know how it feels like to eat ice cream, you can actually go eat an ice-cream.\"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_3 = \"\"\" PEAS(performance,environment,Actuators,sensors).Task environment->problem, agent->solution. Eglish tutor:P->studen't score on test,E->students,staff,A->\\\n",
        "display feedback,S->keyboard,voice\\\n",
        "Task environment->lack of sensor data,noise->partially observable. No sensors->unobservably. Observable fully->no need to maintain internal state.\\\n",
        "single/multiagent->competitive, partially cooperative.\\\n",
        "Deterministic/non-deterministic->you know next state, when performing an action with current state.Stochastic->probability assosciated with it. \\\n",
        "Episodic/sequential->defective parts/chess,taxi driving(long term consequences)\\\n",
        "Static/dynamic->static->agent doesn't need to look at the world when making decisions. Semidynamic->chess when played with a clock.\n",
        "Taxi driving->dynamic, crossword->static\\\n",
        "discrete/continuous->states,\n",
        "known/unknown->outcomes known or you need to learn. Known+partially observable->solitaire->rules known, cards unknown. unknown+fully observable->video game, seen but don't know what to press \"\"\"\n",
        "chapter2_4 = \"\"\" Vacuum world, simple reflexive agent. Partially observable->maintain internal state->changing lanes,see where other cars are. Condition-action sequence\\\n",
        "model based agents->transition model->how the next state depends on current state and action, sensor model->what happens when agents performs an action\\\n",
        "Atomic representation, factored representation,structured representation(objects and their relationships described). concise, more expressive.localist->one to one mapping between concept and representation.Distributed representation.\\\n",
        "Learning based agent->learning element_>makes improvement,performance element->selects actions, problem generator->new experiences\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Descartes->principle of dualism, mind is seperate from the body. Cutting of limbs, etc doesn't affect the brain.\\\n",
        "How do you know you are not an automaton->they can't properly use language.Turing test, chinese room. Eliza->early NLP program.\\\n",
        "Daniel->Brain in A vat experiment: Brain hooked up to a computer program. How do you know what you perceive?\\\n",
        "Human agents->actuators->legs,hand,sensors->eyes,ears.Robot->actuators->motors. Sensors->camera\\.Software agent->actuators->send files,sensors->keyboard,mouse(human input)\n",
        "Agent behaviour defined by Agent function: f:P->a that maps percepts to action. The agent program runs on the physical architecture to produce f. Agent->architecture+program\\\n",
        "ratinality->information gathering, exploration \"\"\"\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",
        "\"value alignment problem\": \"problem of achieving an agreement with our true preferences and objectives we design for the machine\",\n",
        "\"Biological naturalism\":\"Mental states are caused by the low level processes from neurons.\",\n",
        "\"agent\" : \"An agent is anything that perceives its environment through sensors and can act on its environment through actuators\",\n",
        "\"percept\" : \"the agent’s perceptual inputs at any given instance.\",\n",
        "\"percept sequence\" : \"history of percepts \"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "elCCgY64spuq"
      },
      "source": [
        "## Preview of your notes for Module 1\n",
        "\n",
        "Here's a preview of your how your notes will be displayed.  At the end of this Python notebook, we'll aggregate your notes for all modules together into a single display.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gYYeNcdM_maE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "cellView": "form",
        "outputId": "020206dc-0038-4650-a0af-280d1c873e15"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "from IPython.display import display, Markdown, Latex\n",
        "\n",
        "module1_sections = [\n",
        "  (\"AIMA Chapter 1.1 What is AI?\", chapter1_1),\n",
        "  (\"AIMA Chapter 27.1 The Limits of AI\", chapter27_1),\n",
        "  (\"AIMA Chapter 27.1 Can Machines Really Think?\", chapter27_2),\n",
        "  (\"AIMA 2.1 Agents and Environments\", chapter2_1),\n",
        "  (\"AIMA 2.2 Good Behavior: The Concept of Rationality\", chapter2_2),\n",
        "  (\"AIMA 2.3 The Nature of Environments\", chapter2_3),\n",
        "  (\"AIMA 2.4 The Structure of Agents\", chapter2_4),\n",
        "  (\"Module 1 Lecture Notes\", module1_lecture_notes),\n",
        "]\n",
        "\n",
        "\n",
        "def length_check(sections):\n",
        "  warnings = \"\"\n",
        "  for section, summary in sections:\n",
        "    max_word_length = 500\n",
        "    max_character_length = 3000\n",
        "    if \"lecture\" in section.lower():\n",
        "      # It's OK to do longer summaries of the lectures\n",
        "      max_word_length = 2000\n",
        "      max_character_length = 12000  \n",
        "    if (len(summary) > max_character_length or len(summary.split(' ')) > max_word_length):\n",
        "      warnings += \"WARNING: Your summary of '{section}' is too long!\\n\".format(section=section)\n",
        "  return warnings\n",
        "\n",
        "def length_check_definitions(definitions):\n",
        "  warnings = \"\"\n",
        "  for concept, definition in definitions.items():\n",
        "    if(len(definition.split(' ')) > 20):\n",
        "      warnings += \"WARNING: Your definition of '{concept}' is too long!\\n\".format(concept=concept)\n",
        "  return warnings\n",
        "\n",
        "\n",
        "def format_module(module_num, title, sections, definitions, show_placeholder=False):\n",
        "  markdown = \"\"\n",
        "\n",
        "  # Check summary lengths\n",
        "  warnings = length_check(sections)\n",
        "  if warnings != \"\":\n",
        "    markdown += \"## \" + warnings\n",
        "\n",
        "  # Check definition lengths\n",
        "  warnings = length_check_definitions(definitions)\n",
        "  if warnings != \"\":\n",
        "    markdown += \"## \" + warnings\n",
        "\n",
        "  markdown += \"# Module {num}: {title}\\n\".format(num=module_num, title=title)\n",
        "\n",
        "\n",
        "  for section, summary in sections:\n",
        "    if show_placeholder and summary == \" Your summary here \":\n",
        "      summary = placeholder\n",
        "    markdown += \"## {section}\\n{summary}\\n\\n\".format(section=section, summary=summary)\n",
        "  \n",
        "  markdown += \"## Module {num} Definitions\\n\".format(num=module_num)\n",
        "  for concept, definition in definitions.items():\n",
        "    markdown += \"* **{concept}** - {definition}\\n\".format(concept=concept.capitalize(), definition=definition)\n",
        "  return markdown\n",
        "\n",
        "\n",
        "module1_markdown = format_module(1, \"Rational Agents and Task Environments\", module1_sections, module1_definitions)\n",
        "display(Markdown(module1_markdown))"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\nAI->Science of making machines act rationally. think,act like people, think,act rationally. If AI->behaves irrationally, it is because of the objectives that were fed in. For example, if the sole purpose of the AI is to win chess, then it might hypnotize, bribe the opponent,etc.If something is wrong with the objectives, initially we used to reset but now it will have bad consequences. More Intelligence->worse consequences. Machines should satisfy our objectives not theirs. Uncertainity makes a machine act more cautiously.perfect rationallity->impossible. Doing the right thing->based on objective->minimize loss functionThinking rationally->laws of thought->correct inference\n\n## AIMA Chapter 27.1 The Limits of AI\n Weak AI->machines act as if they are intelligent. Strong AI,human AI, general AI->Machines actually consciously think.Human behaviour too complex to be fit into formal rules. GOFAI(only rules) this has eclipsed. Qualification problem->difficulty to capture every behaviour into a set of rules. Embodied cognition approach, brain is not seperate, vision, robotics, etc become central rather than peripheralTuring machines -> infinite, computers->finite. Godel's incompleteness theorem.Humans change their minds, so do computers->upgrade hardware.Turing test->program has a conversation with an interrrogator who has to guess whether it is a computer or not. Computer has to fool I 30% of the time\n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Can machines think->Djikstra->not a relevant question. Turing->yes everyone can think(flights can fly, submarines can swim).Rejected by Searle. Chinese room->human no understanding of Chinese, passed a stack of papers, rulebook in english, papers in chinese. Translate and send it back. Using the responses the system responds in chinese. Stacks of paper doesn't know chinese, human doesn't understand chinese.Therefore computers do not generate understanding.(Chinese room does the same as a computer). Biological naturalism. Critics->Humans made of cells, cell have no understanding hence humans don't either. Qualia-> subjective experience. Do machines feel sympathy? Humans have an advantage here. Want to know how it feels like to eat ice cream, you can actually go eat an ice-cream.\n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n PEAS(performance,environment,Actuators,sensors).Task environment->problem, agent->solution. Eglish tutor:P->studen't score on test,E->students,staff,A->display feedback,S->keyboard,voiceTask environment->lack of sensor data,noise->partially observable. No sensors->unobservably. Observable fully->no need to maintain internal state.single/multiagent->competitive, partially cooperative.Deterministic/non-deterministic->you know next state, when performing an action with current state.Stochastic->probability assosciated with it. Episodic/sequential->defective parts/chess,taxi driving(long term consequences)Static/dynamic->static->agent doesn't need to look at the world when making decisions. Semidynamic->chess when played with a clock.\nTaxi driving->dynamic, crossword->staticdiscrete/continuous->states,\nknown/unknown->outcomes known or you need to learn. Known+partially observable->solitaire->rules known, cards unknown. unknown+fully observable->video game, seen but don't know what to press \n\n## AIMA 2.4 The Structure of Agents\n Vacuum world, simple reflexive agent. Partially observable->maintain internal state->changing lanes,see where other cars are. Condition-action sequencemodel based agents->transition model->how the next state depends on current state and action, sensor model->what happens when agents performs an actionAtomic representation, factored representation,structured representation(objects and their relationships described). concise, more expressive.localist->one to one mapping between concept and representation.Distributed representation.Learning based agent->learning element_>makes improvement,performance element->selects actions, problem generator->new experiences\n\n## Module 1 Lecture Notes\n Descartes->principle of dualism, mind is seperate from the body. Cutting of limbs, etc doesn't affect the brain.How do you know you are not an automaton->they can't properly use language.Turing test, chinese room. Eliza->early NLP program.Daniel->Brain in A vat experiment: Brain hooked up to a computer program. How do you know what you perceive?Human agents->actuators->legs,hand,sensors->eyes,ears.Robot->actuators->motors. Sensors->camera\\.Software agent->actuators->send files,sensors->keyboard,mouse(human input)\nAgent behaviour defined by Agent function: f:P->a that maps percepts to action. The agent program runs on the physical architecture to produce f. Agent->architecture+programratinality->information gathering, exploration \n\n## Module 1 Definitions\n* **Value alignment problem** - problem of achieving an agreement with our true preferences and objectives we design for the machine\n* **Biological naturalism** - Mental states are caused by the low level processes from neurons.\n* **Agent** - An agent is anything that perceives its environment through sensors and can act on its environment through actuators\n* **Percept** - the agent’s perceptual inputs at any given instance.\n* **Percept sequence** - history of percepts \n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9xRbdqDox2zD"
      },
      "source": [
        "#Module 2 - Python"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DpBvu7EMx7sy"
      },
      "source": [
        "# No readings for this module.  Instead you can summarize the lecture instead.\n",
        "\n",
        "# Lecture notes \n",
        "module2_lecture_notes = \"\"\" Python is strongly typed which means that a variable has a type and that the type matters when performing operations on the variable. It is also dynamically typed which means that the type of a variable is determined only during runtime.\\\n",
        "Join is faster than loops->allocates memory upfront and the number of times memory is allocated is less. Useful for large inputs.\\\n",
        "Strong type example: def join(number:int, name:str='xyz')->str return name*number.\n",
        "Duck typing->doesn't check for types.n order for you to call len(obj), the only real constraint on obj is that it must define a .__len__() method. Otherwise, the object can be of types as different as str, list\\\n",
        "Valid lists->[add,sub] where add and sub are predefined functions. A hash function takes a message of variable length and generates a code of fixed length.\n",
        "Automatic Garbage collection. PEP8->python style guide.Python interpretor->repl(read,evaluate,print,loop) environment, python script no repl.\n",
        "All data treated as objects.\"_\".join(words).\n",
        "multiline strings created with triple quotes. defaultdict->won't create a key error, gives a value for unavailable keys. Counter:\n",
        "a=Counter() a['a']->0, a['dog']->0. Python function specified by name alone so no function overloading.Non default args before default args. Positional before keyword args\\\n",
        "*args->non keyword.**kwargs. Dynamic scope->latest update considered. first class objects: An entity that can be dynamically created, destroyed, passed to a function,\n",
        "returned as a value, and have all the rights as other variables in the\n",
        "programming language have. First class citizens: Pass functions as arguments to other functions\n",
        "Return functions as the values from other functions\n",
        "Assign functions to variables or store them in data structures\n",
        "Creating an object:\n",
        "student1 = Student(\"julie\",\"cis\")\n",
        "student1.print_details()\n",
        "Student.print_details(student1) \n",
        "Magic methods: user defined classes act like built in types. No built-in main method. __name__ set to name of python script, set to __main__ by interpretor when executed.\n",
        "Iterators use memory efficiently compared to lists.->raise StopIteration, i=iter(k),i.__next__(),i.next(),next(i).\n",
        "generators->values computed one at a time, avoid storing large sequences in memory.Good for aggregations bad for individual inspections.Importlib->useful for reloading code from file\n",
        "Can't concatenate dicts\n",
        "\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 446
        },
        "outputId": "f17f54d2-2d51-4aa1-9904-a5555c9d4868"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "\n",
        "module2_sections = [\n",
        "  (\"Module 2 Lecture Notes\", module2_lecture_notes),\n",
        "]\n",
        "\n",
        "module2_markdown = format_module(2, \"Python\", module2_sections, module2_definitions)\n",
        "display(Markdown(module2_markdown))"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n Python is strongly typed which means that a variable has a type and that the type matters when performing operations on the variable. It is also dynamically typed which means that the type of a variable is determined only during runtime.Join is faster than loops->allocates memory upfront and the number of times memory is allocated is less. Useful for large inputs.Strong type example: def join(number:int, name:str='xyz')->str return name*number.\nDuck typing->doesn't check for types.n order for you to call len(obj), the only real constraint on obj is that it must define a .__len__() method. Otherwise, the object can be of types as different as str, listValid lists->[add,sub] where add and sub are predefined functions. A hash function takes a message of variable length and generates a code of fixed length.\nAutomatic Garbage collection. PEP8->python style guide.Python interpretor->repl(read,evaluate,print,loop) environment, python script no repl.\nAll data treated as objects.\"_\".join(words).\nmultiline strings created with triple quotes. defaultdict->won't create a key error, gives a value for unavailable keys. Counter:\na=Counter() a['a']->0, a['dog']->0. Python function specified by name alone so no function overloading.Non default args before default args. Positional before keyword args*args->non keyword.**kwargs. Dynamic scope->latest update considered. first class objects: An entity that can be dynamically created, destroyed, passed to a function,\nreturned as a value, and have all the rights as other variables in the\nprogramming language have. First class citizens: Pass functions as arguments to other functions\nReturn functions as the values from other functions\nAssign functions to variables or store them in data structures\nCreating an object:\nstudent1 = Student(\"julie\",\"cis\")\nstudent1.print_details()\nStudent.print_details(student1) \nMagic methods: user defined classes act like built in types. No built-in main method. __name__ set to name of python script, set to __main__ by interpretor when executed.\nIterators use memory efficiently compared to lists.->raise StopIteration, i=iter(k),i.__next__(),i.next(),next(i).\ngenerators->values computed one at a time, avoid storing large sequences in memory.Good for aggregations bad for individual inspections.Importlib->useful for reloading code from file\nCan't concatenate dicts\n\n\n \n\n## Module 2 Definitions\n* **Mutability** - your definition here\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "46MQLR-Gx8dZ"
      },
      "source": [
        "#Module 3 - Search Problems"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BN0b1eVYx-nd"
      },
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
        "chapter3_1 = \"\"\" Donal Knuth->infinite state space->factorial,sqrt \"\"\"\n",
        "chapter3_2 = \"\"\" Egocentric actions(relative to viewpoint of agent), absolute actions \"\"\"\n",
        "chapter3_3 = \"\"\" State space->set of all states, search tree->paths between the sates.Graph search more memory, checks for redundancy compared to tree search.\n",
        "size of state space graph |V|+|E|\n",
        "Best first search->uses an evaluation function to pop from frontier. \"\"\"\n",
        "chapter3_4 = \"\"\" BFS->agent has no clue how far away from the goal it is. For same action cost, bfs useful. Early goal test, checking as soon as it is popped. Unlike Best first search->late goal test.\n",
        "Space a bigger problem. Exponential complexity search problems can't be solved by US.\n",
        "Different action costs->best first search->evaluation function->cost from root to current node.Goal test when it expands not when it is generated.\n",
        "Uniform cost search->doesn't get caught in infinite paths. O(b^d) worse that BFS. When action costs are equal better than BFS\n",
        "DFS-> tree search, no reached, can get stuck in cycles,even lesser memory with backtracking->modifies the state instead of producing a new one. Keeps track of which successor to generate, not all successors are generated\n",
        "O(m).Depth limited search->l chosen based on knowledge of the problem, diameter of the state space graph.\n",
        "IDS->cutoff->there might be a sol at a deeper depth.No solution->O(b^m) else O(b^d). Worst case worse than BFS. Preferred when space is large , d is not known\n",
        "YOu can perform BFS, consume memory and then IDS with nodes on frontier\n",
        "Bidirectional search->simlutaneously searches forward from start state and backward from goal state.b^d/2+b^d/2 less than b^d \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" 8-tile puzzle->9! configurations. Vaccum world n*2n states with n cells.Open-loop approach->ignore percepts while performing the actions,closed-loop\n",
        "States,initial state, transition model, actions, goal,path cost(performance measure). Tree search vs graph search-> trees->no cycles, graph->no root\n",
        "Tree search->nodes generated through transition model.Different paths to the same state->distinct. Tree search can turn a linear problem to an exponential one. Repeated states. Solution use graph search->keep track of nodes visited.\n",
        "Must keep track of all states->uses a lot of memory.8 puzzle problem, 9!/2 states. US->all goals look the same unlike informed search. Search strategy->FIFO,LIFO\n",
        "Complete, optimal, space (no of nodes in memory at the same time)and time complexity(no of nodes generated). B->branching factor, m->max path length(infinite),d=shallowest goal path length.\n",
        "BFS->FIFO,shallowest node, yield->do not need to precompute all successors,node inserted into frontier only after checking if it is the goal.\n",
        "Complete,optimal(if cost=1),not optimal in general, space->O(b^d),time->1+b+b^2...O(b^d)\n",
        "DFS=>LIFO,complete->no(inifinite),optimal->no,time->O(b^m), if m is larger than d ->bad, good if it is dense,space->O(b*m).\n",
        "BFS->short paths, can quickly discard unlikely paths,infinte paths. DFS->fine tuned, space restrictions,many sol with longs paths, wrong can be discarded quickly\n",
        "Depth limited search, l<d->not complete, l>d: not optimal\n",
        "Iterative deepening search, nodes constructed(d(b)+(d-1)b^2...+1(b^d)->O(b^d)->time complexity),space->b*d,optimal(if cost =1),complete\n",
        "Informed search->uses domain specific information.\n",
        "Djikstras's shortest from node to every other node, UCS->shortest to goal node.\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",  \n",
        "\"state space\": \"a set of possible states that the environment can be in(represented using a graph,nodes->states,edges->actions\",\n",
        "\"path\":\"sequence of actions\",\n",
        "\"solution\":\"path from initial to final state\",\n",
        "\"search tree\":\"reperesents the paths that the search algorithm has explored\",\n",
        "\"state\":\"physical configuration\",\n",
        "\"node\":\"data structure representing part of a tree, contains parent, children, depth, g(x) path cost and depth\",\n",
        "\"uninformed search/blind search\":\"only have access to the problem definition\",\n",
        "\"frontier\":\"states that are available for expanding\"\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 916
        },
        "outputId": "b0096b52-7fc0-44bf-cb7e-52a64faa0365"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module3_sections = [\n",
        "  (\"AIMA Chapter 3.1 Problem-Solving Agents\", chapter3_1),\n",
        "  (\"AIMA Chapter 3.2 Example Problems\", chapter3_2),\n",
        "  (\"AIMA Chapter 3.3 Search Algorithms\", chapter3_3),\n",
        "  (\"AIMA Chapter 3.4 Uninformed Search Strategies\", chapter3_4),\n",
        "  (\"Module 3 Lecture Notes\", module3_lecture_notes),\n",
        "]\n",
        "\n",
        "module3_markdown = format_module(3, \"Search Problems\", module3_sections, module3_definitions)\n",
        "display(Markdown(module3_markdown))"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Donal Knuth->infinite state space->factorial,sqrt \n\n## AIMA Chapter 3.2 Example Problems\n Egocentric actions(relative to viewpoint of agent), absolute actions \n\n## AIMA Chapter 3.3 Search Algorithms\n State space->set of all states, search tree->paths between the sates.Graph search more memory, checks for redundancy compared to tree search.\nsize of state space graph |V|+|E|\nBest first search->uses an evaluation function to pop from frontier. \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n BFS->agent has no clue how far away from the goal it is. For same action cost, bfs useful. Early goal test, checking as soon as it is popped. Unlike Best first search->late goal test.\nSpace a bigger problem. Exponential complexity search problems can't be solved by US.\nDifferent action costs->best first search->evaluation function->cost from root to current node.Goal test when it expands not when it is generated.\nUniform cost search->doesn't get caught in infinite paths. O(b^d) worse that BFS. When action costs are equal better than BFS\nDFS-> tree search, no reached, can get stuck in cycles,even lesser memory with backtracking->modifies the state instead of producing a new one. Keeps track of which successor to generate, not all successors are generated\nO(m).Depth limited search->l chosen based on knowledge of the problem, diameter of the state space graph.\nIDS->cutoff->there might be a sol at a deeper depth.No solution->O(b^m) else O(b^d). Worst case worse than BFS. Preferred when space is large , d is not known\nYOu can perform BFS, consume memory and then IDS with nodes on frontier\nBidirectional search->simlutaneously searches forward from start state and backward from goal state.b^d/2+b^d/2 less than b^d \n\n## Module 3 Lecture Notes\n 8-tile puzzle->9! configurations. Vaccum world n*2n states with n cells.Open-loop approach->ignore percepts while performing the actions,closed-loop\nStates,initial state, transition model, actions, goal,path cost(performance measure). Tree search vs graph search-> trees->no cycles, graph->no root\nTree search->nodes generated through transition model.Different paths to the same state->distinct. Tree search can turn a linear problem to an exponential one. Repeated states. Solution use graph search->keep track of nodes visited.\nMust keep track of all states->uses a lot of memory.8 puzzle problem, 9!/2 states. US->all goals look the same unlike informed search. Search strategy->FIFO,LIFO\nComplete, optimal, space (no of nodes in memory at the same time)and time complexity(no of nodes generated). B->branching factor, m->max path length(infinite),d=shallowest goal path length.\nBFS->FIFO,shallowest node, yield->do not need to precompute all successors,node inserted into frontier only after checking if it is the goal.\nComplete,optimal(if cost=1),not optimal in general, space->O(b^d),time->1+b+b^2...O(b^d)\nDFS=>LIFO,complete->no(inifinite),optimal->no,time->O(b^m), if m is larger than d ->bad, good if it is dense,space->O(b*m).\nBFS->short paths, can quickly discard unlikely paths,infinte paths. DFS->fine tuned, space restrictions,many sol with longs paths, wrong can be discarded quickly\nDepth limited search, l<d->not complete, l>d: not optimal\nIterative deepening search, nodes constructed(d(b)+(d-1)b^2...+1(b^d)->O(b^d)->time complexity),space->b*d,optimal(if cost =1),complete\nInformed search->uses domain specific information.\nDjikstras's shortest from node to every other node, UCS->shortest to goal node.\n\n \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **State space** - a set of possible states that the environment can be in(represented using a graph,nodes->states,edges->actions\n* **Path** - sequence of actions\n* **Solution** - path from initial to final state\n* **Search tree** - reperesents the paths that the search algorithm has explored\n* **State** - physical configuration\n* **Node** - data structure representing part of a tree, contains parent, children, depth, g(x) path cost and depth\n* **Uninformed search/blind search** - only have access to the problem definition\n* **Frontier** - states that are available for expanding\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 = \"\"\" IS more efficient that US. Uses domain specific hints(heuristics).GBFS->O(|V|) more efficent on some problems O(bm)\n",
        "G(n) curves monotonic, cost increases down the path.\n",
        "A*->surely expanded nodes->f(n)<C*,(cost of optimal soln path),goal conturs might expand f(n)=C*. will not expand f(n)>C*.\n",
        "Nodes that need to be expanded might be exponential. Super powerful vacuum which doesn't need to move. n dirty squares means 2^n states \n",
        "Weighted A*->suboptimal. Beam search->keep k nodes with best f score. Not complete not optimal.\n",
        "IDS A*search ->uses fcost as the cutoff.\"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" UCS->uses g(n)->path cost. Best first search->f(n) replaces g(n).f(n)=h(n)\n",
        "Romanian map->manhattan distance->abs(a.x-b.x)+abs(a.y-b.y). Not optimal. not complete->can get stuck in loops\n",
        "heuristic is admissiable if it never overestimates the cost to reach the goal. Inadmissable heuristics break optimality by trapping good plans\n",
        "A*->we expand the goal node. Frontier contains same node if it has better cost. f(n)=g(n)+h(n). space: O(b^d).Average number of nodes expanded much lesser compared to IDs.\n",
        "UCS expands equally in all directins. A* expands towards the goal.\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"Heuristic function\" : \"estimated distance from current to goal\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 443
        },
        "cellView": "form",
        "outputId": "73714d3f-cb59-457b-e3e9-fa8eff02bf66"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module4_sections = [\n",
        "  (\"AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\", chapter3_5),\n",
        "  (\"AIMA Chapter 3.6 Heuristic Functions\", chapter3_6),\n",
        "  (\"Module 4 Lecture Notes\", module4_lecture_notes),\n",
        "]\n",
        "\n",
        "module4_markdown = format_module(4, \"Informed Search\", \n",
        "                         module4_sections, \n",
        "                         module4_definitions)\n",
        "display(Markdown(module4_markdown))"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n IS more efficient that US. Uses domain specific hints(heuristics).GBFS->O(|V|) more efficent on some problems O(bm)\nG(n) curves monotonic, cost increases down the path.\nA*->surely expanded nodes->f(n)<C*,(cost of optimal soln path),goal conturs might expand f(n)=C*. will not expand f(n)>C*.\nNodes that need to be expanded might be exponential. Super powerful vacuum which doesn't need to move. n dirty squares means 2^n states \nWeighted A*->suboptimal. Beam search->keep k nodes with best f score. Not complete not optimal.\nIDS A*search ->uses fcost as the cutoff.\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n UCS->uses g(n)->path cost. Best first search->f(n) replaces g(n).f(n)=h(n)\nRomanian map->manhattan distance->abs(a.x-b.x)+abs(a.y-b.y). Not optimal. not complete->can get stuck in loops\nheuristic is admissiable if it never overestimates the cost to reach the goal. Inadmissable heuristics break optimality by trapping good plans\nA*->we expand the goal node. Frontier contains same node if it has better cost. f(n)=g(n)+h(n). space: O(b^d).Average number of nodes expanded much lesser compared to IDs.\nUCS expands equally in all directins. A* expands towards the goal.\n\n\n## Module 4 Definitions\n* **Heuristic function** - estimated distance from current 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 = \"\"\" Game tree->node is board positions, edges->legal moves.\n",
        "Even levels->max. Evaluation func->scores to boards without reference to path.\n",
        "Alpha-->max's current lower bound,Beta->min's current upper bound on min's outcome.Max won't allow a move worse than alpha.Stop ecvaluating max node when v>=beta.\n",
        "v<= alpha for min node. (beta<= alpha).\n",
        "Expectimax->average score under optimal play->not optimal.maginitues of evaluatin functions matter, no pruning. Extend to multiplayer->vector of values and utilities. Space problem\n",
        "alphabeta pruning depends on order.\n",
        "In game tree search, repeated states can occur because of transpositions—different Transposition\n",
        "permutations of the move sequence that end up in the same position, and the problem can be\n",
        "addressed with a transposition table that caches the heuristic value of states.\n",
        "Type A strategy considers all possible moves to a certain depth in the search tree, and then Type A strategy\n",
        "uses a heuristic evaluation function to estimate the utility of states at that depth. It explores\n",
        "a wide but shallow portion of the tree. A Type B strategy ignores moves that look bad, and Type B strategy\n",
        "follows promising lines “as far as possible.” It explores a deep but narrow portion of the tree.\n",
        "Go->type B as branching factor is more.\n",
        "forward pruning prunes moves that appear to be poor moves, but might possibly be good Forward pruning\n",
        "ones.->might have errors.\n",
        "\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 809
        },
        "outputId": "8a371050-1d39-4391-80ba-d0cdcc4afb34"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module5_sections = [\n",
        "  (\"AIMA Chapter 5.1 Game Theory\", chapter5_1),\n",
        "  (\"AIMA Chapter 5.2 Optimal Decisions in Games\", chapter5_2),\n",
        "  (\"AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\", chapter5_3),\n",
        "  (\"AIMA Chapter 5.5 Stochastic Games\", chapter5_5),\n",
        "  (\"AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\", chapter16_1),\n",
        "  (\"AIMA Chapter 16.2 The Basis of Utility Theory\", chapter16_2),\n",
        "  (\"AIMA Chapter 16.3 Utility Functions\", chapter16_3),\n",
        "  (\"Module 5 Lecture Notes\", module5_lecture_notes),\n",
        "]\n",
        "\n",
        "module5_markdown = format_module(5, \"Adversarial Search and Games\", \n",
        "                         module5_sections, \n",
        "                         module5_definitions)\n",
        "display(Markdown(module5_markdown))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n Game tree->node is board positions, edges->legal moves.\nEven levels->max. Evaluation func->scores to boards without reference to path.\nAlpha-->max's current lower bound,Beta->min's current upper bound on min's outcome.Max won't allow a move worse than alpha.Stop ecvaluating max node when v>=beta.\nv<= alpha for min node. (beta<= alpha).\nExpectimax->average score under optimal play->not optimal.maginitues of evaluatin functions matter, no pruning. Extend to multiplayer->vector of values and utilities. Space problem\nalphabeta pruning depends on order.\nIn game tree search, repeated states can occur because of transpositions—different Transposition\npermutations of the move sequence that end up in the same position, and the problem can be\naddressed with a transposition table that caches the heuristic value of states.\nType A strategy considers all possible moves to a certain depth in the search tree, and then Type A strategy\nuses a heuristic evaluation function to estimate the utility of states at that depth. It explores\na wide but shallow portion of the tree. A Type B strategy ignores moves that look bad, and Type B strategy\nfollows promising lines “as far as possible.” It explores a deep but narrow portion of the tree.\nGo->type B as branching factor is more.\nforward pruning prunes moves that appear to be poor moves, but might possibly be good Forward pruning\nones.->might have errors.\n\n\n\n## Module 5 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qVSQhTVSyYYO"
      },
      "source": [
        "#Module 6 - \"Constraint Satisfaction Problems\""
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wm4mfW82yaRH"
      },
      "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 = \"\"\" General purpose algo with no changes from problem to problem. Specify problem in a declarative language\n",
        "CSP's maximise objective function.COnstraint graph->nodes are variables, arcs are constraints.DOmain size O(d^n)with n variables\n",
        "discrete->finite,infinite->daus,job scheduling, continous->time\n",
        "Higher order constraints->3 or more variables. Preference-, DFS\n",
        "n variables with domain size d. B=n*d,(n-1)*(d). Tree has n!*d^n leaves\n",
        "Variable assignments commutative, need to check assignments for a single variable . b=d and d^n leaves\n",
        "Forward checking propagates values from assigned to unassigned.\n",
        "Constraint propagation->enforces constraints locally\n",
        "WOrst case: O(d^2)\n",
        "AC3:\n",
        "All nodes can be connected to every other node. 2*n*(n-1) i.e O(n^2)\n",
        "arc ->queue d times. D values, checking an arc O(d^2)\n",
        "worst case: O(n^ d^3)\n",
        "Towards AC3:\n",
        "1)At each iteration, we only need to examine those Xi\n",
        "where at least one neighbor of Xi has lost a value in the\n",
        "previous iteration.\n",
        "2. If Xi loses a value only because of arc inconsistencies\n",
        "with Yj\n",
        ", we don’t need to check Yj on the next iteration.\n",
        "3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only\n",
        "need to check that (j,i) is still arc-consistent.\n",
        "A CSP is k-\n",
        "consistent if, for any set of k−1 variables and for any consistent assignment to those variables,\n",
        "a consistent value can always be assigned to any kth variable.\n",
        "A CSP is strongly k-consistent if it is k-consistent and is also (k−1)-consistent, (k−2)- consistent, ... all the way down to 1-consistent.\n",
        "NP-complete->time might be exponential so can space.\n",
        " \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 741
        },
        "outputId": "8629bf6c-abea-49b2-af11-ce2982919e97"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module6_sections = [\n",
        "  (\"AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\", chapter6_1),\n",
        "  (\"AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\", chapter6_2),\n",
        "  (\"AIMA Chapter 6.3 Backtracking Search for CSPs\", chapter6_3),\n",
        "  (\"AIMA Chapter 6.4 Local Search for CSPs\", chapter6_4),\n",
        "  (\"AIMA Chapter 6.5 The Structure of Problems\", chapter6_5),\n",
        "  (\"Module 6 Lecture Notes\", module6_lecture_notes),\n",
        "]\n",
        "\n",
        "module6_markdown = format_module(6, \"Constraint Satisfaction Problems\", \n",
        "                         module6_sections, \n",
        "                         module6_definitions)\n",
        "display(Markdown(module6_markdown))"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n General purpose algo with no changes from problem to problem. Specify problem in a declarative language\nCSP's maximise objective function.COnstraint graph->nodes are variables, arcs are constraints.DOmain size O(d^n)with n variables\ndiscrete->finite,infinite->daus,job scheduling, continous->time\nHigher order constraints->3 or more variables. Preference-, DFS\nn variables with domain size d. B=n*d,(n-1)*(d). Tree has n!*d^n leaves\nVariable assignments commutative, need to check assignments for a single variable . b=d and d^n leaves\nForward checking propagates values from assigned to unassigned.\nConstraint propagation->enforces constraints locally\nWOrst case: O(d^2)\nAC3:\nAll nodes can be connected to every other node. 2*n*(n-1) i.e O(n^2)\narc ->queue d times. D values, checking an arc O(d^2)\nworst case: O(n^ d^3)\nTowards AC3:\n1)At each iteration, we only need to examine those Xi\nwhere at least one neighbor of Xi has lost a value in the\nprevious iteration.\n2. If Xi loses a value only because of arc inconsistencies\nwith Yj\n, we don’t need to check Yj on the next iteration.\n3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only\nneed to check that (j,i) is still arc-consistent.\nA CSP is k-\nconsistent if, for any set of k−1 variables and for any consistent assignment to those variables,\na consistent value can always be assigned to any kth variable.\nA CSP is strongly k-consistent if it is k-consistent and is also (k−1)-consistent, (k−2)- consistent, ... all the way down to 1-consistent.\nNP-complete->time might be exponential so can space.\n \n\n## Module 6 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" A KB consists of sentences which are assertions about the world. an agent consists of a KB which might contain background knowledge.\n",
        "Agents tells what it has perceived, asks KB about actions, tells KB about action and returns action so that it can be executed.\n",
        "Declarative approach, tell KB one by one(sentences) until the agent knows how to operate.the procedural approach encodes desired behaviors directly\n",
        "as program code.\n",
        " \"\"\"\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 = \"\"\"Forward Chaining is a kind of data-driven reasoning. An agent can start with known\n",
        "data, adding premises as new percepts come in, and then incrementally apply the\n",
        "forward chaining algorithm to derive new conclusions. It doesn’t have to have a\n",
        "specific query in mind to do so.\n",
        "Backward chaining works backwards from a query. If the query is known to be true,\n",
        "then no work is needed. Otherwise, the algorithm finds implications in the KB whose\n",
        "conclusions is the query. If all the premises of one of those can be proved to be true\n",
        "(via backward chaining), then the query is true.\n",
        "Definite clause – disjunction of literals where exactly one is positive\n",
        "• Horn clause – disjunction of literals where at most one is positive\n",
        "• This includes definite clauses\n",
        "• And clauses with no positive literals\n",
        "Horn clauses are closed under resolution. If you apply resolution to a horn clause, you\n",
        "get back a horn clause. \n",
        "Logic can serve as a general class of representations for knowledge-based agents.  M(alpha) to mean the set of all models of alpha.\n",
        "a⊨β if and only if M(a) ⊆ M(β). a is stronger,more specific.\n",
        "Possible Worlds is the process of\n",
        "enumerating all Possible Worlds that are\n",
        "compatible with the KB. M(KB) ⊆ M(alpha1 )\n",
        "Sound: should only derive entailed sentences. Complete-should derive all sentences that are entailed.\n",
        "Rules:\n",
        "(alpha ⟹ β) ≡ (¬β ⟹ ¬alpha) Contraposition\n",
        "(alpha ⟹ β) ≡ (¬a ⋁ β) Implication elimination\n",
        "(a ⇔ β) ≡ ((a ⟹ β) ⋀ (β ⟹a)) Biconditional elimination\n",
        "¬(a ⋀ β) ≡ (¬a ⋁ ¬β) De Morgan\n",
        "¬(a ⋁ β) ≡ (¬a ⋀ ¬β) De Morgan\n",
        "((a ⋀ β) ⋁ ɣ) ≡ ((a ⋀ β) ⋁ (a ⋀ ɣ))) Distributivity of ⋀ over ⋁\n",
        "((a ⋁ β) ⋀ ɣ) ≡ ((a ⋁ β) ⋀ (a ⋁ ɣ))) Distributivity of ⋁ over ⋀\n",
        "If ℓi and m are complementary literals,\n",
        "which means that one is the negation of\n",
        "another, then we can eliminate them via\n",
        "unit resolution.\n",
        "CNF->distribute ⋁ over ⋀ wherever possible\n",
        "Every definite clause can be written as an implication whose premise is a\n",
        "conjunction of positive literals whose conclusion is a positive literal.\n",
        "¬ L1,1 ⋁ ¬ Breeze ⋁ B1,1 can be written as the implication L1,1 ⋀ Breeze ⟹ B1,1 \n",
        "Forward and backward chaining algorithm->inference with horn class\n",
        "deciding entailment with Horn class can be done in linear time wrt KB.\n",
        "Inference procedures based on resolution work using the principle of proof by\n",
        "contradiction.\n",
        "To show KB⊨a then we can show that KB ⋀ ¬a is unsatisfiable.\n",
        "continue until->1)There are no new clauses that can be added. In this case, the KB does not entail a\n",
        "2. Two clauses resolve to yield the empty clause, in which case the KB does entail a\n",
        "\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"knowledge based agents\" : \"use reasoning over an internal representation of knowledge to decide what actions to take\",\n",
        "\n",
        "}\n",
        "\n"
      ],
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 860
        },
        "outputId": "627b1537-bd71-43d7-e014-be8cce3005da"
      },
      "source": [
        "#@title Preview of your summary\n",
        "#@markdown You don't need to modify anything in this cell. Just press play.\n",
        "module7_sections = [\n",
        "  (\"AIMA Chapter 7.1 Knowledge-Based Agents\", chapter7_1),\n",
        "  (\"AIMA Chapter 7.2 The Wumpus World\", chapter7_2),\n",
        "  (\"AIMA Chapter 7.3 Logic\", chapter7_3),\n",
        "  (\"AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\", chapter7_4),\n",
        "  (\"AIMA 7.5 Propositional Theorem Proving\", chapter7_5),\n",
        "  (\"Module 7 Lecture Notes\", module7_lecture_notes),\n",
        "]\n",
        "\n",
        "module7_markdown = format_module(7, \"Logical Agents\", \n",
        "                         module7_sections, \n",
        "                         module7_definitions)\n",
        "display(Markdown(module7_markdown))"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n A KB consists of sentences which are assertions about the world. an agent consists of a KB which might contain background knowledge.\nAgents tells what it has perceived, asks KB about actions, tells KB about action and returns action so that it can be executed.\nDeclarative approach, tell KB one by one(sentences) until the agent knows how to operate.the procedural approach encodes desired behaviors directly\nas program code.\n \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\nForward Chaining is a kind of data-driven reasoning. An agent can start with known\ndata, adding premises as new percepts come in, and then incrementally apply the\nforward chaining algorithm to derive new conclusions. It doesn’t have to have a\nspecific query in mind to do so.\nBackward chaining works backwards from a query. If the query is known to be true,\nthen no work is needed. Otherwise, the algorithm finds implications in the KB whose\nconclusions is the query. If all the premises of one of those can be proved to be true\n(via backward chaining), then the query is true.\nDefinite clause – disjunction of literals where exactly one is positive\n• Horn clause – disjunction of literals where at most one is positive\n• This includes definite clauses\n• And clauses with no positive literals\nHorn clauses are closed under resolution. If you apply resolution to a horn clause, you\nget back a horn clause. \nLogic can serve as a general class of representations for knowledge-based agents.  M(alpha) to mean the set of all models of alpha.\na⊨β if and only if M(a) ⊆ M(β). a is stronger,more specific.\nPossible Worlds is the process of\nenumerating all Possible Worlds that are\ncompatible with the KB. M(KB) ⊆ M(alpha1 )\nSound: should only derive entailed sentences. Complete-should derive all sentences that are entailed.\nRules:\n(alpha ⟹ β) ≡ (¬β ⟹ ¬alpha) Contraposition\n(alpha ⟹ β) ≡ (¬a ⋁ β) Implication elimination\n(a ⇔ β) ≡ ((a ⟹ β) ⋀ (β ⟹a)) Biconditional elimination\n¬(a ⋀ β) ≡ (¬a ⋁ ¬β) De Morgan\n¬(a ⋁ β) ≡ (¬a ⋀ ¬β) De Morgan\n((a ⋀ β) ⋁ ɣ) ≡ ((a ⋀ β) ⋁ (a ⋀ ɣ))) Distributivity of ⋀ over ⋁\n((a ⋁ β) ⋀ ɣ) ≡ ((a ⋁ β) ⋀ (a ⋁ ɣ))) Distributivity of ⋁ over ⋀\nIf ℓi and m are complementary literals,\nwhich means that one is the negation of\nanother, then we can eliminate them via\nunit resolution.\nCNF->distribute ⋁ over ⋀ wherever possible\nEvery definite clause can be written as an implication whose premise is a\nconjunction of positive literals whose conclusion is a positive literal.\n¬ L1,1 ⋁ ¬ Breeze ⋁ B1,1 can be written as the implication L1,1 ⋀ Breeze ⟹ B1,1 \nForward and backward chaining algorithm->inference with horn class\ndeciding entailment with Horn class can be done in linear time wrt KB.\nInference procedures based on resolution work using the principle of proof by\ncontradiction.\nTo show KB⊨a then we can show that KB ⋀ ¬a is unsatisfiable.\ncontinue until->1)There are no new clauses that can be added. In this case, the KB does not entail a\n2. Two clauses resolve to yield the empty clause, in which case the KB does entail a\n\n\n \n\n## Module 7 Definitions\n* **Knowledge based agents** - use reasoning over an internal representation of knowledge to decide what actions to take\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": "add94f86-c983-4354-b516-9b5952e9a127"
      },
      "source": [
        "# This will generate the full set of notes that you can use for your exam.\n",
        "full_markdown = \"\\n\\n\".join([module1_markdown, \n",
        "                             module2_markdown, \n",
        "                             module3_markdown, \n",
        "                             module4_markdown, \n",
        "                             module5_markdown,\n",
        "                             module6_markdown,\n",
        "                             module7_markdown,]\n",
        "                       )\n",
        "display(Markdown(full_markdown))"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\nAI->Science of making machines act rationally. think,act like people, think,act rationally. If AI->behaves irrationally, it is because of the objectives that were fed in. For example, if the sole purpose of the AI is to win chess, then it might hypnotize, bribe the opponent,etc.If something is wrong with the objectives, initially we used to reset but now it will have bad consequences. More Intelligence->worse consequences. Machines should satisfy our objectives not theirs. Uncertainity makes a machine act more cautiously.perfect rationallity->impossible. Doing the right thing->based on objective->minimize loss functionThinking rationally->laws of thought->correct inference\n\n## AIMA Chapter 27.1 The Limits of AI\n Weak AI->machines act as if they are intelligent. Strong AI,human AI, general AI->Machines actually consciously think.Human behaviour too complex to be fit into formal rules. GOFAI(only rules) this has eclipsed. Qualification problem->difficulty to capture every behaviour into a set of rules. Embodied cognition approach, brain is not seperate, vision, robotics, etc become central rather than peripheralTuring machines -> infinite, computers->finite. Godel's incompleteness theorem.Humans change their minds, so do computers->upgrade hardware.Turing test->program has a conversation with an interrrogator who has to guess whether it is a computer or not. Computer has to fool I 30% of the time\n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Can machines think->Djikstra->not a relevant question. Turing->yes everyone can think(flights can fly, submarines can swim).Rejected by Searle. Chinese room->human no understanding of Chinese, passed a stack of papers, rulebook in english, papers in chinese. Translate and send it back. Using the responses the system responds in chinese. Stacks of paper doesn't know chinese, human doesn't understand chinese.Therefore computers do not generate understanding.(Chinese room does the same as a computer). Biological naturalism. Critics->Humans made of cells, cell have no understanding hence humans don't either. Qualia-> subjective experience. Do machines feel sympathy? Humans have an advantage here. Want to know how it feels like to eat ice cream, you can actually go eat an ice-cream.\n\n## AIMA 2.1 Agents and Environments\n Your summary here \n\n## AIMA 2.2 Good Behavior: The Concept of Rationality\n Your summary here \n\n## AIMA 2.3 The Nature of Environments\n PEAS(performance,environment,Actuators,sensors).Task environment->problem, agent->solution. Eglish tutor:P->studen't score on test,E->students,staff,A->display feedback,S->keyboard,voiceTask environment->lack of sensor data,noise->partially observable. No sensors->unobservably. Observable fully->no need to maintain internal state.single/multiagent->competitive, partially cooperative.Deterministic/non-deterministic->you know next state, when performing an action with current state.Stochastic->probability assosciated with it. Episodic/sequential->defective parts/chess,taxi driving(long term consequences)Static/dynamic->static->agent doesn't need to look at the world when making decisions. Semidynamic->chess when played with a clock.\nTaxi driving->dynamic, crossword->staticdiscrete/continuous->states,\nknown/unknown->outcomes known or you need to learn. Known+partially observable->solitaire->rules known, cards unknown. unknown+fully observable->video game, seen but don't know what to press \n\n## AIMA 2.4 The Structure of Agents\n Vacuum world, simple reflexive agent. Partially observable->maintain internal state->changing lanes,see where other cars are. Condition-action sequencemodel based agents->transition model->how the next state depends on current state and action, sensor model->what happens when agents performs an actionAtomic representation, factored representation,structured representation(objects and their relationships described). concise, more expressive.localist->one to one mapping between concept and representation.Distributed representation.Learning based agent->learning element_>makes improvement,performance element->selects actions, problem generator->new experiences\n\n## Module 1 Lecture Notes\n Descartes->principle of dualism, mind is seperate from the body. Cutting of limbs, etc doesn't affect the brain.How do you know you are not an automaton->they can't properly use language.Turing test, chinese room. Eliza->early NLP program.Daniel->Brain in A vat experiment: Brain hooked up to a computer program. How do you know what you perceive?Human agents->actuators->legs,hand,sensors->eyes,ears.Robot->actuators->motors. Sensors->camera\\.Software agent->actuators->send files,sensors->keyboard,mouse(human input)\nAgent behaviour defined by Agent function: f:P->a that maps percepts to action. The agent program runs on the physical architecture to produce f. Agent->architecture+programratinality->information gathering, exploration \n\n## Module 1 Definitions\n* **Value alignment problem** - problem of achieving an agreement with our true preferences and objectives we design for the machine\n* **Biological naturalism** - Mental states are caused by the low level processes from neurons.\n* **Agent** - An agent is anything that perceives its environment through sensors and can act on its environment through actuators\n* **Percept** - the agent’s perceptual inputs at any given instance.\n* **Percept sequence** - history of percepts \n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Python is strongly typed which means that a variable has a type and that the type matters when performing operations on the variable. It is also dynamically typed which means that the type of a variable is determined only during runtime.Join is faster than loops->allocates memory upfront and the number of times memory is allocated is less. Useful for large inputs.Strong type example: def join(number:int, name:str='xyz')->str return name*number.\nDuck typing->doesn't check for types.n order for you to call len(obj), the only real constraint on obj is that it must define a .__len__() method. Otherwise, the object can be of types as different as str, listValid lists->[add,sub] where add and sub are predefined functions. A hash function takes a message of variable length and generates a code of fixed length.\nAutomatic Garbage collection. PEP8->python style guide.Python interpretor->repl(read,evaluate,print,loop) environment, python script no repl.\nAll data treated as objects.\"_\".join(words).\nmultiline strings created with triple quotes. defaultdict->won't create a key error, gives a value for unavailable keys. Counter:\na=Counter() a['a']->0, a['dog']->0. Python function specified by name alone so no function overloading.Non default args before default args. Positional before keyword args*args->non keyword.**kwargs. Dynamic scope->latest update considered. first class objects: An entity that can be dynamically created, destroyed, passed to a function,\nreturned as a value, and have all the rights as other variables in the\nprogramming language have. First class citizens: Pass functions as arguments to other functions\nReturn functions as the values from other functions\nAssign functions to variables or store them in data structures\nCreating an object:\nstudent1 = Student(\"julie\",\"cis\")\nstudent1.print_details()\nStudent.print_details(student1) \nMagic methods: user defined classes act like built in types. No built-in main method. __name__ set to name of python script, set to __main__ by interpretor when executed.\nIterators use memory efficiently compared to lists.->raise StopIteration, i=iter(k),i.__next__(),i.next(),next(i).\ngenerators->values computed one at a time, avoid storing large sequences in memory.Good for aggregations bad for individual inspections.Importlib->useful for reloading code from file\nCan't concatenate dicts\n\n\n \n\n## Module 2 Definitions\n* **Mutability** - your definition here\n\n\n# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n Donal Knuth->infinite state space->factorial,sqrt \n\n## AIMA Chapter 3.2 Example Problems\n Egocentric actions(relative to viewpoint of agent), absolute actions \n\n## AIMA Chapter 3.3 Search Algorithms\n State space->set of all states, search tree->paths between the sates.Graph search more memory, checks for redundancy compared to tree search.\nsize of state space graph |V|+|E|\nBest first search->uses an evaluation function to pop from frontier. \n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n BFS->agent has no clue how far away from the goal it is. For same action cost, bfs useful. Early goal test, checking as soon as it is popped. Unlike Best first search->late goal test.\nSpace a bigger problem. Exponential complexity search problems can't be solved by US.\nDifferent action costs->best first search->evaluation function->cost from root to current node.Goal test when it expands not when it is generated.\nUniform cost search->doesn't get caught in infinite paths. O(b^d) worse that BFS. When action costs are equal better than BFS\nDFS-> tree search, no reached, can get stuck in cycles,even lesser memory with backtracking->modifies the state instead of producing a new one. Keeps track of which successor to generate, not all successors are generated\nO(m).Depth limited search->l chosen based on knowledge of the problem, diameter of the state space graph.\nIDS->cutoff->there might be a sol at a deeper depth.No solution->O(b^m) else O(b^d). Worst case worse than BFS. Preferred when space is large , d is not known\nYOu can perform BFS, consume memory and then IDS with nodes on frontier\nBidirectional search->simlutaneously searches forward from start state and backward from goal state.b^d/2+b^d/2 less than b^d \n\n## Module 3 Lecture Notes\n 8-tile puzzle->9! configurations. Vaccum world n*2n states with n cells.Open-loop approach->ignore percepts while performing the actions,closed-loop\nStates,initial state, transition model, actions, goal,path cost(performance measure). Tree search vs graph search-> trees->no cycles, graph->no root\nTree search->nodes generated through transition model.Different paths to the same state->distinct. Tree search can turn a linear problem to an exponential one. Repeated states. Solution use graph search->keep track of nodes visited.\nMust keep track of all states->uses a lot of memory.8 puzzle problem, 9!/2 states. US->all goals look the same unlike informed search. Search strategy->FIFO,LIFO\nComplete, optimal, space (no of nodes in memory at the same time)and time complexity(no of nodes generated). B->branching factor, m->max path length(infinite),d=shallowest goal path length.\nBFS->FIFO,shallowest node, yield->do not need to precompute all successors,node inserted into frontier only after checking if it is the goal.\nComplete,optimal(if cost=1),not optimal in general, space->O(b^d),time->1+b+b^2...O(b^d)\nDFS=>LIFO,complete->no(inifinite),optimal->no,time->O(b^m), if m is larger than d ->bad, good if it is dense,space->O(b*m).\nBFS->short paths, can quickly discard unlikely paths,infinte paths. DFS->fine tuned, space restrictions,many sol with longs paths, wrong can be discarded quickly\nDepth limited search, l<d->not complete, l>d: not optimal\nIterative deepening search, nodes constructed(d(b)+(d-1)b^2...+1(b^d)->O(b^d)->time complexity),space->b*d,optimal(if cost =1),complete\nInformed search->uses domain specific information.\nDjikstras's shortest from node to every other node, UCS->shortest to goal node.\n\n \n\n## Module 3 Definitions\n* **Problem-solving agent** - an agent that can formulate a plan via search\n* **State space** - a set of possible states that the environment can be in(represented using a graph,nodes->states,edges->actions\n* **Path** - sequence of actions\n* **Solution** - path from initial to final state\n* **Search tree** - reperesents the paths that the search algorithm has explored\n* **State** - physical configuration\n* **Node** - data structure representing part of a tree, contains parent, children, depth, g(x) path cost and depth\n* **Uninformed search/blind search** - only have access to the problem definition\n* **Frontier** - states that are available for expanding\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n IS more efficient that US. Uses domain specific hints(heuristics).GBFS->O(|V|) more efficent on some problems O(bm)\nG(n) curves monotonic, cost increases down the path.\nA*->surely expanded nodes->f(n)<C*,(cost of optimal soln path),goal conturs might expand f(n)=C*. will not expand f(n)>C*.\nNodes that need to be expanded might be exponential. Super powerful vacuum which doesn't need to move. n dirty squares means 2^n states \nWeighted A*->suboptimal. Beam search->keep k nodes with best f score. Not complete not optimal.\nIDS A*search ->uses fcost as the cutoff.\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n UCS->uses g(n)->path cost. Best first search->f(n) replaces g(n).f(n)=h(n)\nRomanian map->manhattan distance->abs(a.x-b.x)+abs(a.y-b.y). Not optimal. not complete->can get stuck in loops\nheuristic is admissiable if it never overestimates the cost to reach the goal. Inadmissable heuristics break optimality by trapping good plans\nA*->we expand the goal node. Frontier contains same node if it has better cost. f(n)=g(n)+h(n). space: O(b^d).Average number of nodes expanded much lesser compared to IDs.\nUCS expands equally in all directins. A* expands towards the goal.\n\n\n## Module 4 Definitions\n* **Heuristic function** - estimated distance from current to goal\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n Your summary here \n\n## AIMA Chapter 5.2 Optimal Decisions in Games\n Your summary here \n\n## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n Your summary here \n\n## AIMA Chapter 5.5 Stochastic Games\n Your summary here \n\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n Your summary here \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## Module 5 Lecture Notes\n Game tree->node is board positions, edges->legal moves.\nEven levels->max. Evaluation func->scores to boards without reference to path.\nAlpha-->max's current lower bound,Beta->min's current upper bound on min's outcome.Max won't allow a move worse than alpha.Stop ecvaluating max node when v>=beta.\nv<= alpha for min node. (beta<= alpha).\nExpectimax->average score under optimal play->not optimal.maginitues of evaluatin functions matter, no pruning. Extend to multiplayer->vector of values and utilities. Space problem\nalphabeta pruning depends on order.\nIn game tree search, repeated states can occur because of transpositions—different Transposition\npermutations of the move sequence that end up in the same position, and the problem can be\naddressed with a transposition table that caches the heuristic value of states.\nType A strategy considers all possible moves to a certain depth in the search tree, and then Type A strategy\nuses a heuristic evaluation function to estimate the utility of states at that depth. It explores\na wide but shallow portion of the tree. A Type B strategy ignores moves that look bad, and Type B strategy\nfollows promising lines “as far as possible.” It explores a deep but narrow portion of the tree.\nGo->type B as branching factor is more.\nforward pruning prunes moves that appear to be poor moves, but might possibly be good Forward pruning\nones.->might have errors.\n\n\n\n## Module 5 Definitions\n* **Concept** - definition\n\n\n# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n Your summary here \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n Your summary here \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.4 Local Search for CSPs\n Your summary here \n\n## AIMA Chapter 6.5 The Structure of Problems\n Your summary here \n\n## Module 6 Lecture Notes\n General purpose algo with no changes from problem to problem. Specify problem in a declarative language\nCSP's maximise objective function.COnstraint graph->nodes are variables, arcs are constraints.DOmain size O(d^n)with n variables\ndiscrete->finite,infinite->daus,job scheduling, continous->time\nHigher order constraints->3 or more variables. Preference-, DFS\nn variables with domain size d. B=n*d,(n-1)*(d). Tree has n!*d^n leaves\nVariable assignments commutative, need to check assignments for a single variable . b=d and d^n leaves\nForward checking propagates values from assigned to unassigned.\nConstraint propagation->enforces constraints locally\nWOrst case: O(d^2)\nAC3:\nAll nodes can be connected to every other node. 2*n*(n-1) i.e O(n^2)\narc ->queue d times. D values, checking an arc O(d^2)\nworst case: O(n^ d^3)\nTowards AC3:\n1)At each iteration, we only need to examine those Xi\nwhere at least one neighbor of Xi has lost a value in the\nprevious iteration.\n2. If Xi loses a value only because of arc inconsistencies\nwith Yj\n, we don’t need to check Yj on the next iteration.\n3. Removing a value on Xi can only make Yj arcinconsistent with respect to Xi itself. Thus, we only\nneed to check that (j,i) is still arc-consistent.\nA CSP is k-\nconsistent if, for any set of k−1 variables and for any consistent assignment to those variables,\na consistent value can always be assigned to any kth variable.\nA CSP is strongly k-consistent if it is k-consistent and is also (k−1)-consistent, (k−2)- consistent, ... all the way down to 1-consistent.\nNP-complete->time might be exponential so can space.\n \n\n## Module 6 Definitions\n* **Concept** - definition\n\n\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n A KB consists of sentences which are assertions about the world. an agent consists of a KB which might contain background knowledge.\nAgents tells what it has perceived, asks KB about actions, tells KB about action and returns action so that it can be executed.\nDeclarative approach, tell KB one by one(sentences) until the agent knows how to operate.the procedural approach encodes desired behaviors directly\nas program code.\n \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\nForward Chaining is a kind of data-driven reasoning. An agent can start with known\ndata, adding premises as new percepts come in, and then incrementally apply the\nforward chaining algorithm to derive new conclusions. It doesn’t have to have a\nspecific query in mind to do so.\nBackward chaining works backwards from a query. If the query is known to be true,\nthen no work is needed. Otherwise, the algorithm finds implications in the KB whose\nconclusions is the query. If all the premises of one of those can be proved to be true\n(via backward chaining), then the query is true.\nDefinite clause – disjunction of literals where exactly one is positive\n• Horn clause – disjunction of literals where at most one is positive\n• This includes definite clauses\n• And clauses with no positive literals\nHorn clauses are closed under resolution. If you apply resolution to a horn clause, you\nget back a horn clause. \nLogic can serve as a general class of representations for knowledge-based agents.  M(alpha) to mean the set of all models of alpha.\na⊨β if and only if M(a) ⊆ M(β). a is stronger,more specific.\nPossible Worlds is the process of\nenumerating all Possible Worlds that are\ncompatible with the KB. M(KB) ⊆ M(alpha1 )\nSound: should only derive entailed sentences. Complete-should derive all sentences that are entailed.\nRules:\n(alpha ⟹ β) ≡ (¬β ⟹ ¬alpha) Contraposition\n(alpha ⟹ β) ≡ (¬a ⋁ β) Implication elimination\n(a ⇔ β) ≡ ((a ⟹ β) ⋀ (β ⟹a)) Biconditional elimination\n¬(a ⋀ β) ≡ (¬a ⋁ ¬β) De Morgan\n¬(a ⋁ β) ≡ (¬a ⋀ ¬β) De Morgan\n((a ⋀ β) ⋁ ɣ) ≡ ((a ⋀ β) ⋁ (a ⋀ ɣ))) Distributivity of ⋀ over ⋁\n((a ⋁ β) ⋀ ɣ) ≡ ((a ⋁ β) ⋀ (a ⋁ ɣ))) Distributivity of ⋁ over ⋀\nIf ℓi and m are complementary literals,\nwhich means that one is the negation of\nanother, then we can eliminate them via\nunit resolution.\nCNF->distribute ⋁ over ⋀ wherever possible\nEvery definite clause can be written as an implication whose premise is a\nconjunction of positive literals whose conclusion is a positive literal.\n¬ L1,1 ⋁ ¬ Breeze ⋁ B1,1 can be written as the implication L1,1 ⋀ Breeze ⟹ B1,1 \nForward and backward chaining algorithm->inference with horn class\ndeciding entailment with Horn class can be done in linear time wrt KB.\nInference procedures based on resolution work using the principle of proof by\ncontradiction.\nTo show KB⊨a then we can show that KB ⋀ ¬a is unsatisfiable.\ncontinue until->1)There are no new clauses that can be added. In this case, the KB does not entail a\n2. Two clauses resolve to yield the empty clause, in which case the KB does entail a\n\n\n \n\n## Module 7 Definitions\n* **Knowledge based agents** - use reasoning over an internal representation of knowledge to decide what actions to take\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}