{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Bharg Mehta - 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": "6ecc256b-63fd-4355-8be3-6a70849c688f"
      },
      "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": 180,
      "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": "c05912be-633a-4200-f162-e84a90bcb5c8"
      },
      "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": 181,
      "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": 182,
      "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 = \"\"\" Chapter 1.1 summary. \"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter27_2 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter2_3 = \"\"\" Specification of a task environment has four components (P.E.A.S)\n",
        "- **P** - Performance measure\n",
        "- **E** - Environment\n",
        "- **A** - Actuators\n",
        "- **S** - Sensors \n",
        "\n",
        "**Properties of Task Environments**\n",
        "1. **Fully Observable** v/s **Partially Observable** v/s **Unobservable**\n",
        "2. **Deterministic** v/s **Non-deterministic** v/s **Stochastic**\n",
        "Stochastic is probabilistic\n",
        "3. **Episodic** v/s **Sequential**\n",
        "4. **Static** v/s **Dynamic**\n",
        "5. **Discrete** v/s **Continuous**\n",
        "Continuous requires a state representation of environment along with how time is managed\n",
        "6. **Single agent** v/s **Multi agent**\n",
        "\"\"\"\n",
        "chapter2_4 = \"\"\"*Agent  = architecture + program*\n",
        "1. Simple Reflex Agents - action selected based on current percept and ignoring the rest of the history of percept.(Fully-observable)\n",
        "2. Model-based Reflex agents - To handle partial observability, the agent maintains internal state that depends on the percept history that thereby reflects some of the unobserved aspects of the current state. \n",
        "Transition model - The knowledge about \"how the world works\" - either implemented in simple Boolean circuits or in complete scientific theories. \n",
        "Sensor model - The knowledge of how the state of the world is reflected in the agent's percept.\n",
        "Model-based agent - Transition model + Sensor model, allow the agent to keep a track of the state of the world and the agent that uses such models are called model-based agents\n",
        "3. Goal-based agents - Its actions are based on the goal to achieve\n",
        "4. Utility-based agents\n",
        "5. Learning based models \n",
        "\n",
        "Increasing order of complexity and expressive power: $Atomic < Factored < Structured$\n",
        "Examples, \n",
        "\n",
        "Atomic Representation - Search and Game-playing algorithms, hidden Markov Models and Markov Decision processes\n",
        "\n",
        "Factored representation - CSP, propositional logic, planning, Bayesian Networks and various machine learning algorithms\n",
        "\n",
        "Structured representations - relational databases and first-order logic, first order probability models, natural language understanding\n",
        "\n",
        "More expressive models can capture everything more concisely than the less expressive one. But with increasing expressiveness, learning becomes complex.\n",
        "\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 1.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module1_definitions = {\n",
        "\"agent\" : \"anything that can perceive and act in an environment\",\n",
        "\"Agent Function\":\"agent function f : P → a that maps a sequence of percept vectors P to an action a\",\n",
        "\"Agent Program\" : \"Agent_function = architecture + program\",\n",
        "\"Episodic\": \"choice of each action is not dependent on the previous actions\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": 183,
      "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": "6246cd29-1571-42a7-92ac-2b0521aa86fe"
      },
      "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": 184,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n 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 Specification of a task environment has four components (P.E.A.S)\n- **P** - Performance measure\n- **E** - Environment\n- **A** - Actuators\n- **S** - Sensors \n\n**Properties of Task Environments**\n1. **Fully Observable** v/s **Partially Observable** v/s **Unobservable**\n2. **Deterministic** v/s **Non-deterministic** v/s **Stochastic**\nStochastic is probabilistic\n3. **Episodic** v/s **Sequential**\n4. **Static** v/s **Dynamic**\n5. **Discrete** v/s **Continuous**\nContinuous requires a state representation of environment along with how time is managed\n6. **Single agent** v/s **Multi agent**\n\n\n## AIMA 2.4 The Structure of Agents\n*Agent  = architecture + program*\n1. Simple Reflex Agents - action selected based on current percept and ignoring the rest of the history of percept.(Fully-observable)\n2. Model-based Reflex agents - To handle partial observability, the agent maintains internal state that depends on the percept history that thereby reflects some of the unobserved aspects of the current state. \nTransition model - The knowledge about \"how the world works\" - either implemented in simple Boolean circuits or in complete scientific theories. \nSensor model - The knowledge of how the state of the world is reflected in the agent's percept.\nModel-based agent - Transition model + Sensor model, allow the agent to keep a track of the state of the world and the agent that uses such models are called model-based agents\n3. Goal-based agents - Its actions are based on the goal to achieve\n4. Utility-based agents\n5. Learning based models \n\nIncreasing order of complexity and expressive power: $Atomic < Factored < Structured$\nExamples, \n\nAtomic Representation - Search and Game-playing algorithms, hidden Markov Models and Markov Decision processes\n\nFactored representation - CSP, propositional logic, planning, Bayesian Networks and various machine learning algorithms\n\nStructured representations - relational databases and first-order logic, first order probability models, natural language understanding\n\nMore expressive models can capture everything more concisely than the less expressive one. But with increasing expressiveness, learning becomes complex.\n\n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Agent function** - agent function f : P → a that maps a sequence of percept vectors P to an action a\n* **Agent program** - Agent_function = architecture + program\n* **Episodic** - choice of each action is not dependent on the previous actions\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"mutability\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 185,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 207
        },
        "outputId": "2861dcc3-221a-48f0-88f6-7af861fd6a34"
      },
      "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": 186,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 2: Python\n## Module 2 Lecture Notes\n Your summary here \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": [
        "chapter3_1 = \"\"\"\n",
        "environment considered: episodic, single agent, fully observable, deterministic, static, discrete, and known.\n",
        "\n",
        "informed algorithms : agent can estimate how far it is from the goal\n",
        "uninformed algorithms : It has no clue how far it is from goal\n",
        "\n",
        "Agent follows a 4 phase problem solving process :\n",
        "- Goal Formulation \n",
        "- Problem Formulation - creates abstract definition to reach goal from start\n",
        "- Search - Agent tries to find a sequence of actions that reaches the goal. process is search, seq of steps is solution\n",
        "- Execution - Perform actions in the solution\n",
        "\n",
        "Important property - in a fully observable, deterministic, known environment, the solution to any problem is a fixed sequence of actions\n",
        "\n",
        "Defining a Search Problem :\n",
        "1. State Space\n",
        "2. Initial state\n",
        "3. Set of one or more goal states\n",
        "4. Actions available to the agent\n",
        "5. Transition model : Describes what each action does. RESULT(s, a) \n",
        "6. Performance measure/ path cost function\n",
        "7. Goal test\"\"\"\n",
        "\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "chapter3_3 = \"\"\" Search algorithm takes a search problem as input and returns a solution, or failure.\n",
        "\n",
        "Tree search - Node is a state, edge is the action, root is initial state.\n",
        "\n",
        "Three kinds of queues are used in search algorithms:\n",
        "- A priority queue - used in best-first search.\n",
        "- A FIFO queue - used in breadth-first search.\n",
        "- A LIFO queue - used in depth-first search.\n",
        "\n",
        "We call a search algorithm a **graph search if it checks for redundant paths** and a **tree-like search if it does not check**.\n",
        "\n",
        "Performance evaluation of algorithms:\n",
        "- Completeness: always find a solution if there exists one or return False when no solution exists\n",
        "- Cost optimality: finds the least cost solution first\n",
        "- Time complexity: How long does it take to find a solution? No. of Nodes generated (in worst case)\n",
        "- Space complexity: No of nodes simultaneously in memory (in worst case)\n",
        "\n",
        "\"\"\"\n",
        "chapter3_4 = \"\"\"\n",
        "- **BFS**\n",
        "    All actions have the same cost, then breadth-first search, root node is expanded first, then all the successors of the root and so on.\n",
        "    Queue used-FIFO\n",
        "    Properties :\n",
        "        - Optimal : if all actions have the same cost. Else its not optimal \n",
        "        - Complete \n",
        "        - Time complexity is O(b^d) \n",
        "        - Space complecity is O(b^d) \n",
        "    The memory requirements are a bigger problem than time.\n",
        "\n",
        "- **UCS or Dijkstra's algorithm**\n",
        "    Actions have different costs, evaluation function is the cost of the path from the root to the current node. Pick the node that leads to least cost\n",
        "    Algorithm’s worst-case time and space complexity can be greater than bfs.\n",
        "    Properties :\n",
        "        - Optimal\n",
        "        - Complete\n",
        "\n",
        "- **DFS**\n",
        "    Depth-first search always expands the deepest node in the frontier first. implemented as a tree-like search.\n",
        "    Properties :\n",
        "        - Not Optimal : \n",
        "        - Not complete : For finite and acyclic state spaces its complete but for cyclic state spaces and infinite state space incomplete\n",
        "        - Time complexity : O(b^m)\n",
        "        - Space Complexity : O(b*m) :\n",
        "    depth-first search has much smaller needs for memory.\n",
        "\n",
        "- **Depth Limited Search**\n",
        "    A version of depth-first search in which we supply a depth limit, l, and treat all nodes at depth l as if they had no successors. \n",
        "    Properties - \n",
        "    The time complexity is O(b^l) and the space complexity is O(bl).\n",
        "    Poor choice of l, algo will fail to reach the solution, making it incomplete.\n",
        "\n",
        "- **Iterative Depth Limited Search**\n",
        "    Picking a good value for l by trying all values: first 0, then 1, then 2, and .... till a solution is found, or the depth- limited search returns the failure\n",
        "\n",
        "    Properties :\n",
        "        - Complete\n",
        "        - Optimal\n",
        "        - Space Complexity - O(bd)\n",
        "        - The time complexity is O(b^d ) when there is a solution, or O(b^m ) when there is none\n",
        "    It is the preferred uninformed search method when the search state space is larger than can fit in memory and the depth of the solution is not known.\n",
        "\n",
        " \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" \n",
        "- b = maximum branching factor : max number of successors of a node that need to be considered.\n",
        "- d = depth of shallowest goal node: number of actions in an optimal solution\n",
        "- m = the maximum number of actions in any path\n",
        "\n",
        "- Bidirectional Search\n",
        "\n",
        "    An alternative approach called bidirectional search simultaneously searches forward from the initial state and backwards from the goal state(s), hoping that the two searches will meet\n",
        "\n",
        "    The motivation is that O(b^d/2 + b^d/2) is much less than O(b^d) \n",
        "    Bidirectional search expands two frontiers, one around the initial state and one around the goal, stopping when the two frontiers meet.\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",
        "\"early goal test\": \"checking a node for goal test as soon as it is generated\", \n",
        "\"late goal test\" : \"Goal test after poping from a queue\"\n",
        "}\n",
        "\n"
      ],
      "execution_count": 187,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "3e7da1ce-33b1-46a7-f76e-4b3be52f0209"
      },
      "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": 188,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 3: Search Problems\n## AIMA Chapter 3.1 Problem-Solving Agents\n\nenvironment considered: episodic, single agent, fully observable, deterministic, static, discrete, and known.\n\ninformed algorithms : agent can estimate how far it is from the goal\nuninformed algorithms : It has no clue how far it is from goal\n\nAgent follows a 4 phase problem solving process :\n- Goal Formulation \n- Problem Formulation - creates abstract definition to reach goal from start\n- Search - Agent tries to find a sequence of actions that reaches the goal. process is search, seq of steps is solution\n- Execution - Perform actions in the solution\n\nImportant property - in a fully observable, deterministic, known environment, the solution to any problem is a fixed sequence of actions\n\nDefining a Search Problem :\n1. State Space\n2. Initial state\n3. Set of one or more goal states\n4. Actions available to the agent\n5. Transition model : Describes what each action does. RESULT(s, a) \n6. Performance measure/ path cost function\n7. Goal test\n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Search algorithm takes a search problem as input and returns a solution, or failure.\n\nTree search - Node is a state, edge is the action, root is initial state.\n\nThree kinds of queues are used in search algorithms:\n- A priority queue - used in best-first search.\n- A FIFO queue - used in breadth-first search.\n- A LIFO queue - used in depth-first search.\n\nWe call a search algorithm a **graph search if it checks for redundant paths** and a **tree-like search if it does not check**.\n\nPerformance evaluation of algorithms:\n- Completeness: always find a solution if there exists one or return False when no solution exists\n- Cost optimality: finds the least cost solution first\n- Time complexity: How long does it take to find a solution? No. of Nodes generated (in worst case)\n- Space complexity: No of nodes simultaneously in memory (in worst case)\n\n\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n\n- **BFS**\n    All actions have the same cost, then breadth-first search, root node is expanded first, then all the successors of the root and so on.\n    Queue used-FIFO\n    Properties :\n        - Optimal : if all actions have the same cost. Else its not optimal \n        - Complete \n        - Time complexity is O(b^d) \n        - Space complecity is O(b^d) \n    The memory requirements are a bigger problem than time.\n\n- **UCS or Dijkstra's algorithm**\n    Actions have different costs, evaluation function is the cost of the path from the root to the current node. Pick the node that leads to least cost\n    Algorithm’s worst-case time and space complexity can be greater than bfs.\n    Properties :\n        - Optimal\n        - Complete\n\n- **DFS**\n    Depth-first search always expands the deepest node in the frontier first. implemented as a tree-like search.\n    Properties :\n        - Not Optimal : \n        - Not complete : For finite and acyclic state spaces its complete but for cyclic state spaces and infinite state space incomplete\n        - Time complexity : O(b^m)\n        - Space Complexity : O(b*m) :\n    depth-first search has much smaller needs for memory.\n\n- **Depth Limited Search**\n    A version of depth-first search in which we supply a depth limit, l, and treat all nodes at depth l as if they had no successors. \n    Properties - \n    The time complexity is O(b^l) and the space complexity is O(bl).\n    Poor choice of l, algo will fail to reach the solution, making it incomplete.\n\n- **Iterative Depth Limited Search**\n    Picking a good value for l by trying all values: first 0, then 1, then 2, and .... till a solution is found, or the depth- limited search returns the failure\n\n    Properties :\n        - Complete\n        - Optimal\n        - Space Complexity - O(bd)\n        - The time complexity is O(b^d ) when there is a solution, or O(b^m ) when there is none\n    It is the preferred uninformed search method when the search state space is larger than can fit in memory and the depth of the solution is not known.\n\n \n\n## Module 3 Lecture Notes\n \n- b = maximum branching factor : max number of successors of a node that need to be considered.\n- d = depth of shallowest goal node: number of actions in an optimal solution\n- m = the maximum number of actions in any path\n\n- Bidirectional Search\n\n    An alternative approach called bidirectional search simultaneously searches forward from the initial state and backwards from the goal state(s), hoping that the two searches will meet\n\n    The motivation is that O(b^d/2 + b^d/2) is much less than O(b^d) \n    Bidirectional search expands two frontiers, one around the initial state and one around the goal, stopping when the two frontiers meet.\n\n\n\n## Module 3 Definitions\n* **Early goal test** - checking a node for goal test as soon as it is generated\n* **Late goal test** - Goal test after poping from a queue\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": [
        "chapter3_5 = \"\"\" \n",
        "Informed search, uses domain-specific hints about the location of goals, finds solutions more efficiently than an uninformed\n",
        "heuristic function, h(n)\n",
        "\n",
        "**Greedy Best first search**\n",
        "It is a form of best-first search, node with lowesth(n) expands first i.e. node that appears closest to the goal, based on it is likely to find a solution quickly. evaluation function f(n) = h(n).\n",
        "\n",
        "**A star search**\n",
        "\n",
        "best-first search that uses f(n) = g(n) + h(n)\n",
        "where g(n) is path cost from the initial state to node n, and h(n) is estimated cost from n to a goal state,\n",
        "Properties - \n",
        "    - A* is complete\n",
        "    - A* optimality depends on if the heuristic is admissible or not. if it is admissible then its optimal\n",
        "\n",
        "An admissible heuristic is therefore optimistic.\n",
        "\n",
        "A heuristic h(n) is consistent if, for every node n and every successor n′ of n generated by an action a, we have:\n",
        "h(n) ≤ c(n,a,n′)+h(n′). Every consistent heuristic is admissible (but not vice versa), A∗ is cost-optimal with consistent heuristic, \n",
        "\n",
        "A∗ is efficient because it prunes away search tree nodes that are not necessary for finding an optimal solution.\n",
        "\n",
        "**Satisficing search** - \n",
        "A∗ expands a lot of nodes. Explore fewer nodes (taking less time and space) leads to suboptimal solutions, but are good enough- satisficing solutions. \n",
        "If we allow A∗ search to use an inadmissible heuristic—one that may overestimate—then we risk missing the optimal solution, but the heuristic can potentially be more accurate, thereby reducing the number of\n",
        "nodes expanded. \n",
        "\n",
        "weighted A∗ search where we weight the heuristic value more heavily, f(n) = g(n) + W × h(n), for some W > 1.\n",
        "\n",
        "\"\"\"\n",
        "chapter3_6 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 189,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 603
        },
        "cellView": "form",
        "outputId": "bf70b7a8-b03a-4cf9-b2c4-c90bca3cf3c1"
      },
      "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": 190,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n \nInformed search, uses domain-specific hints about the location of goals, finds solutions more efficiently than an uninformed\nheuristic function, h(n)\n\n**Greedy Best first search**\nIt is a form of best-first search, node with lowesth(n) expands first i.e. node that appears closest to the goal, based on it is likely to find a solution quickly. evaluation function f(n) = h(n).\n\n**A star search**\n\nbest-first search that uses f(n) = g(n) + h(n)\nwhere g(n) is path cost from the initial state to node n, and h(n) is estimated cost from n to a goal state,\nProperties - \n    - A* is complete\n    - A* optimality depends on if the heuristic is admissible or not. if it is admissible then its optimal\n\nAn admissible heuristic is therefore optimistic.\n\nA heuristic h(n) is consistent if, for every node n and every successor n′ of n generated by an action a, we have:\nh(n) ≤ c(n,a,n′)+h(n′). Every consistent heuristic is admissible (but not vice versa), A∗ is cost-optimal with consistent heuristic, \n\nA∗ is efficient because it prunes away search tree nodes that are not necessary for finding an optimal solution.\n\n**Satisficing search** - \nA∗ expands a lot of nodes. Explore fewer nodes (taking less time and space) leads to suboptimal solutions, but are good enough- satisficing solutions. \nIf we allow A∗ search to use an inadmissible heuristic—one that may overestimate—then we risk missing the optimal solution, but the heuristic can potentially be more accurate, thereby reducing the number of\nnodes expanded. \n\nweighted A∗ search where we weight the heuristic value more heavily, f(n) = g(n) + W × h(n), for some W > 1.\n\n\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 5 - Adversarial Search and Games"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" **Simplest Game Environment**\n",
        "\n",
        "- Multiagent\n",
        "- State\n",
        "- Discrete\n",
        "- Fully observable\n",
        "- Strategic\n",
        "\n",
        "**Key properties of our games:**\n",
        "\n",
        "- Two players make alternate moves\n",
        "- Zero-sum games\n",
        "- Clear set of legal moves\n",
        "- Well-defined outcomes\n",
        "\n",
        "Card games are stochastic.\"\"\"\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 191,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 874
        },
        "outputId": "171ae98b-a622-47f6-d0ff-3fed320aeff6"
      },
      "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": 192,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n **Simplest Game Environment**\n\n- Multiagent\n- State\n- Discrete\n- Fully observable\n- Strategic\n\n**Key properties of our games:**\n\n- Two players make alternate moves\n- Zero-sum games\n- Clear set of legal moves\n- Well-defined outcomes\n\nCard games are stochastic.\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 Your summary here \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 = \"\"\" A constraint satisfaction problem consists of three components, X,D, and C:\n",
        "\n",
        "- $X$ is a set of variables, ${X1, . . . ,Xn}$.\n",
        "- $D$ is a set of non-empty domains, ${D1, . . . ,Dn}$, one for each variable\n",
        "- $C$ is a set of constraints that specify allowable combinations of values. Each constraint $C_j$ consists of a pair $<scope, rel>$, where scope is a tuple of variables that participate in the constraint and $rel$ is a Relation is a relation that defines the values that those variables can take\n",
        "\n",
        "CSPs deal with assignments of values to variables, ${X_i = v_i,X_j =v_j, . . ., X_n = v_n}$ - Legal assignments\n",
        "\n",
        "- Simplest kind of CSP involves variables that have discrete, finite domains.\n",
        "Unary Constraints - It restricts the value of a single variable\n",
        "Binary Constraints - It restricts the value of two variables\n",
        "Binary CSP - CSP with only unary and binary constraints\n",
        "Global constraints - It constrains arbitrary number of variables. It doesn't mean it  constrains all variables.\n",
        "\n",
        "Resource Constraint  - Sometimes also called as *Atmost* constraint. \n",
        "\n",
        "- Every CSP can be converted to a binary CSP if enough auxiliary variables are introduced.\n",
        "- Dual-graph transformation →  create a new graph in which there will be one variable for each constraint in the original graph, and one binary constraint for each pair of constraints in the original graph that share variables. \"\"\"\n",
        "\n",
        "chapter6_2 = \"\"\" \n",
        "**AC-3**\n",
        "- AC-3 maintains a queue of arcs to consider\n",
        "- Initially AC-3 queue has all the arcs\n",
        "- AC-3 then pops out an arbitrary arc $(X_i, X_j)$ and then makes the variable $X_i$ arc consistent with $X_j$\n",
        "- If $D_i$ unchanged, the algorithm just moves on to the next arc. But if $D_i$ is changed (makes the domain smaller), then we add to the queue all arcs $(X_k,X_i)$ in which they are neighbors\n",
        "- If $D_i$ becomes empty set, whole CSP has no consistent solution, and AC-3 return failure. Else, keep checking till there are no more arcs in the queue\n",
        "- The CSP problem after and before AC-3 will have the same solutions but the one remaining after AC-3 will be faster to solve due to smaller domain size of variables and maybe lesser variables to solve for.\n",
        "- Complexity analysis of AC-3, $n$ variables, each with at most $d$ elements in domain with $c$ binary constraints.\n",
        "    - Each arc $(X_k,X_i)$ can be inserted in the queue only $d$ times because $X_i$ has at most d values to delete. $O(d^2)$ time (checking arc consistency)\n",
        "    - $O(cd^3)$ total worst-case time.\n",
        "    \n",
        "Strongly k-consistent runtime graph O(n^2d) \"\"\"\n",
        "\n",
        "chapter6_3 = \"\"\" MRV - Minimum Remaining Value → also called as the most-constrained variable or fail-first heuristic\n",
        "\n",
        "Degree heuristic → Attempts to reduce branching factor by choosing element involved in the largest number of constraints on other unassigned variables. For eg: in the sudoku problem it will be the one in which it will be a part of the maximum number arcs\n",
        "\n",
        "MRV is a more powerful heuristic but degree heuristic can act as a tie-breaker. \n",
        "\n",
        "**Forward Checking** - When a variable $X$ is assigned a value, for all variable $Y$ that are neighbours of $X$, i.e. $\\{X,Y\\}$ are arcs, all the values in the domain of $Y$ are removed that make those arcs inconsistent. \n",
        "\n",
        "**MAC (Maintaining Arc Consistencies) -** MAC is strictly more powerful than forward checking. **forward checking does not recursively propagate constraints** when changes are made to the domains of variables.\n",
        "\n",
        "**Chronological backtracking -** This is the regular backtracking algorithm \"\"\"\n",
        "chapter6_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_5 = \"\"\" 1. Choose a subset $S$ of the CSP’s variables such that the constraint graph becomes a tree\n",
        "after removal of $S$. $S$ is cycle cutset.\n",
        "2. For each possible assignment to the variables in $S$ that satisfies all constraints on $S$,\n",
        "(a) remove from the domains of the remaining variables any values that are inconsistent\n",
        "with the assignment for $S$, and\n",
        "(b) if the remaining CSP has a solution, return it together with the assignment for $S$.\n",
        "\n",
        "For the cycle cutset has size $c$, then the total run time is $O(dc · (n−c)d^2)$ \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"Complete Assignment\":\"Every variable is assigned a value and the solution thus achieved is consistent and complete\", \n",
        "\"Partial Assignment\":\"Assignment of values to variables such that some variables are left out\",\n",
        "\"Partial Solution\":\"A consistent solution with partial assignment is called a partial solution\"   \n",
        "}\n"
      ],
      "execution_count": 193,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "4ff1289b-d366-470d-c7c4-c9da54e1c20a"
      },
      "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": 194,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 6: Constraint Satisfaction Problems\n## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n A constraint satisfaction problem consists of three components, X,D, and C:\n\n- $X$ is a set of variables, ${X1, . . . ,Xn}$.\n- $D$ is a set of non-empty domains, ${D1, . . . ,Dn}$, one for each variable\n- $C$ is a set of constraints that specify allowable combinations of values. Each constraint $C_j$ consists of a pair $<scope, rel>$, where scope is a tuple of variables that participate in the constraint and $rel$ is a Relation is a relation that defines the values that those variables can take\n\nCSPs deal with assignments of values to variables, ${X_i = v_i,X_j =v_j, . . ., X_n = v_n}$ - Legal assignments\n\n- Simplest kind of CSP involves variables that have discrete, finite domains.\nUnary Constraints - It restricts the value of a single variable\nBinary Constraints - It restricts the value of two variables\nBinary CSP - CSP with only unary and binary constraints\nGlobal constraints - It constrains arbitrary number of variables. It doesn't mean it  constrains all variables.\n\nResource Constraint  - Sometimes also called as *Atmost* constraint. \n\n- Every CSP can be converted to a binary CSP if enough auxiliary variables are introduced.\n- Dual-graph transformation →  create a new graph in which there will be one variable for each constraint in the original graph, and one binary constraint for each pair of constraints in the original graph that share variables. \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n \n**AC-3**\n- AC-3 maintains a queue of arcs to consider\n- Initially AC-3 queue has all the arcs\n- AC-3 then pops out an arbitrary arc $(X_i, X_j)$ and then makes the variable $X_i$ arc consistent with $X_j$\n- If $D_i$ unchanged, the algorithm just moves on to the next arc. But if $D_i$ is changed (makes the domain smaller), then we add to the queue all arcs $(X_k,X_i)$ in which they are neighbors\n- If $D_i$ becomes empty set, whole CSP has no consistent solution, and AC-3 return failure. Else, keep checking till there are no more arcs in the queue\n- The CSP problem after and before AC-3 will have the same solutions but the one remaining after AC-3 will be faster to solve due to smaller domain size of variables and maybe lesser variables to solve for.\n- Complexity analysis of AC-3, $n$ variables, each with at most $d$ elements in domain with $c$ binary constraints.\n    - Each arc $(X_k,X_i)$ can be inserted in the queue only $d$ times because $X_i$ has at most d values to delete. $O(d^2)$ time (checking arc consistency)\n    - $O(cd^3)$ total worst-case time.\n    \nStrongly k-consistent runtime graph O(n^2d) \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n MRV - Minimum Remaining Value → also called as the most-constrained variable or fail-first heuristic\n\nDegree heuristic → Attempts to reduce branching factor by choosing element involved in the largest number of constraints on other unassigned variables. For eg: in the sudoku problem it will be the one in which it will be a part of the maximum number arcs\n\nMRV is a more powerful heuristic but degree heuristic can act as a tie-breaker. \n\n**Forward Checking** - When a variable $X$ is assigned a value, for all variable $Y$ that are neighbours of $X$, i.e. $\\{X,Y\\}$ are arcs, all the values in the domain of $Y$ are removed that make those arcs inconsistent. \n\n**MAC (Maintaining Arc Consistencies) -** MAC is strictly more powerful than forward checking. **forward checking does not recursively propagate constraints** when changes are made to the domains of variables.\n\n**Chronological backtracking -** This is the regular backtracking algorithm \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 1. Choose a subset $S$ of the CSP’s variables such that the constraint graph becomes a tree\nafter removal of $S$. $S$ is cycle cutset.\n2. For each possible assignment to the variables in $S$ that satisfies all constraints on $S$,\n(a) remove from the domains of the remaining variables any values that are inconsistent\nwith the assignment for $S$, and\n(b) if the remaining CSP has a solution, return it together with the assignment for $S$.\n\nFor the cycle cutset has size $c$, then the total run time is $O(dc · (n−c)d^2)$ \n\n## Module 6 Lecture Notes\n Your summary here \n\n## Module 6 Definitions\n* **Complete assignment** - Every variable is assigned a value and the solution thus achieved is consistent and complete\n* **Partial assignment** - Assignment of values to variables such that some variables are left out\n* **Partial solution** - A consistent solution with partial assignment is called a partial solution\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 195,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "cellView": "form",
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 535
        },
        "outputId": "1420bb51-d7aa-4987-e8b7-abd660bf6eb4"
      },
      "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": 196,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n Your summary here \n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vX7lbnJd4sT5"
      },
      "source": [
        "# Your Exam Notes\n",
        "\n",
        "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
        "\n",
        "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
        "* Run the cell below. \n",
        "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
        "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
        "* In the print options, change the layout from Landscape to Portrait. \n",
        "* Clicking the Save, will save a PDF that you can then print.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "adaaf807-2886-4a53-8a48-4e979109ff9e"
      },
      "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": 198,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 1: Rational Agents and Task Environments\n## AIMA Chapter 1.1 What is AI?\n Chapter 1.1 summary. \n\n## AIMA Chapter 27.1 The Limits of AI\n Your summary here \n\n## AIMA Chapter 27.1 Can Machines Really Think?\n Your summary here \n\n## AIMA 2.1 Agents and Environments\n 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 Specification of a task environment has four components (P.E.A.S)\n- **P** - Performance measure\n- **E** - Environment\n- **A** - Actuators\n- **S** - Sensors \n\n**Properties of Task Environments**\n1. **Fully Observable** v/s **Partially Observable** v/s **Unobservable**\n2. **Deterministic** v/s **Non-deterministic** v/s **Stochastic**\nStochastic is probabilistic\n3. **Episodic** v/s **Sequential**\n4. **Static** v/s **Dynamic**\n5. **Discrete** v/s **Continuous**\nContinuous requires a state representation of environment along with how time is managed\n6. **Single agent** v/s **Multi agent**\n\n\n## AIMA 2.4 The Structure of Agents\n*Agent  = architecture + program*\n1. Simple Reflex Agents - action selected based on current percept and ignoring the rest of the history of percept.(Fully-observable)\n2. Model-based Reflex agents - To handle partial observability, the agent maintains internal state that depends on the percept history that thereby reflects some of the unobserved aspects of the current state. \nTransition model - The knowledge about \"how the world works\" - either implemented in simple Boolean circuits or in complete scientific theories. \nSensor model - The knowledge of how the state of the world is reflected in the agent's percept.\nModel-based agent - Transition model + Sensor model, allow the agent to keep a track of the state of the world and the agent that uses such models are called model-based agents\n3. Goal-based agents - Its actions are based on the goal to achieve\n4. Utility-based agents\n5. Learning based models \n\nIncreasing order of complexity and expressive power: $Atomic < Factored < Structured$\nExamples, \n\nAtomic Representation - Search and Game-playing algorithms, hidden Markov Models and Markov Decision processes\n\nFactored representation - CSP, propositional logic, planning, Bayesian Networks and various machine learning algorithms\n\nStructured representations - relational databases and first-order logic, first order probability models, natural language understanding\n\nMore expressive models can capture everything more concisely than the less expressive one. But with increasing expressiveness, learning becomes complex.\n\n\n## Module 1 Lecture Notes\n Your summary here \n\n## Module 1 Definitions\n* **Agent** - anything that can perceive and act in an environment\n* **Agent function** - agent function f : P → a that maps a sequence of percept vectors P to an action a\n* **Agent program** - Agent_function = architecture + program\n* **Episodic** - choice of each action is not dependent on the previous actions\n\n\n# Module 2: Python\n## Module 2 Lecture Notes\n Your summary here \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\nenvironment considered: episodic, single agent, fully observable, deterministic, static, discrete, and known.\n\ninformed algorithms : agent can estimate how far it is from the goal\nuninformed algorithms : It has no clue how far it is from goal\n\nAgent follows a 4 phase problem solving process :\n- Goal Formulation \n- Problem Formulation - creates abstract definition to reach goal from start\n- Search - Agent tries to find a sequence of actions that reaches the goal. process is search, seq of steps is solution\n- Execution - Perform actions in the solution\n\nImportant property - in a fully observable, deterministic, known environment, the solution to any problem is a fixed sequence of actions\n\nDefining a Search Problem :\n1. State Space\n2. Initial state\n3. Set of one or more goal states\n4. Actions available to the agent\n5. Transition model : Describes what each action does. RESULT(s, a) \n6. Performance measure/ path cost function\n7. Goal test\n\n## AIMA Chapter 3.2 Example Problems\n Your summary here \n\n## AIMA Chapter 3.3 Search Algorithms\n Search algorithm takes a search problem as input and returns a solution, or failure.\n\nTree search - Node is a state, edge is the action, root is initial state.\n\nThree kinds of queues are used in search algorithms:\n- A priority queue - used in best-first search.\n- A FIFO queue - used in breadth-first search.\n- A LIFO queue - used in depth-first search.\n\nWe call a search algorithm a **graph search if it checks for redundant paths** and a **tree-like search if it does not check**.\n\nPerformance evaluation of algorithms:\n- Completeness: always find a solution if there exists one or return False when no solution exists\n- Cost optimality: finds the least cost solution first\n- Time complexity: How long does it take to find a solution? No. of Nodes generated (in worst case)\n- Space complexity: No of nodes simultaneously in memory (in worst case)\n\n\n\n## AIMA Chapter 3.4 Uninformed Search Strategies\n\n- **BFS**\n    All actions have the same cost, then breadth-first search, root node is expanded first, then all the successors of the root and so on.\n    Queue used-FIFO\n    Properties :\n        - Optimal : if all actions have the same cost. Else its not optimal \n        - Complete \n        - Time complexity is O(b^d) \n        - Space complecity is O(b^d) \n    The memory requirements are a bigger problem than time.\n\n- **UCS or Dijkstra's algorithm**\n    Actions have different costs, evaluation function is the cost of the path from the root to the current node. Pick the node that leads to least cost\n    Algorithm’s worst-case time and space complexity can be greater than bfs.\n    Properties :\n        - Optimal\n        - Complete\n\n- **DFS**\n    Depth-first search always expands the deepest node in the frontier first. implemented as a tree-like search.\n    Properties :\n        - Not Optimal : \n        - Not complete : For finite and acyclic state spaces its complete but for cyclic state spaces and infinite state space incomplete\n        - Time complexity : O(b^m)\n        - Space Complexity : O(b*m) :\n    depth-first search has much smaller needs for memory.\n\n- **Depth Limited Search**\n    A version of depth-first search in which we supply a depth limit, l, and treat all nodes at depth l as if they had no successors. \n    Properties - \n    The time complexity is O(b^l) and the space complexity is O(bl).\n    Poor choice of l, algo will fail to reach the solution, making it incomplete.\n\n- **Iterative Depth Limited Search**\n    Picking a good value for l by trying all values: first 0, then 1, then 2, and .... till a solution is found, or the depth- limited search returns the failure\n\n    Properties :\n        - Complete\n        - Optimal\n        - Space Complexity - O(bd)\n        - The time complexity is O(b^d ) when there is a solution, or O(b^m ) when there is none\n    It is the preferred uninformed search method when the search state space is larger than can fit in memory and the depth of the solution is not known.\n\n \n\n## Module 3 Lecture Notes\n \n- b = maximum branching factor : max number of successors of a node that need to be considered.\n- d = depth of shallowest goal node: number of actions in an optimal solution\n- m = the maximum number of actions in any path\n\n- Bidirectional Search\n\n    An alternative approach called bidirectional search simultaneously searches forward from the initial state and backwards from the goal state(s), hoping that the two searches will meet\n\n    The motivation is that O(b^d/2 + b^d/2) is much less than O(b^d) \n    Bidirectional search expands two frontiers, one around the initial state and one around the goal, stopping when the two frontiers meet.\n\n\n\n## Module 3 Definitions\n* **Early goal test** - checking a node for goal test as soon as it is generated\n* **Late goal test** - Goal test after poping from a queue\n\n\n# Module 4: Informed Search\n## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n \nInformed search, uses domain-specific hints about the location of goals, finds solutions more efficiently than an uninformed\nheuristic function, h(n)\n\n**Greedy Best first search**\nIt is a form of best-first search, node with lowesth(n) expands first i.e. node that appears closest to the goal, based on it is likely to find a solution quickly. evaluation function f(n) = h(n).\n\n**A star search**\n\nbest-first search that uses f(n) = g(n) + h(n)\nwhere g(n) is path cost from the initial state to node n, and h(n) is estimated cost from n to a goal state,\nProperties - \n    - A* is complete\n    - A* optimality depends on if the heuristic is admissible or not. if it is admissible then its optimal\n\nAn admissible heuristic is therefore optimistic.\n\nA heuristic h(n) is consistent if, for every node n and every successor n′ of n generated by an action a, we have:\nh(n) ≤ c(n,a,n′)+h(n′). Every consistent heuristic is admissible (but not vice versa), A∗ is cost-optimal with consistent heuristic, \n\nA∗ is efficient because it prunes away search tree nodes that are not necessary for finding an optimal solution.\n\n**Satisficing search** - \nA∗ expands a lot of nodes. Explore fewer nodes (taking less time and space) leads to suboptimal solutions, but are good enough- satisficing solutions. \nIf we allow A∗ search to use an inadmissible heuristic—one that may overestimate—then we risk missing the optimal solution, but the heuristic can potentially be more accurate, thereby reducing the number of\nnodes expanded. \n\nweighted A∗ search where we weight the heuristic value more heavily, f(n) = g(n) + W × h(n), for some W > 1.\n\n\n\n## AIMA Chapter 3.6 Heuristic Functions\n Your summary here \n\n## Module 4 Lecture Notes\n Your summary here \n\n## Module 4 Definitions\n* **Concept** - definition\n\n\n# Module 5: Adversarial Search and Games\n## AIMA Chapter 5.1 Game Theory\n **Simplest Game Environment**\n\n- Multiagent\n- State\n- Discrete\n- Fully observable\n- Strategic\n\n**Key properties of our games:**\n\n- Two players make alternate moves\n- Zero-sum games\n- Clear set of legal moves\n- Well-defined outcomes\n\nCard games are stochastic.\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 Your summary here \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 A constraint satisfaction problem consists of three components, X,D, and C:\n\n- $X$ is a set of variables, ${X1, . . . ,Xn}$.\n- $D$ is a set of non-empty domains, ${D1, . . . ,Dn}$, one for each variable\n- $C$ is a set of constraints that specify allowable combinations of values. Each constraint $C_j$ consists of a pair $<scope, rel>$, where scope is a tuple of variables that participate in the constraint and $rel$ is a Relation is a relation that defines the values that those variables can take\n\nCSPs deal with assignments of values to variables, ${X_i = v_i,X_j =v_j, . . ., X_n = v_n}$ - Legal assignments\n\n- Simplest kind of CSP involves variables that have discrete, finite domains.\nUnary Constraints - It restricts the value of a single variable\nBinary Constraints - It restricts the value of two variables\nBinary CSP - CSP with only unary and binary constraints\nGlobal constraints - It constrains arbitrary number of variables. It doesn't mean it  constrains all variables.\n\nResource Constraint  - Sometimes also called as *Atmost* constraint. \n\n- Every CSP can be converted to a binary CSP if enough auxiliary variables are introduced.\n- Dual-graph transformation →  create a new graph in which there will be one variable for each constraint in the original graph, and one binary constraint for each pair of constraints in the original graph that share variables. \n\n## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n \n**AC-3**\n- AC-3 maintains a queue of arcs to consider\n- Initially AC-3 queue has all the arcs\n- AC-3 then pops out an arbitrary arc $(X_i, X_j)$ and then makes the variable $X_i$ arc consistent with $X_j$\n- If $D_i$ unchanged, the algorithm just moves on to the next arc. But if $D_i$ is changed (makes the domain smaller), then we add to the queue all arcs $(X_k,X_i)$ in which they are neighbors\n- If $D_i$ becomes empty set, whole CSP has no consistent solution, and AC-3 return failure. Else, keep checking till there are no more arcs in the queue\n- The CSP problem after and before AC-3 will have the same solutions but the one remaining after AC-3 will be faster to solve due to smaller domain size of variables and maybe lesser variables to solve for.\n- Complexity analysis of AC-3, $n$ variables, each with at most $d$ elements in domain with $c$ binary constraints.\n    - Each arc $(X_k,X_i)$ can be inserted in the queue only $d$ times because $X_i$ has at most d values to delete. $O(d^2)$ time (checking arc consistency)\n    - $O(cd^3)$ total worst-case time.\n    \nStrongly k-consistent runtime graph O(n^2d) \n\n## AIMA Chapter 6.3 Backtracking Search for CSPs\n MRV - Minimum Remaining Value → also called as the most-constrained variable or fail-first heuristic\n\nDegree heuristic → Attempts to reduce branching factor by choosing element involved in the largest number of constraints on other unassigned variables. For eg: in the sudoku problem it will be the one in which it will be a part of the maximum number arcs\n\nMRV is a more powerful heuristic but degree heuristic can act as a tie-breaker. \n\n**Forward Checking** - When a variable $X$ is assigned a value, for all variable $Y$ that are neighbours of $X$, i.e. $\\{X,Y\\}$ are arcs, all the values in the domain of $Y$ are removed that make those arcs inconsistent. \n\n**MAC (Maintaining Arc Consistencies) -** MAC is strictly more powerful than forward checking. **forward checking does not recursively propagate constraints** when changes are made to the domains of variables.\n\n**Chronological backtracking -** This is the regular backtracking algorithm \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 1. Choose a subset $S$ of the CSP’s variables such that the constraint graph becomes a tree\nafter removal of $S$. $S$ is cycle cutset.\n2. For each possible assignment to the variables in $S$ that satisfies all constraints on $S$,\n(a) remove from the domains of the remaining variables any values that are inconsistent\nwith the assignment for $S$, and\n(b) if the remaining CSP has a solution, return it together with the assignment for $S$.\n\nFor the cycle cutset has size $c$, then the total run time is $O(dc · (n−c)d^2)$ \n\n## Module 6 Lecture Notes\n Your summary here \n\n## Module 6 Definitions\n* **Complete assignment** - Every variable is assigned a value and the solution thus achieved is consistent and complete\n* **Partial assignment** - Assignment of values to variables such that some variables are left out\n* **Partial solution** - A consistent solution with partial assignment is called a partial solution\n\n\n# Module 7: Logical Agents\n## AIMA Chapter 7.1 Knowledge-Based Agents\n Your summary here \n\n## AIMA Chapter 7.2 The Wumpus World\n Your summary here \n\n## AIMA Chapter 7.3 Logic\n Your summary here \n\n## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n Your summary here \n\n## AIMA 7.5 Propositional Theorem Proving\n Your summary here \n\n## Module 7 Lecture Notes\n Your summary here \n\n## Module 7 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}