{
 "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",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "lzaavW96tcxM",
    "outputId": "7c5cdea4-fab7-49d0-daab-45049c3068af"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The example summary is 116 words long, so you could write an additional 384 words.\n"
     ]
    }
   ],
   "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)))"
   ]
  },
  {
   "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",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "8DvZ57A-djo1",
    "outputId": "0fba2813-5f70-45b4-a740-0e496effad3c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length in words is 500\n",
      "The length in characters is 3030\n"
     ]
    }
   ],
   "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))"
   ]
  },
  {
   "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",
   "execution_count": 19,
   "metadata": {
    "collapsed": true,
    "id": "2RECnJArJew4"
   },
   "outputs": [],
   "source": [
    "name = \"\"\n",
    "permission = True\n",
    "anonymous = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GZZXyrV-xuAp"
   },
   "source": [
    "# Module 1 - Intro to AI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "id": "Y2NfE1CKxzS-"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length in words for chapter1_1 is 227\n",
      "The length in words for chapter27_1 is 107\n",
      "The length in words for chapter1_1 is 131\n",
      "The length in words for chapter2_1 is 43\n",
      "The length in words for chapter2_2 is 139\n",
      "The length in words for chapter2_3 is 29\n",
      "The length in words for chapter2_4 is 33\n",
      "The length in words for module1_lecture_notes is 2\n"
     ]
    }
   ],
   "source": [
    "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
    "\n",
    "chapter1_1 = \"\"\" \n",
    "- Intelligent (diff versions) --> human performance / rationality, internal thought process / intelligent behavior\n",
    "    - Human vs Rational, Thought vs behavior\n",
    "- Approaches\n",
    "    - 1)Acting Humanly - The turning test approach\n",
    "        - Computer to pass test need NLP, knowledge representation, automated reasoning, ML\n",
    "    - 2)Thinking Humany - The cognitive modelling approach\n",
    "        - Introspection, Psychological experiments, brain imaging\n",
    "    - 3)Thinking rationally - The\"Laws of thought\" approach \n",
    "        - Focus on Logic & probability\n",
    "    - 4)Acting Rationally - The rational agent appraoch\n",
    "        - Rational Agent - has 2 advantages\n",
    "            - More general than 'laws of thought\"\n",
    "            - More amenable to scientific development\n",
    "        - Agent focus on the right thing --> Standard Model with limited rationality\n",
    "    - 5)Beneficial Machines\n",
    "        - Value alignment problem is a tradeoff betwee true preference and objective we put into machine\n",
    "            \"\"\" \n",
    "print(\"The length in words for chapter1_1 is\", len(chapter1_1.split(' ')))\n",
    "\n",
    "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
    "chapter27_1 = \"\"\" \n",
    "- 1) The argument from informality:\n",
    "    - Human behaviour is too complex to get captured in set of rules\n",
    "    - Criticison on (Good Old Fashioned AI) GOFAI whihc works on logical rules for qualificcaton problem\n",
    "    - Embodied Cognition is to ensure brain can't be considered separeately, as cognition takes place within body\n",
    "    - In short, Derefus is agains the AI agend with logical rules\n",
    "- 2) The argument from disabily:\n",
    "    - Machines can't do emotions\n",
    "- 3) Mathematical Objections: \n",
    "    - Godel's incompleteness theoram\n",
    "- 4) Measuring AI - Turing test\n",
    "\"\"\"\n",
    "print(\"The length in words for chapter27_1 is\", len(chapter27_1.split(' ')))\n",
    "\n",
    "chapter27_2 = \"\"\" \n",
    "- Turning view ---- Police conventon that everyone thinks \n",
    "- Chinese Room:\n",
    "    - John Searel rejects the above \n",
    "    - When non Chinese speakers in a room, just use pieces of paper to construct Chinese words\n",
    "    - Doesn't mean speakers know Chinese and it's the same for Machines\n",
    "    - Biological Naturalism -> Low level physical process neurons, are the key for high level emergent features\n",
    "        - So for a human what Neuron is, transistors is nor for Machines\n",
    "- Consciousness and Qualia\n",
    "    - Issue of Consciousness -> awarness of outside world, self and subjective living experience\n",
    "    - Qualia is technical term for intrinsic nature of experiences\n",
    "\"\"\"\n",
    "\n",
    "print(\"The length in words for chapter1_1 is\", len(chapter27_2.split(' ')))\n",
    "\n",
    "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
    "chapter2_1 = \"\"\" \n",
    "- Agent pereceive its environment via sensors and act using actuators\n",
    "- Agent Function maps any given percepts to actions. It's an abstract mathematical desc\n",
    "- Agent Program is conremet implementation running within some physical systems\n",
    "- Agent Function will be implemented by Agent Program\n",
    "\"\"\"\n",
    "\n",
    "print(\"The length in words for chapter2_1 is\", len(chapter2_1.split(' ')))\n",
    "\n",
    "chapter2_2 = \"\"\" \n",
    " - Performance Measures:\n",
    "     - Conseuqnetialism\n",
    "     - Need to build agent such that it goes with uncertaininty and learns as it goes by\n",
    " - Rationality :\n",
    "    - Performance measures the adefines success criteria, agent's prior environemnt knowledge,\n",
    "        actions that agent perform, agent's percetps\n",
    "    - Priori is the gegoraphy of environment\n",
    " - Omniscience, learning and autonomy:\n",
    "    - Omniscient agends knows actual outcome and it acts accordinly, but not possible in reality\n",
    "    - Rationality maximizes the expected performance\n",
    "    - Perfection maximuzes actual performance\n",
    "    - Information Gathering -performing action so as to modify future percepts\n",
    "    - Lacking Autonomy - Agent's prior knowledge is from designer\n",
    "\"\"\"\n",
    "print(\"The length in words for chapter2_2 is\", len(chapter2_2.split(' ')))\n",
    "\n",
    "chapter2_3 = \"\"\" \n",
    "- Task Environment: Performance, Environment, Actuators, Sensors\n",
    "- FUlly vs Partially Observable\n",
    "- Single vs Multiple Agent\n",
    "- Deterministic vs Non Deterministic\n",
    "- Static vs Dynamic\n",
    "- Discrete vs Continous\n",
    "- Knowns vs Unknown\n",
    "\"\"\"\n",
    "\n",
    "print(\"The length in words for chapter2_3 is\", len(chapter2_3.split(' ')))\n",
    "\n",
    "chapter2_4 = \"\"\" \n",
    "- Agent = Agent Architecture (running on device) + Agent Program (which implements agent function)\n",
    "- Agent Programs:\n",
    "    - -----\n",
    "- Simple Reflex Agents:\n",
    "- Model Based reflex agents:\n",
    "- Goal based agents\n",
    "\"\"\"\n",
    "\n",
    "print(\"The length in words for chapter2_4 is\", len(chapter2_4.split(' ')))\n",
    "\n",
    "# Lecture notes \n",
    "module1_lecture_notes = \"\"\" \n",
    "\"\"\"\n",
    "\n",
    "print(\"The length in words for module1_lecture_notes is\", len(module1_lecture_notes.split(' ')))\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",
    "}\n",
    "\n"
   ]
  },
  {
   "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",
   "execution_count": 5,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 725
    },
    "id": "gYYeNcdM_maE",
    "outputId": "0caad8dd-ad20-4626-cb91-923d00b0fbab",
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 1: Rational Agents and Task Environments\n",
       "## AIMA Chapter 1.1 What is AI?\n",
       " \n",
       "- Intelligent (diff versions) --> human performance / rationality, internal thought process / intelligent behavior\n",
       "    - Human vs Rational, Thought vs behavior\n",
       "- Approaches\n",
       "    - 1)Acting Humanly - The turning test approach\n",
       "        - Computer to pass test need NLP, knowledge representation, automated reasoning, ML\n",
       "    - 2)Thinking Humany - The cognitive modelling approach\n",
       "        - Introspection, Psychological experiments, brain imaging\n",
       "    - 3)Thinking rationally - The\"Laws of thought\" approach \n",
       "        - Focus on Logic & probability\n",
       "    - 4)Acting Rationally - The rational agent appraoch\n",
       "        - Rational Agent - has 2 advantages\n",
       "            - More general than 'laws of thought\"\n",
       "            - More amenable to scientific development\n",
       "        - Agent focus on the right thing --> Standard Model with limited rationality\n",
       "    - 5)Beneficial Machines\n",
       "        - Value alignment problem is a tradeoff betwee true preference and objective we put into machine\n",
       "            \n",
       "\n",
       "## AIMA Chapter 27.1 The Limits of AI\n",
       " \n",
       "- 1) The argument from informality:\n",
       "    - Human behaviour is too complex to get captured in set of rules\n",
       "    - Criticison on (Good Old Fashioned AI) GOFAI whihc works on logical rules for qualificcaton problem\n",
       "    - Embodied Cognition is to ensure brain can't be considered separeately, as cognition takes place within body\n",
       "    - In short, Derefus is agains the AI agend with logical rules\n",
       "- 2) The argument from disabily:\n",
       "    - Machines can't do emotions\n",
       "- 3) Mathematical Objections: \n",
       "    - Godel's incompleteness theoram\n",
       "- 4) Measuring AI - Turing test\n",
       "\n",
       "\n",
       "## AIMA Chapter 27.1 Can Machines Really Think?\n",
       " \n",
       "- Turning view ---- Police conventon that everyone thinks \n",
       "- Chinese Room:\n",
       "    - John Searel rejects the above \n",
       "    - When non Chinese speakers in a room, just use pieces of paper to construct Chinese words\n",
       "    - Doesn't mean speakers know Chinese and it's the same for Machines\n",
       "    - Biological Naturalism -> Low level physical process neurons, are the key for high level emergent features\n",
       "        - So for a human what Neuron is, transistors is nor for Machines\n",
       "- Consciousness and Qualia\n",
       "    - Issue of Consciousness -> awarness of outside world, self and subjective living experience\n",
       "    - Qualia is technical term for intrinsic nature of experiences\n",
       "\n",
       "\n",
       "## AIMA 2.1 Agents and Environments\n",
       " \n",
       "- Agent pereceive its environment via sensors and act using actuators\n",
       "- Agent Function maps any given percepts to actions. It's an abstract mathematical desc\n",
       "- Agent Program is conremet implementation running within some physical systems\n",
       "- Agent Function will be implemented by Agent Program\n",
       "\n",
       "\n",
       "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
       " \n",
       " - Performance Measures:\n",
       "     - Conseuqnetialism\n",
       "     - Need to build agent such that it goes with uncertaininty and learns as it goes by\n",
       " - Rationality :\n",
       "    - Performance measures the adefines success criteria, agent's prior environemnt knowledge,\n",
       "        actions that agent perform, agent's percetps\n",
       "    - Priori is the gegoraphy of environment\n",
       " - Omniscience, learning and autonomy:\n",
       "    - Omniscient agends knows actual outcome and it acts accordinly, but not possible in reality\n",
       "    - Rationality maximizes the expected performance\n",
       "    - Perfection maximuzes actual performance\n",
       "    - Information Gathering -performing action so as to modify future percepts\n",
       "    - Lacking Autonomy - Agent's prior knowledge is from designer\n",
       "\n",
       "\n",
       "## AIMA 2.3 The Nature of Environments\n",
       " \n",
       "- Task Environment: Performance, Environment, Actuators, Sensors\n",
       "- FUlly vs Partially Observable\n",
       "- Single vs Multiple Agent\n",
       "- Deterministic vs Non Deterministic\n",
       "- Static vs Dynamic\n",
       "- Discrete vs Continous\n",
       "- Knowns vs Unknown\n",
       "\n",
       "\n",
       "## AIMA 2.4 The Structure of Agents\n",
       " \n",
       "- Agent = Agent Architecture (running on device) + Agent Program (which implements agent function)\n",
       "- Agent Programs:\n",
       "    - -----\n",
       "- Simple Reflex Agents:\n",
       "- Model Based reflex agents:\n",
       "- Goal based agents\n",
       "\n",
       "\n",
       "## Module 1 Lecture Notes\n",
       " \n",
       "\n",
       "\n",
       "## Module 1 Definitions\n",
       "* **Agent** - anything that can perceive and act in an environment\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9xRbdqDox2zD"
   },
   "source": [
    "#Module 2 - Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true,
    "id": "DpBvu7EMx7sy"
   },
   "outputs": [],
   "source": [
    "# No readings for this module.  Instead you can summarize the lecture instead.\n",
    "\n",
    "# Lecture notes \n",
    "module2_lecture_notes = \"\"\" \n",
    "- Strings are immutable\n",
    "- Lists are mutable \n",
    "- Sequence Types --> Tuples, List, String\n",
    "- Advantage of Generators:\n",
    "    - Less code than iterator\n",
    "    - maintains the local state automatically\n",
    "    - One at a time values are computed\n",
    "    - Good for agg and crucial for infite sequence\n",
    "    - Not good for inspecting indivudal values\"\"\"\n",
    "\n",
    "# Each definition should be at most 20 words long.\n",
    "module2_definitions = {\n",
    "\"mutability\" : \"your definition here\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 209
    },
    "id": "ydOK__lwWgdp",
    "outputId": "237a5fc3-0d0f-4240-8ebf-655b10675954"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 2: Python\n",
       "## Module 2 Lecture Notes\n",
       " \n",
       "- Strings are immutable\n",
       "- Lists are mutable \n",
       "- Sequence Types --> Tuples, List, String\n",
       "- Advantage of Generators:\n",
       "    - Less code than iterator\n",
       "    - maintains the local state automatically\n",
       "    - One at a time values are computed\n",
       "    - Good for agg and crucial for infite sequence\n",
       "    - Not good for inspecting indivudal values\n",
       "\n",
       "## Module 2 Definitions\n",
       "* **Mutability** - your definition here\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "46MQLR-Gx8dZ"
   },
   "source": [
    "#Module 3 - Search Problems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true,
    "id": "BN0b1eVYx-nd"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
    "chapter3_1 = \"\"\" \n",
    "- FOUR PHASE PROBLEM SOLVING PROCESS --> Goal Formation, Problem Formulation, Serach & Execution\n",
    "- OPEN LOOP - Known environemnt and deterministic\n",
    "- CLOSED LOOP - Environment is non deterministic\n",
    "- Branching strategy is used in Partially observable and non-deterministic environements\"\"\"\n",
    "chapter3_2 = \"\"\" \n",
    "<b> a) Standardized Problems: </b>\n",
    " - This is the benchmar for reserachers to compare algorithms\n",
    "\n",
    "<b> b) Real World Problems: </b>\n",
    " - Examples are Route Finding Problems, Touring Proble, VLSI Layout, robot navigation, Automatic assembly sequencing\n",
    "\"\"\"\n",
    "chapter3_3 = \"\"\" \n",
    "\n",
    "i) Best First Search:\n",
    "    - Proceeds with the minimum value of an evaulaton function\n",
    " \n",
    "ii) Redundant Paths:\n",
    "    - Algorithm are doomed, if they can't remember past\n",
    "    - 3 Approaches:\n",
    "        - Remember the previous state ( works if state space fits in memory). We call search algorithm here \"Graph Search\"\n",
    "        - Don't worry about prevous state and the sequence doesn't allow ( eg., assemblage). Since it doesn's \n",
    "            check this we can this as \"tree-like search\"\n",
    "        - Compromise and check for cylcles, but not for redundtant path in genral\n",
    "\n",
    "iii) Measuring Problem solving performance:\n",
    "\n",
    " - Completetness, cost Optimality, time & space complexity\n",
    "\"\"\"\n",
    "chapter3_4 = \"\"\" \n",
    "- BFS:\n",
    "   - when all options have same cost and cost optimal in this case\n",
    "   - Complete even on infinted spaces\n",
    "   - FIFO Queue\n",
    "   - Early Goal Test - To check if a node is a solution as soon as it is genered\n",
    "   - Late Goal Test -wait unti a node is popped off the queue\n",
    "   - Space Complexity = O(b^d)\n",
    "- DFS:\n",
    " - Implemented not as a graph search but tree like search\n",
    " - It is not cost optimal\n",
    " - Retruns first solution though it isn't cheapers\n",
    " - Efficient and complete for fintie spaces\n",
    " - Stuck in loop for cyclic state spaces\n",
    " - Incomplete for infinitee spaces\n",
    " - Memory is small for problesm where tree like search is possible\n",
    " - Memory complexity is O(bm)\n",
    "- Depth Limited search\n",
    " - Just to keep DFS from wandering inifited path\n",
    " - Time complesit is O(b^l)\n",
    "- Iterative deepening:\n",
    " - Does a good job of picking good value of l for the above\n",
    " - Time complexity is O(b^m)\n",
    "- Bidirectional search\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module3_lecture_notes = \"\"\" \n",
    "- Relfect Agent: It takes only the current percets and select actions accordingly\n",
    "- Problem Solving Agend: It has a goal in mind and does a seuence of action\n",
    "- Task Evironment:\n",
    "    - Fully Observable, deterministic and known environment (Solution is fixed sequence of actions)\n",
    "    - Partially observable and non deterministic (Branching Strategy)\n",
    "- Basic Serch Algorithm:\n",
    "    - Tree Search ( Problem is repeated states with exponentail cost in many cases)\n",
    "    - Graph Search - its an enhancement of above where we trace the visited nodes\n",
    "- Un-informed (Blind search) serach strategies - all non-goal nodes in the frontier looks equally good:\n",
    "    - Strategy is finding the order of expansion like using LIFO, FIFI or priority queue\n",
    "    - Completenes indicates if we find solution always\n",
    "    - <b> BFS </b>\n",
    "        - FIFO Frontier, complete if b is finite, O(b^2) time and space complexity, optimal if cost=1\n",
    "        - Use when space is restricted\n",
    "    - <b> DFS </b>\n",
    "        - LIFO, not complete in infitine depth, O(b^m) time and O(b*m) space and not optimal\n",
    "        - Use when possible finite paths\n",
    "    - <b> Depth Limited Search </b>\n",
    "    - <b> Iterative Deepening Search </b>\n",
    "- Informed Serarch - Some non-goal states can be ranke above others\"\"\"\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",
    "\"Search\": \"It is the process of finding sequence of actions\",\n",
    "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",\n",
    "\"Search probkem\": \"States, initial state, goal states, action, trasition model, action cost function\",\n",
    "\"State Space\": \"Its the set of all possible states in an environment\",\n",
    "\"Transition Model\":\"It describes what each action does\",\n",
    "\"Path\":\"Sequence of actions\",\n",
    "\"Solution\":\"Path from initial to goal state\",\n",
    "\"Model\": \"Formulation of Problem\",\n",
    "\"Complete & Optimal cost\": \"BFS, Uinform COst, Iterative Deeepning, Bi-directional\",\n",
    "\"Time Complexity\":\"BFS [O(b^d)] , DFS [O(b^m)]\",\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 474
    },
    "id": "lvtN3p7ET3Tx",
    "outputId": "21b42a50-b270-439d-ac74-40c061bf0bde",
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 3: Search Problems\n",
       "## AIMA Chapter 3.1 Problem-Solving Agents\n",
       " \n",
       "- FOUR PHASE PROBLEM SOLVING PROCESS --> Goal Formation, Problem Formulation, Serach & Execution\n",
       "- OPEN LOOP - Known environemnt and deterministic\n",
       "- CLOSED LOOP - Environment is non deterministic\n",
       "- Branching strategy is used in Partially observable and non-deterministic environements\n",
       "\n",
       "## AIMA Chapter 3.2 Example Problems\n",
       " \n",
       "<b> a) Standardized Problems: </b>\n",
       " - This is the benchmar for reserachers to compare algorithms\n",
       "\n",
       "<b> b) Real World Problems: </b>\n",
       " - Examples are Route Finding Problems, Touring Proble, VLSI Layout, robot navigation, Automatic assembly sequencing\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.3 Search Algorithms\n",
       " \n",
       "\n",
       "i) Best First Search:\n",
       "    - Proceeds with the minimum value of an evaulaton function\n",
       " \n",
       "ii) Redundant Paths:\n",
       "    - Algorithm are doomed, if they can't remember past\n",
       "    - 3 Approaches:\n",
       "        - Remember the previous state ( works if state space fits in memory). We call search algorithm here \"Graph Search\"\n",
       "        - Don't worry about prevous state and the sequence doesn't allow ( eg., assemblage). Since it doesn's \n",
       "            check this we can this as \"tree-like search\"\n",
       "        - Compromise and check for cylcles, but not for redundtant path in genral\n",
       "\n",
       "iii) Measuring Problem solving performance:\n",
       "\n",
       " - Completetness, cost Optimality, time & space complexity\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
       " \n",
       "- BFS:\n",
       "   - when all options have same cost and cost optimal in this case\n",
       "   - Complete even on infinted spaces\n",
       "   - FIFO Queue\n",
       "   - Early Goal Test - To check if a node is a solution as soon as it is genered\n",
       "   - Late Goal Test -wait unti a node is popped off the queue\n",
       "   - Space Complexity = O(b^d)\n",
       "- DFS:\n",
       " - Implemented not as a graph search but tree like search\n",
       " - It is not cost optimal\n",
       " - Retruns first solution though it isn't cheapers\n",
       " - Efficient and complete for fintie spaces\n",
       " - Stuck in loop for cyclic state spaces\n",
       " - Incomplete for infinitee spaces\n",
       " - Memory is small for problesm where tree like search is possible\n",
       " - Memory complexity is O(bm)\n",
       "- Depth Limited search\n",
       " - Just to keep DFS from wandering inifited path\n",
       " - Time complesit is O(b^l)\n",
       "- Iterative deepening:\n",
       " - Does a good job of picking good value of l for the above\n",
       " - Time complexity is O(b^m)\n",
       "- Bidirectional search\n",
       "\n",
       "\n",
       "## Module 3 Lecture Notes\n",
       " \n",
       "- Relfect Agent: It takes only the current percets and select actions accordingly\n",
       "- Problem Solving Agend: It has a goal in mind and does a seuence of action\n",
       "- Task Evironment:\n",
       "    - Fully Observable, deterministic and known environment (Solution is fixed sequence of actions)\n",
       "    - Partially observable and non deterministic (Branching Strategy)\n",
       "- Basic Serch Algorithm:\n",
       "    - Tree Search ( Problem is repeated states with exponentail cost in many cases)\n",
       "    - Graph Search - its an enhancement of above where we trace the visited nodes\n",
       "- Un-informed (Blind search) serach strategies - all non-goal nodes in the frontier looks equally good:\n",
       "    - Strategy is finding the order of expansion like using LIFO, FIFI or priority queue\n",
       "    - Completenes indicates if we find solution always\n",
       "    - <b> BFS </b>\n",
       "        - FIFO Frontier, complete if b is finite, O(b^2) time and space complexity, optimal if cost=1\n",
       "        - Use when space is restricted\n",
       "    - <b> DFS </b>\n",
       "        - LIFO, not complete in infitine depth, O(b^m) time and O(b*m) space and not optimal\n",
       "        - Use when possible finite paths\n",
       "    - <b> Depth Limited Search </b>\n",
       "    - <b> Iterative Deepening Search </b>\n",
       "- Informed Serarch - Some non-goal states can be ranke above others\n",
       "\n",
       "## Module 3 Definitions\n",
       "* **Search** - It is the process of finding sequence of actions\n",
       "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
       "* **Search probkem** - States, initial state, goal states, action, trasition model, action cost function\n",
       "* **State space** - Its the set of all possible states in an environment\n",
       "* **Transition model** - It describes what each action does\n",
       "* **Path** - Sequence of actions\n",
       "* **Solution** - Path from initial to goal state\n",
       "* **Model** - Formulation of Problem\n",
       "* **Complete & optimal cost** - BFS, Uinform COst, Iterative Deeepning, Bi-directional\n",
       "* **Time complexity** - BFS [O(b^d)] , DFS [O(b^m)]\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WHREsHSSyA-h"
   },
   "source": [
    "#Module 4 - Informed Search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true,
    "id": "tuFC8w7CyCns"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
    "chapter3_5 = \"\"\" The discuss here is in GBFS and how it uses only h(n), whereas A* uses g(n) + h(n) \\\n",
    "Terms such as consistency and triangle inequality were discussed as a property of admissable heuristic \\\n",
    "Unfiform cost secrch has circulat contour \\\n",
    "In A* f = h + g doesn't gaurantee a montonic increase in cost path \\\n",
    "A* search is complet and cost optimal usally, but ain't the answer for all\n",
    "\"\"\"\n",
    "chapter3_6 = \"\"\" \n",
    "-  \n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module4_lecture_notes = \"\"\" \n",
    "- Uniform Cost Search(UCS) is a search tree algorithm on weighted graph \n",
    "- UCS name is confusing and it doens't imply the same \n",
    "- UCS uses priority queue path cost g(N), i.e., how much its gonna cost between nodes \n",
    "- g(N) will increase as we expand the path\n",
    "- UCS doesn't know goal upfront as it uses priority queue and goes with less cost\n",
    "----\n",
    "- Hence we go for informed search using heuristic functions\n",
    "- Informed serach agorithms - Greedy-best first serach and A*\n",
    "- we use Path Cost g(N), evaluation function f(N)\n",
    "- Heurustic functon h(N) makes the best guess from that state to the goal\n",
    "- We want to underestimate this value\n",
    "----\n",
    "- Greedy Best First search uses priority gues and based on h(n) ( distance from goal) values it adds the value to the priority quere\n",
    "- It isn't optimal if there is an obstacle\n",
    "- it is not comlete either as it's not gauranteted to find solution everytime and can go in loops\n",
    "- GBFS search is complete in finite sapce\n",
    "- Asymptotic worst case time compexity O(|V|)\n",
    "\n",
    "----\n",
    "- A* is a knwon form of GBFS. It uses the positive of UCS + GBFS\n",
    "- The heurustic function is h(n) + g(n)\n",
    "- It might explore more than GBFS, but gaurantee to get to best solution\n",
    "\n",
    "- Memory Bound Search\n",
    "  - Reference Count\n",
    "  - Beam Search - \n",
    "  - Iterative- deepening A* Search ( IDA*) \n",
    "  - Recursive BFS\n",
    "- Bidirectional Heuristic Search\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module4_definitions = {\n",
    "\"Relaxed Problem\" : \"Problem with fewere restrictions on the actions than original\",    \n",
    "\"Triange inequality\": \"A side of the triangle can't ge greater than the sum of other two sides\",\n",
    "\"Beam Search\":\"Limits the size of the frontier.It keeps only k nodes with best f scores, hence it is incomplete and suboptimatl.\",\n",
    "\"Weighted A*\":\"it expands fewere nodes but sacrifices optimality\"\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 341
    },
    "id": "vqtEs0gHs9sO",
    "outputId": "822c50fc-17b3-444f-d7dd-83cdfb49f6d9"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 4: Informed Search\n",
       "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
       " The discuss here is in GBFS and how it uses only h(n), whereas A* uses g(n) + h(n) Terms such as consistency and triangle inequality were discussed as a property of admissable heuristic Unfiform cost secrch has circulat contour In A* f = h + g doesn't gaurantee a montonic increase in cost path A* search is complet and cost optimal usally, but ain't the answer for all\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.6 Heuristic Functions\n",
       " \n",
       "-  \n",
       "\n",
       "\n",
       "## Module 4 Lecture Notes\n",
       " \n",
       "- Uniform Cost Search(UCS) is a search tree algorithm on weighted graph \n",
       "- UCS name is confusing and it doens't imply the same \n",
       "- UCS uses priority queue path cost g(N), i.e., how much its gonna cost between nodes \n",
       "- g(N) will increase as we expand the path\n",
       "- UCS doesn't know goal upfront as it uses priority queue and goes with less cost\n",
       "----\n",
       "- Hence we go for informed search using heuristic functions\n",
       "- Informed serach agorithms - Greedy-best first serach and A*\n",
       "- we use Path Cost g(N), evaluation function f(N)\n",
       "- Heurustic functon h(N) makes the best guess from that state to the goal\n",
       "- We want to underestimate this value\n",
       "----\n",
       "- Greedy Best First search uses priority gues and based on h(n) ( distance from goal) values it adds the value to the priority quere\n",
       "- It isn't optimal if there is an obstacle\n",
       "- it is not comlete either as it's not gauranteted to find solution everytime and can go in loops\n",
       "- GBFS search is complete in finite sapce\n",
       "- Asymptotic worst case time compexity O(|V|)\n",
       "\n",
       "----\n",
       "- A* is a knwon form of GBFS. It uses the positive of UCS + GBFS\n",
       "- The heurustic function is h(n) + g(n)\n",
       "- It might explore more than GBFS, but gaurantee to get to best solution\n",
       "\n",
       "- Memory Bound Search\n",
       "  - Reference Count\n",
       "  - Beam Search - \n",
       "  - Iterative- deepening A* Search ( IDA*) \n",
       "  - Recursive BFS\n",
       "- Bidirectional Heuristic Search\n",
       "\n",
       "\n",
       "## Module 4 Definitions\n",
       "* **Relaxed problem** - Problem with fewere restrictions on the actions than original\n",
       "* **Triange inequality** - A side of the triangle can't ge greater than the sum of other two sides\n",
       "* **Beam search** - Limits the size of the frontier.It keeps only k nodes with best f scores, hence it is incomplete and suboptimatl.\n",
       "* **Weighted a*** - it expands fewere nodes but sacrifices optimality\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "F3FPMzG9yUls"
   },
   "source": [
    "#Module 5 - Adversarial Search and Games"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true,
    "id": "iEIOpL7vyWcc"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
    "chapter5_1 = \"\"\" deterministic, 2 players, tun taking, perfect information, zer- sum games. \\\n",
    "initial state, to-move, actions,results,is-termina,utility \\\n",
    "\"\"\"\n",
    "chapter5_2 = \"\"\" Min max if depth is m and b moves, then it peforms DFS \\\n",
    " and hence time complexity is O(b^m). Space complexity is O(bm) \\\n",
    "Impractical for complex games\\\n",
    "With move order we can achieve a best complexity of O(b^(m/2))\n",
    "\n",
    "- Move ordering for alpha bete minimax prunining\n",
    "- Type A Strategy - explores Wide but shallow portion of tree (chess)\n",
    "- Type B Strategy - explores deep but narrow portion of tree (go)\"\"\"\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 = \"\"\" \n",
    "- P(S'|s,a) --> Probabilty that actiion a in state s reaches state S'\n",
    "- Utility function captures agents prefernces\n",
    "- Expected Utility - avg utiity values of outcomes, witghed by prob that the outcome occurs\n",
    "- Maximum expected utilitu ( MEU) - Choosing an action which maximises agent's expected utility\n",
    "\"\"\"\n",
    "chapter16_2 = \"\"\" \n",
    "- Constraints on rational preferences\n",
    "- 6 Constraints:\n",
    " - Orderability\n",
    "     - Agent can't avoid choosing and need to chose one or other, Like A or B\n",
    " - Transitivity\n",
    "    - A to B and B to C, then A to C\n",
    " - Continuity\n",
    "     - B in between A and C prefernce\n",
    " - Sustainibilty\n",
    "     - Agent is indfferent between 2 lotteries\n",
    " - Monotonicity\n",
    "     - same two possible outcomes\n",
    " - Decomposibilty\n",
    "     - no fun in gambling\n",
    "\n",
    "- Rational Preference leads to utility\n",
    "\n",
    "    - Existence of untility functions:\n",
    "        - Follows of axioms of utility  and there exists function U where U(A) > U(B) and iff A is preferred to B and U(A) = U(B)\n",
    "    - Expected Utility of a lottery:\n",
    "        - \n",
    "\"\"\"\n",
    "chapter16_3 = \"\"\" \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module5_lecture_notes = \"\"\"  \"\"\"\n",
    "\n",
    "# Definitions\n",
    "module5_definitions = {\n",
    "\"concept\" : \"definition\", \n",
    "\"Preference Elicitation\": \"Working with human's untitlity function\",\n",
    "\"Certainitly Equivalent\": \"Value of agenet will accept in lieu of lottery\",\n",
    "\"Insurance Premium\": \"Diff between EMV of lottery and its certainty equivalent\",\n",
    "\"Neutral Curve\": \"Agent having a linear curve\",\n",
    "\"Optimizers Curve\": \"Tendencey for estimated EU of the best choice to be too high\",\n",
    "\"Normative Theory\":\"Describes how a Rational Agent should be\",\n",
    "\"Descriptive Theory\":\"How actual agents act\",\n",
    "\"Framing Effect\":\"Exact wording of decision problem can have a big impact on the agent choice\",\n",
    "\"Anchoring Effect\": \"Reative over absolute judgemet\"\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 674
    },
    "id": "KUc_LgzDvWf-",
    "outputId": "e9f5458e-82b4-4fa5-c56a-a0748aba7eaf"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 5: Adversarial Search and Games\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " deterministic, 2 players, tun taking, perfect information, zer- sum games. initial state, to-move, actions,results,is-termina,utility \n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       " Min max if depth is m and b moves, then it peforms DFS  and hence time complexity is O(b^m). Space complexity is O(bm) Impractical for complex gamesWith move order we can achieve a best complexity of O(b^(m/2))\n",
       "\n",
       "- Move ordering for alpha bete minimax prunining\n",
       "- Type A Strategy - explores Wide but shallow portion of tree (chess)\n",
       "- Type B Strategy - explores deep but narrow portion of tree (go)\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",
       " \n",
       "- P(S'|s,a) --> Probabilty that actiion a in state s reaches state S'\n",
       "- Utility function captures agents prefernces\n",
       "- Expected Utility - avg utiity values of outcomes, witghed by prob that the outcome occurs\n",
       "- Maximum expected utilitu ( MEU) - Choosing an action which maximises agent's expected utility\n",
       "\n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " \n",
       "- Constraints on rational preferences\n",
       "- 6 Constraints:\n",
       " - Orderability\n",
       "     - Agent can't avoid choosing and need to chose one or other, Like A or B\n",
       " - Transitivity\n",
       "    - A to B and B to C, then A to C\n",
       " - Continuity\n",
       "     - B in between A and C prefernce\n",
       " - Sustainibilty\n",
       "     - Agent is indfferent between 2 lotteries\n",
       " - Monotonicity\n",
       "     - same two possible outcomes\n",
       " - Decomposibilty\n",
       "     - no fun in gambling\n",
       "\n",
       "- Rational Preference leads to utility\n",
       "\n",
       "    - Existence of untility functions:\n",
       "        - Follows of axioms of utility  and there exists function U where U(A) > U(B) and iff A is preferred to B and U(A) = U(B)\n",
       "    - Expected Utility of a lottery:\n",
       "        - \n",
       "\n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " \n",
       "\n",
       "## Module 5 Lecture Notes\n",
       "  \n",
       "\n",
       "## Module 5 Definitions\n",
       "* **Concept** - definition\n",
       "* **Preference elicitation** - Working with human's untitlity function\n",
       "* **Certainitly equivalent** - Value of agenet will accept in lieu of lottery\n",
       "* **Insurance premium** - Diff between EMV of lottery and its certainty equivalent\n",
       "* **Neutral curve** - Agent having a linear curve\n",
       "* **Optimizers curve** - Tendencey for estimated EU of the best choice to be too high\n",
       "* **Normative theory** - Describes how a Rational Agent should be\n",
       "* **Descriptive theory** - How actual agents act\n",
       "* **Framing effect** - Exact wording of decision problem can have a big impact on the agent choice\n",
       "* **Anchoring effect** - Reative over absolute judgemet\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qVSQhTVSyYYO"
   },
   "source": [
    "#Module 6 - \"Constraint Satisfaction Problems\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "id": "Wm4mfW82yaRH"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length in chapter6_1 is 86\n",
      "The length in chapter6_1 is 556\n"
     ]
    }
   ],
   "source": [
    "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
    "chapter6_1 = \"\"\" \n",
    "- 3 Components --> Set of Variables, Domains and Constraints\n",
    "- CSK deals with the variables assignments\n",
    "- Solving CSP is a NP Complete problem\n",
    "- Example 1: Map Coloring\n",
    "- Example 2: Job Shop Scheduling\n",
    "- Examples of Types of constraints --> Precedences Constrain & disjunctive constraint\n",
    "- Map coloring, scheduling & 8-queens are examples of discrete & finite domains\n",
    "- In the case of infinite domains, implicit constains (such as T1 + d1 <= T2) should be used than explitic tuples values\n",
    "- Linear Programming Problems are examples of continous domains\n",
    "\n",
    "\"\"\"\n",
    "chapter6_2 = \"\"\" Local consistency, node consistency, arc consistency, path consistency, k-consistenct, global constraints\n",
    "- Path consistelcy: in case of unary domain this does by looking at triples of variables\n",
    "- K Consistent - If for any set k-1 variables, consistent value can always be assigned to kth variable. Run time O(n^2d)\"\"\"\n",
    "chapter6_3 = \"\"\" Your summary here \"\"\"\n",
    "chapter6_4 = \"\"\" \n",
    "- It uses complete-state forumation, wherein each states assigns value to every variable\n",
    "- It violates constraitns for sure, but we do reassignment in next steps which close to the solution - min-conflicts heuristics\n",
    "- Plataeau search allows the movement to another state with same score\n",
    "- Wandering of plateau is dorected with Tab Search technique, whick keeps small set of recently visited nodes and make sure it is not \n",
    "visited again\n",
    "-\"Constrain Weighting\" is yet anothe technique , where it aims to search the important constraints\n",
    "- Local search example is flight scedule \"\"\"  \n",
    "chapter6_5 = \"\"\" \n",
    "- Make sure we deal the problem as independent sub problems\n",
    "- Directional Arc Consistency - iff every Xi are Arc Conssitent with Xj for j > i\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module6_lecture_notes = \"\"\" \n",
    "- So for we are trying to do a search to formulate a plan \n",
    "- Instread of planning for sequence of action, we identify the problem in CSP\n",
    "- in A* we used knowledge of world, here in CSP has the knowledge about constrains\n",
    "- CSP consists of set of variables, domains, finite set of the constraints\n",
    "- If the variables doesn't violate constrains, then it's consistent\n",
    "- AllDiff is a global constraint\n",
    "- Preferance Constraints\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module6_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n",
    "\n",
    "\n",
    "print(\"The length in chapter6_1 is\", len(chapter6_1.split(' ')))\n",
    "print(\"The length in chapter6_1 is\", len(chapter6_1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 541
    },
    "id": "kKWbCsbfxL3R",
    "outputId": "f51aeef3-74ac-4ec6-b389-54aae53b8cbc"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 6: Constraint Satisfaction Problems\n",
       "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
       " \n",
       "- 3 Components --> Set of Variables, Domains and Constraints\n",
       "- CSK deals with the variables assignments\n",
       "- Solving CSP is a NP Complete problem\n",
       "- Example 1: Map Coloring\n",
       "- Example 2: Job Shop Scheduling\n",
       "- Examples of Types of constraints --> Precedences Constrain & disjunctive constraint\n",
       "- Map coloring, scheduling & 8-queens are examples of discrete & finite domains\n",
       "- In the case of infinite domains, implicit constains (such as T1 + d1 <= T2) should be used than explitic tuples values\n",
       "- Linear Programming Problems are examples of continous domains\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
       " Local consistency, node consistency, arc consistency, path consistency, k-consistenct, global constraints\n",
       "- Path consistelcy: in case of unary domain this does by looking at triples of variables\n",
       "- K Consistent - If for any set k-1 variables, consistent value can always be assigned to kth variable. Run time O(n^2d)\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",
       " \n",
       "- It uses complete-state forumation, wherein each states assigns value to every variable\n",
       "- It violates constraitns for sure, but we do reassignment in next steps which close to the solution - min-conflicts heuristics\n",
       "- Plataeau search allows the movement to another state with same score\n",
       "- Wandering of plateau is dorected with Tab Search technique, whick keeps small set of recently visited nodes and make sure it is not \n",
       "visited again\n",
       "-\"Constrain Weighting\" is yet anothe technique , where it aims to search the important constraints\n",
       "- Local search example is flight scedule \n",
       "\n",
       "## AIMA Chapter 6.5 The Structure of Problems\n",
       " \n",
       "- Make sure we deal the problem as independent sub problems\n",
       "- Directional Arc Consistency - iff every Xi are Arc Conssitent with Xj for j > i\n",
       "\n",
       "\n",
       "## Module 6 Lecture Notes\n",
       " \n",
       "- So for we are trying to do a search to formulate a plan \n",
       "- Instread of planning for sequence of action, we identify the problem in CSP\n",
       "- in A* we used knowledge of world, here in CSP has the knowledge about constrains\n",
       "- CSP consists of set of variables, domains, finite set of the constraints\n",
       "- If the variables doesn't violate constrains, then it's consistent\n",
       "- AllDiff is a global constraint\n",
       "- Preferance Constraints\n",
       "\n",
       "## Module 6 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "RYESi2kMybL8"
   },
   "source": [
    "#Module 7 - Logical Agents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true,
    "id": "qIRJ4YYCzNHL"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
    "\n",
    "chapter7_1 = \"\"\" \n",
    "- KB is the central component of KB agent\n",
    "- KB = set of sentances\n",
    "- Each sentance in the KB is expressed in Knowledge representation language and some assertions\n",
    "- Axiom is a sentance without derived from other sentance\n",
    "- Inference is dervingh sentance from another\n",
    "- TELL --> adding new sentance, ASK --> querying\n",
    "- Three things done by KB agent when called --> TELLS KB what it perceives, ASK KB what to perform, TELLS KB which action was chosen\n",
    "- Knowledge Level (specify only what agend needs) vs Implementaion Level\n",
    "- Declarative  (Startin with empty knowlege designed TELLS one by one) vs Procedural approach (as program code)\n",
    "- Best is the mix of both Declrarive and procedureal approach\n",
    "\"\"\" \n",
    "chapter7_2 = \"\"\" \n",
    " - Performance Measure, Environment, Actuators, Sensors\"\"\"\n",
    "chapter7_3 = \"\"\" \n",
    "- Logic defines semantics or meanring of a sentance\n",
    "- Semantics in turn definds the truth of each sentence to each possible word\n",
    "- When precision is needed, we used \"Model\" instead of possible world.\n",
    "- If a sentance alpha is true in model \"m\", then we say\n",
    "    - m satisifes alpha (or)\n",
    "    - m is a model of alpha\n",
    "- logical entailment between sentances - i.e. sentence follows logically from other sentences\n",
    "- Entailment is like needle being in the haystack, whereas inference is finding it\n",
    "- Sound/Truth preserving is an inference algorthim that determines only entailed sentences\n",
    "- Inference is alg is complete only when it can derive sentences that is entailed\n",
    "- Grounding is the connection between logical reasoning & real ennvironment in which agent exits\n",
    "\"\"\"\n",
    "chapter7_4 = \"\"\" \n",
    "- Atomis sentances consists of a single proposition symbol\n",
    "- Syntax\n",
    "- Semantics\n",
    "\n",
    "\"\"\"\n",
    "chapter7_5 = \"\"\" \n",
    "- If nbr of models is large , but lenght of proof is short => Theoram proving more efficient than model chekcing\n",
    "- Concepts:\n",
    "    - Logical Equivalence -> 2 sentances if true in same set of models\n",
    "    - Validity ( Tautologies -> valid sentances) - If sentance true in all models\n",
    "    - Satisfiability -> a sentances true in or satisified by some model\n",
    "Inference and proof:\n",
    " - Modus Ponens Rule --> (alpha => beta, alpha) / beta ( here beta is inferred given the numerator)\n",
    " - And-Elimination Rule --> From a conjunction, any of the conjunction can be inferred --> (Alpha and Beta) / Alpha\n",
    "- Monotonicity - set of entailed sentances can only increase in as informaton added to KB\n",
    "Proof by Resolution:\n",
    " - Single inference rule which yields a complete inference algorithm when coupled with any seach algorithm\n",
    " - Factoring: The remove of multiple copies of literals  \n",
    " - Ground Resolution Theoram - Completeness theoram for resultion in propositional logic\n",
    "Horn & Definite clauses:\n",
    " - Disjunction of literals of which exactly 1 is posiitve is called definite clause\n",
    " - Horn Clause - Disjunction of literals of which atmost 1 is posiitve\n",
    "     - Premise is body, conclusion is head\n",
    " - Fact : Sentance with single positive literal\n",
    "Forward and Backward Chaining: (for knowledge bases in Horn Form)\n",
    "    - Sound & complete\n",
    "    - Sound Inferecne algorothom derives only sentacnes that are entailed, wherase complete derives all sentances\n",
    "    - Backword chaining is a form of goal-directed reasoning \n",
    "\"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module7_lecture_notes = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Definitions\n",
    "module7_definitions = {\n",
    "\"concept\" : \"definition\", \n",
    "\"commutative of and\": \"(alpha and beta) === (beta and alpha)\",\n",
    "\"commutative of or\" : \"(alpha or beta) === (beta or alpha)\",\n",
    "\"Associative of and\": \"((alpha and beta) and gamma) === (alpha and (beta and gamma))\",\n",
    "\"Associative of or\": \"((alpha or beta) or gamma) === (alpha or (beta or gamma))\",\n",
    "\"double negation elimination\": \"not (not alpha) === alpha\",\n",
    "\"Contraposition\": \"(alpha => beta) === (not Beta => not alpha)\",\n",
    "\"Implication elimination\": \"(alpha => beta) === (not alpha or beta)\",\n",
    "\"Biconditional elimination\": \"(alpha <=> beta) === ((alpha => beta) and (beta => alpha))\",\n",
    "\"demorgan\": \"not(alpha and beta) === ( not alpha or not beta)\",\n",
    "\"demorgan\": \"not(alpha or beta) === ( not alpha and not beta)\",\n",
    "\"distribute of and over or\": \"(alpha and ( beta or gamma)) === ((alpha and beta) or (alpha and gamma))\",\n",
    "\"distribute of or over and\": \"(alpha or ( beta and gamma)) === ((alpha or beta) and (alpha or gamma))\",\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 541
    },
    "id": "lXNcHuKjyNXa",
    "outputId": "fd406b8c-6eaa-4be5-be5f-3639d4b7fa43"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 7: Logical Agents\n",
       "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
       " \n",
       "- KB is the central component of KB agent\n",
       "- KB = set of sentances\n",
       "- Each sentance in the KB is expressed in Knowledge representation language and some assertions\n",
       "- Axiom is a sentance without derived from other sentance\n",
       "- Inference is dervingh sentance from another\n",
       "- TELL --> adding new sentance, ASK --> querying\n",
       "- Three things done by KB agent when called --> TELLS KB what it perceives, ASK KB what to perform, TELLS KB which action was chosen\n",
       "- Knowledge Level (specify only what agend needs) vs Implementaion Level\n",
       "- Declarative  (Startin with empty knowlege designed TELLS one by one) vs Procedural approach (as program code)\n",
       "- Best is the mix of both Declrarive and procedureal approach\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.2 The Wumpus World\n",
       " \n",
       " - Performance Measure, Environment, Actuators, Sensors\n",
       "\n",
       "## AIMA Chapter 7.3 Logic\n",
       " \n",
       "- Logic defines semantics or meanring of a sentance\n",
       "- Semantics in turn definds the truth of each sentence to each possible word\n",
       "- When precision is needed, we used \"Model\" instead of possible world.\n",
       "- If a sentance alpha is true in model \"m\", then we say\n",
       "    - m satisifes alpha (or)\n",
       "    - m is a model of alpha\n",
       "- logical entailment between sentances - i.e. sentence follows logically from other sentences\n",
       "- Entailment is like needle being in the haystack, whereas inference is finding it\n",
       "- Sound/Truth preserving is an inference algorthim that determines only entailed sentences\n",
       "- Inference is alg is complete only when it can derive sentences that is entailed\n",
       "- Grounding is the connection between logical reasoning & real ennvironment in which agent exits\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
       " \n",
       "- Atomis sentances consists of a single proposition symbol\n",
       "- Syntax\n",
       "- Semantics\n",
       "\n",
       "\n",
       "\n",
       "## AIMA 7.5 Propositional Theorem Proving\n",
       " \n",
       "- If nbr of models is large , but lenght of proof is short => Theoram proving more efficient than model chekcing\n",
       "- Concepts:\n",
       "    - Logical Equivalence -> 2 sentances if true in same set of models\n",
       "    - Validity ( Tautologies -> valid sentances) - If sentance true in all models\n",
       "    - Satisfiability -> a sentances true in or satisified by some model\n",
       "Inference and proof:\n",
       " - Modus Ponens Rule --> (alpha => beta, alpha) / beta ( here beta is inferred given the numerator)\n",
       " - And-Elimination Rule --> From a conjunction, any of the conjunction can be inferred --> (Alpha and Beta) / Alpha\n",
       "- Monotonicity - set of entailed sentances can only increase in as informaton added to KB\n",
       "Proof by Resolution:\n",
       " - Single inference rule which yields a complete inference algorithm when coupled with any seach algorithm\n",
       " - Factoring: The remove of multiple copies of literals  \n",
       " - Ground Resolution Theoram - Completeness theoram for resultion in propositional logic\n",
       "Horn & Definite clauses:\n",
       " - Disjunction of literals of which exactly 1 is posiitve is called definite clause\n",
       " - Horn Clause - Disjunction of literals of which atmost 1 is posiitve\n",
       "     - Premise is body, conclusion is head\n",
       " - Fact : Sentance with single positive literal\n",
       "Forward and Backward Chaining: (for knowledge bases in Horn Form)\n",
       "    - Sound & complete\n",
       "    - Sound Inferecne algorothom derives only sentacnes that are entailed, wherase complete derives all sentances\n",
       "    - Backword chaining is a form of goal-directed reasoning \n",
       "\n",
       "\n",
       "## Module 7 Lecture Notes\n",
       " Your summary here \n",
       "\n",
       "## Module 7 Definitions\n",
       "* **Concept** - definition\n",
       "* **Commutative of and** - (alpha and beta) === (beta and alpha)\n",
       "* **Commutative of or** - (alpha or beta) === (beta or alpha)\n",
       "* **Associative of and** - ((alpha and beta) and gamma) === (alpha and (beta and gamma))\n",
       "* **Associative of or** - ((alpha or beta) or gamma) === (alpha or (beta or gamma))\n",
       "* **Double negation elimination** - not (not alpha) === alpha\n",
       "* **Contraposition** - (alpha => beta) === (not Beta => not alpha)\n",
       "* **Implication elimination** - (alpha => beta) === (not alpha or beta)\n",
       "* **Biconditional elimination** - (alpha <=> beta) === ((alpha => beta) and (beta => alpha))\n",
       "* **Demorgan** - not(alpha or beta) === ( not alpha and not beta)\n",
       "* **Distribute of and over or** - (alpha and ( beta or gamma)) === ((alpha and beta) or (alpha and gamma))\n",
       "* **Distribute of or over and** - (alpha or ( beta and gamma)) === ((alpha or beta) and (alpha or gamma))\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "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",
   "execution_count": 18,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 3366
    },
    "id": "T3cm1WV542_a",
    "outputId": "a929c6c6-b72b-4fd8-bd35-a014674c9230",
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 1: Rational Agents and Task Environments\n",
       "## AIMA Chapter 1.1 What is AI?\n",
       " \n",
       "- Intelligent (diff versions) --> human performance / rationality, internal thought process / intelligent behavior\n",
       "    - Human vs Rational, Thought vs behavior\n",
       "- Approaches\n",
       "    - 1)Acting Humanly - The turning test approach\n",
       "        - Computer to pass test need NLP, knowledge representation, automated reasoning, ML\n",
       "    - 2)Thinking Humany - The cognitive modelling approach\n",
       "        - Introspection, Psychological experiments, brain imaging\n",
       "    - 3)Thinking rationally - The\"Laws of thought\" approach \n",
       "        - Focus on Logic & probability\n",
       "    - 4)Acting Rationally - The rational agent appraoch\n",
       "        - Rational Agent - has 2 advantages\n",
       "            - More general than 'laws of thought\"\n",
       "            - More amenable to scientific development\n",
       "        - Agent focus on the right thing --> Standard Model with limited rationality\n",
       "    - 5)Beneficial Machines\n",
       "        - Value alignment problem is a tradeoff betwee true preference and objective we put into machine\n",
       "            \n",
       "\n",
       "## AIMA Chapter 27.1 The Limits of AI\n",
       " \n",
       "- 1) The argument from informality:\n",
       "    - Human behaviour is too complex to get captured in set of rules\n",
       "    - Criticison on (Good Old Fashioned AI) GOFAI whihc works on logical rules for qualificcaton problem\n",
       "    - Embodied Cognition is to ensure brain can't be considered separeately, as cognition takes place within body\n",
       "    - In short, Derefus is agains the AI agend with logical rules\n",
       "- 2) The argument from disabily:\n",
       "    - Machines can't do emotions\n",
       "- 3) Mathematical Objections: \n",
       "    - Godel's incompleteness theoram\n",
       "- 4) Measuring AI - Turing test\n",
       "\n",
       "\n",
       "## AIMA Chapter 27.1 Can Machines Really Think?\n",
       " \n",
       "- Turning view ---- Police conventon that everyone thinks \n",
       "- Chinese Room:\n",
       "    - John Searel rejects the above \n",
       "    - When non Chinese speakers in a room, just use pieces of paper to construct Chinese words\n",
       "    - Doesn't mean speakers know Chinese and it's the same for Machines\n",
       "    - Biological Naturalism -> Low level physical process neurons, are the key for high level emergent features\n",
       "        - So for a human what Neuron is, transistors is nor for Machines\n",
       "- Consciousness and Qualia\n",
       "    - Issue of Consciousness -> awarness of outside world, self and subjective living experience\n",
       "    - Qualia is technical term for intrinsic nature of experiences\n",
       "\n",
       "\n",
       "## AIMA 2.1 Agents and Environments\n",
       " \n",
       "- Agent pereceive its environment via sensors and act using actuators\n",
       "- Agent Function maps any given percepts to actions. It's an abstract mathematical desc\n",
       "- Agent Program is conremet implementation running within some physical systems\n",
       "- Agent Function will be implemented by Agent Program\n",
       "\n",
       "\n",
       "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
       " \n",
       " - Performance Measures:\n",
       "     - Conseuqnetialism\n",
       "     - Need to build agent such that it goes with uncertaininty and learns as it goes by\n",
       " - Rationality :\n",
       "    - Performance measures the adefines success criteria, agent's prior environemnt knowledge,\n",
       "        actions that agent perform, agent's percetps\n",
       "    - Priori is the gegoraphy of environment\n",
       " - Omniscience, learning and autonomy:\n",
       "    - Omniscient agends knows actual outcome and it acts accordinly, but not possible in reality\n",
       "    - Rationality maximizes the expected performance\n",
       "    - Perfection maximuzes actual performance\n",
       "    - Information Gathering -performing action so as to modify future percepts\n",
       "    - Lacking Autonomy - Agent's prior knowledge is from designer\n",
       "\n",
       "\n",
       "## AIMA 2.3 The Nature of Environments\n",
       " \n",
       "- Task Environment: Performance, Environment, Actuators, Sensors\n",
       "- FUlly vs Partially Observable\n",
       "- Single vs Multiple Agent\n",
       "- Deterministic vs Non Deterministic\n",
       "- Static vs Dynamic\n",
       "- Discrete vs Continous\n",
       "- Knowns vs Unknown\n",
       "\n",
       "\n",
       "## AIMA 2.4 The Structure of Agents\n",
       " \n",
       "- Agent = Agent Architecture (running on device) + Agent Program (which implements agent function)\n",
       "- Agent Programs:\n",
       "    - -----\n",
       "- Simple Reflex Agents:\n",
       "- Model Based reflex agents:\n",
       "- Goal based agents\n",
       "\n",
       "\n",
       "## Module 1 Lecture Notes\n",
       " \n",
       "\n",
       "\n",
       "## Module 1 Definitions\n",
       "* **Agent** - anything that can perceive and act in an environment\n",
       "\n",
       "\n",
       "# Module 2: Python\n",
       "## Module 2 Lecture Notes\n",
       " \n",
       "- Strings are immutable\n",
       "- Lists are mutable \n",
       "- Sequence Types --> Tuples, List, String\n",
       "- Advantage of Generators:\n",
       "    - Less code than iterator\n",
       "    - maintains the local state automatically\n",
       "    - One at a time values are computed\n",
       "    - Good for agg and crucial for infite sequence\n",
       "    - Not good for inspecting indivudal values\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",
       " \n",
       "- FOUR PHASE PROBLEM SOLVING PROCESS --> Goal Formation, Problem Formulation, Serach & Execution\n",
       "- OPEN LOOP - Known environemnt and deterministic\n",
       "- CLOSED LOOP - Environment is non deterministic\n",
       "- Branching strategy is used in Partially observable and non-deterministic environements\n",
       "\n",
       "## AIMA Chapter 3.2 Example Problems\n",
       " \n",
       "<b> a) Standardized Problems: </b>\n",
       " - This is the benchmar for reserachers to compare algorithms\n",
       "\n",
       "<b> b) Real World Problems: </b>\n",
       " - Examples are Route Finding Problems, Touring Proble, VLSI Layout, robot navigation, Automatic assembly sequencing\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.3 Search Algorithms\n",
       " \n",
       "\n",
       "i) Best First Search:\n",
       "    - Proceeds with the minimum value of an evaulaton function\n",
       " \n",
       "ii) Redundant Paths:\n",
       "    - Algorithm are doomed, if they can't remember past\n",
       "    - 3 Approaches:\n",
       "        - Remember the previous state ( works if state space fits in memory). We call search algorithm here \"Graph Search\"\n",
       "        - Don't worry about prevous state and the sequence doesn't allow ( eg., assemblage). Since it doesn's \n",
       "            check this we can this as \"tree-like search\"\n",
       "        - Compromise and check for cylcles, but not for redundtant path in genral\n",
       "\n",
       "iii) Measuring Problem solving performance:\n",
       "\n",
       " - Completetness, cost Optimality, time & space complexity\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
       " \n",
       "- BFS:\n",
       "   - when all options have same cost and cost optimal in this case\n",
       "   - Complete even on infinted spaces\n",
       "   - FIFO Queue\n",
       "   - Early Goal Test - To check if a node is a solution as soon as it is genered\n",
       "   - Late Goal Test -wait unti a node is popped off the queue\n",
       "   - Space Complexity = O(b^d)\n",
       "- DFS:\n",
       " - Implemented not as a graph search but tree like search\n",
       " - It is not cost optimal\n",
       " - Retruns first solution though it isn't cheapers\n",
       " - Efficient and complete for fintie spaces\n",
       " - Stuck in loop for cyclic state spaces\n",
       " - Incomplete for infinitee spaces\n",
       " - Memory is small for problesm where tree like search is possible\n",
       " - Memory complexity is O(bm)\n",
       "- Depth Limited search\n",
       " - Just to keep DFS from wandering inifited path\n",
       " - Time complesit is O(b^l)\n",
       "- Iterative deepening:\n",
       " - Does a good job of picking good value of l for the above\n",
       " - Time complexity is O(b^m)\n",
       "- Bidirectional search\n",
       "\n",
       "\n",
       "## Module 3 Lecture Notes\n",
       " \n",
       "- Relfect Agent: It takes only the current percets and select actions accordingly\n",
       "- Problem Solving Agend: It has a goal in mind and does a seuence of action\n",
       "- Task Evironment:\n",
       "    - Fully Observable, deterministic and known environment (Solution is fixed sequence of actions)\n",
       "    - Partially observable and non deterministic (Branching Strategy)\n",
       "- Basic Serch Algorithm:\n",
       "    - Tree Search ( Problem is repeated states with exponentail cost in many cases)\n",
       "    - Graph Search - its an enhancement of above where we trace the visited nodes\n",
       "- Un-informed (Blind search) serach strategies - all non-goal nodes in the frontier looks equally good:\n",
       "    - Strategy is finding the order of expansion like using LIFO, FIFI or priority queue\n",
       "    - Completenes indicates if we find solution always\n",
       "    - <b> BFS </b>\n",
       "        - FIFO Frontier, complete if b is finite, O(b^2) time and space complexity, optimal if cost=1\n",
       "        - Use when space is restricted\n",
       "    - <b> DFS </b>\n",
       "        - LIFO, not complete in infitine depth, O(b^m) time and O(b*m) space and not optimal\n",
       "        - Use when possible finite paths\n",
       "    - <b> Depth Limited Search </b>\n",
       "    - <b> Iterative Deepening Search </b>\n",
       "- Informed Serarch - Some non-goal states can be ranke above others\n",
       "\n",
       "## Module 3 Definitions\n",
       "* **Search** - It is the process of finding sequence of actions\n",
       "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
       "* **Search probkem** - States, initial state, goal states, action, trasition model, action cost function\n",
       "* **State space** - Its the set of all possible states in an environment\n",
       "* **Transition model** - It describes what each action does\n",
       "* **Path** - Sequence of actions\n",
       "* **Solution** - Path from initial to goal state\n",
       "* **Model** - Formulation of Problem\n",
       "* **Complete & optimal cost** - BFS, Uinform COst, Iterative Deeepning, Bi-directional\n",
       "* **Time complexity** - BFS [O(b^d)] , DFS [O(b^m)]\n",
       "\n",
       "\n",
       "# Module 4: Informed Search\n",
       "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
       " The discuss here is in GBFS and how it uses only h(n), whereas A* uses g(n) + h(n) Terms such as consistency and triangle inequality were discussed as a property of admissable heuristic Unfiform cost secrch has circulat contour In A* f = h + g doesn't gaurantee a montonic increase in cost path A* search is complet and cost optimal usally, but ain't the answer for all\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.6 Heuristic Functions\n",
       " \n",
       "-  \n",
       "\n",
       "\n",
       "## Module 4 Lecture Notes\n",
       " \n",
       "- Uniform Cost Search(UCS) is a search tree algorithm on weighted graph \n",
       "- UCS name is confusing and it doens't imply the same \n",
       "- UCS uses priority queue path cost g(N), i.e., how much its gonna cost between nodes \n",
       "- g(N) will increase as we expand the path\n",
       "- UCS doesn't know goal upfront as it uses priority queue and goes with less cost\n",
       "----\n",
       "- Hence we go for informed search using heuristic functions\n",
       "- Informed serach agorithms - Greedy-best first serach and A*\n",
       "- we use Path Cost g(N), evaluation function f(N)\n",
       "- Heurustic functon h(N) makes the best guess from that state to the goal\n",
       "- We want to underestimate this value\n",
       "----\n",
       "- Greedy Best First search uses priority gues and based on h(n) ( distance from goal) values it adds the value to the priority quere\n",
       "- It isn't optimal if there is an obstacle\n",
       "- it is not comlete either as it's not gauranteted to find solution everytime and can go in loops\n",
       "- GBFS search is complete in finite sapce\n",
       "- Asymptotic worst case time compexity O(|V|)\n",
       "\n",
       "----\n",
       "- A* is a knwon form of GBFS. It uses the positive of UCS + GBFS\n",
       "- The heurustic function is h(n) + g(n)\n",
       "- It might explore more than GBFS, but gaurantee to get to best solution\n",
       "\n",
       "- Memory Bound Search\n",
       "  - Reference Count\n",
       "  - Beam Search - \n",
       "  - Iterative- deepening A* Search ( IDA*) \n",
       "  - Recursive BFS\n",
       "- Bidirectional Heuristic Search\n",
       "\n",
       "\n",
       "## Module 4 Definitions\n",
       "* **Relaxed problem** - Problem with fewere restrictions on the actions than original\n",
       "* **Triange inequality** - A side of the triangle can't ge greater than the sum of other two sides\n",
       "* **Beam search** - Limits the size of the frontier.It keeps only k nodes with best f scores, hence it is incomplete and suboptimatl.\n",
       "* **Weighted a*** - it expands fewere nodes but sacrifices optimality\n",
       "\n",
       "\n",
       "# Module 5: Adversarial Search and Games\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " deterministic, 2 players, tun taking, perfect information, zer- sum games. initial state, to-move, actions,results,is-termina,utility \n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       " Min max if depth is m and b moves, then it peforms DFS  and hence time complexity is O(b^m). Space complexity is O(bm) Impractical for complex gamesWith move order we can achieve a best complexity of O(b^(m/2))\n",
       "\n",
       "- Move ordering for alpha bete minimax prunining\n",
       "- Type A Strategy - explores Wide but shallow portion of tree (chess)\n",
       "- Type B Strategy - explores deep but narrow portion of tree (go)\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",
       " \n",
       "- P(S'|s,a) --> Probabilty that actiion a in state s reaches state S'\n",
       "- Utility function captures agents prefernces\n",
       "- Expected Utility - avg utiity values of outcomes, witghed by prob that the outcome occurs\n",
       "- Maximum expected utilitu ( MEU) - Choosing an action which maximises agent's expected utility\n",
       "\n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " \n",
       "- Constraints on rational preferences\n",
       "- 6 Constraints:\n",
       " - Orderability\n",
       "     - Agent can't avoid choosing and need to chose one or other, Like A or B\n",
       " - Transitivity\n",
       "    - A to B and B to C, then A to C\n",
       " - Continuity\n",
       "     - B in between A and C prefernce\n",
       " - Sustainibilty\n",
       "     - Agent is indfferent between 2 lotteries\n",
       " - Monotonicity\n",
       "     - same two possible outcomes\n",
       " - Decomposibilty\n",
       "     - no fun in gambling\n",
       "\n",
       "- Rational Preference leads to utility\n",
       "\n",
       "    - Existence of untility functions:\n",
       "        - Follows of axioms of utility  and there exists function U where U(A) > U(B) and iff A is preferred to B and U(A) = U(B)\n",
       "    - Expected Utility of a lottery:\n",
       "        - \n",
       "\n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " \n",
       "\n",
       "## Module 5 Lecture Notes\n",
       "  \n",
       "\n",
       "## Module 5 Definitions\n",
       "* **Concept** - definition\n",
       "* **Preference elicitation** - Working with human's untitlity function\n",
       "* **Certainitly equivalent** - Value of agenet will accept in lieu of lottery\n",
       "* **Insurance premium** - Diff between EMV of lottery and its certainty equivalent\n",
       "* **Neutral curve** - Agent having a linear curve\n",
       "* **Optimizers curve** - Tendencey for estimated EU of the best choice to be too high\n",
       "* **Normative theory** - Describes how a Rational Agent should be\n",
       "* **Descriptive theory** - How actual agents act\n",
       "* **Framing effect** - Exact wording of decision problem can have a big impact on the agent choice\n",
       "* **Anchoring effect** - Reative over absolute judgemet\n",
       "\n",
       "\n",
       "# Module 6: Constraint Satisfaction Problems\n",
       "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
       " \n",
       "- 3 Components --> Set of Variables, Domains and Constraints\n",
       "- CSK deals with the variables assignments\n",
       "- Solving CSP is a NP Complete problem\n",
       "- Example 1: Map Coloring\n",
       "- Example 2: Job Shop Scheduling\n",
       "- Examples of Types of constraints --> Precedences Constrain & disjunctive constraint\n",
       "- Map coloring, scheduling & 8-queens are examples of discrete & finite domains\n",
       "- In the case of infinite domains, implicit constains (such as T1 + d1 <= T2) should be used than explitic tuples values\n",
       "- Linear Programming Problems are examples of continous domains\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
       " Local consistency, node consistency, arc consistency, path consistency, k-consistenct, global constraints\n",
       "- Path consistelcy: in case of unary domain this does by looking at triples of variables\n",
       "- K Consistent - If for any set k-1 variables, consistent value can always be assigned to kth variable. Run time O(n^2d)\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",
       " \n",
       "- It uses complete-state forumation, wherein each states assigns value to every variable\n",
       "- It violates constraitns for sure, but we do reassignment in next steps which close to the solution - min-conflicts heuristics\n",
       "- Plataeau search allows the movement to another state with same score\n",
       "- Wandering of plateau is dorected with Tab Search technique, whick keeps small set of recently visited nodes and make sure it is not \n",
       "visited again\n",
       "-\"Constrain Weighting\" is yet anothe technique , where it aims to search the important constraints\n",
       "- Local search example is flight scedule \n",
       "\n",
       "## AIMA Chapter 6.5 The Structure of Problems\n",
       " \n",
       "- Make sure we deal the problem as independent sub problems\n",
       "- Directional Arc Consistency - iff every Xi are Arc Conssitent with Xj for j > i\n",
       "\n",
       "\n",
       "## Module 6 Lecture Notes\n",
       " \n",
       "- So for we are trying to do a search to formulate a plan \n",
       "- Instread of planning for sequence of action, we identify the problem in CSP\n",
       "- in A* we used knowledge of world, here in CSP has the knowledge about constrains\n",
       "- CSP consists of set of variables, domains, finite set of the constraints\n",
       "- If the variables doesn't violate constrains, then it's consistent\n",
       "- AllDiff is a global constraint\n",
       "- Preferance Constraints\n",
       "\n",
       "## Module 6 Definitions\n",
       "* **Concept** - definition\n",
       "\n",
       "\n",
       "# Module 7: Logical Agents\n",
       "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
       " \n",
       "- KB is the central component of KB agent\n",
       "- KB = set of sentances\n",
       "- Each sentance in the KB is expressed in Knowledge representation language and some assertions\n",
       "- Axiom is a sentance without derived from other sentance\n",
       "- Inference is dervingh sentance from another\n",
       "- TELL --> adding new sentance, ASK --> querying\n",
       "- Three things done by KB agent when called --> TELLS KB what it perceives, ASK KB what to perform, TELLS KB which action was chosen\n",
       "- Knowledge Level (specify only what agend needs) vs Implementaion Level\n",
       "- Declarative  (Startin with empty knowlege designed TELLS one by one) vs Procedural approach (as program code)\n",
       "- Best is the mix of both Declrarive and procedureal approach\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.2 The Wumpus World\n",
       " \n",
       " - Performance Measure, Environment, Actuators, Sensors\n",
       "\n",
       "## AIMA Chapter 7.3 Logic\n",
       " \n",
       "- Logic defines semantics or meanring of a sentance\n",
       "- Semantics in turn definds the truth of each sentence to each possible word\n",
       "- When precision is needed, we used \"Model\" instead of possible world.\n",
       "- If a sentance alpha is true in model \"m\", then we say\n",
       "    - m satisifes alpha (or)\n",
       "    - m is a model of alpha\n",
       "- logical entailment between sentances - i.e. sentence follows logically from other sentences\n",
       "- Entailment is like needle being in the haystack, whereas inference is finding it\n",
       "- Sound/Truth preserving is an inference algorthim that determines only entailed sentences\n",
       "- Inference is alg is complete only when it can derive sentences that is entailed\n",
       "- Grounding is the connection between logical reasoning & real ennvironment in which agent exits\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
       " \n",
       "- Atomis sentances consists of a single proposition symbol\n",
       "- Syntax\n",
       "- Semantics\n",
       "\n",
       "\n",
       "\n",
       "## AIMA 7.5 Propositional Theorem Proving\n",
       " \n",
       "- If nbr of models is large , but lenght of proof is short => Theoram proving more efficient than model chekcing\n",
       "- Concepts:\n",
       "    - Logical Equivalence -> 2 sentances if true in same set of models\n",
       "    - Validity ( Tautologies -> valid sentances) - If sentance true in all models\n",
       "    - Satisfiability -> a sentances true in or satisified by some model\n",
       "Inference and proof:\n",
       " - Modus Ponens Rule --> (alpha => beta, alpha) / beta ( here beta is inferred given the numerator)\n",
       " - And-Elimination Rule --> From a conjunction, any of the conjunction can be inferred --> (Alpha and Beta) / Alpha\n",
       "- Monotonicity - set of entailed sentances can only increase in as informaton added to KB\n",
       "Proof by Resolution:\n",
       " - Single inference rule which yields a complete inference algorithm when coupled with any seach algorithm\n",
       " - Factoring: The remove of multiple copies of literals  \n",
       " - Ground Resolution Theoram - Completeness theoram for resultion in propositional logic\n",
       "Horn & Definite clauses:\n",
       " - Disjunction of literals of which exactly 1 is posiitve is called definite clause\n",
       " - Horn Clause - Disjunction of literals of which atmost 1 is posiitve\n",
       "     - Premise is body, conclusion is head\n",
       " - Fact : Sentance with single positive literal\n",
       "Forward and Backward Chaining: (for knowledge bases in Horn Form)\n",
       "    - Sound & complete\n",
       "    - Sound Inferecne algorothom derives only sentacnes that are entailed, wherase complete derives all sentances\n",
       "    - Backword chaining is a form of goal-directed reasoning \n",
       "\n",
       "\n",
       "## Module 7 Lecture Notes\n",
       " Your summary here \n",
       "\n",
       "## Module 7 Definitions\n",
       "* **Concept** - definition\n",
       "* **Commutative of and** - (alpha and beta) === (beta and alpha)\n",
       "* **Commutative of or** - (alpha or beta) === (beta or alpha)\n",
       "* **Associative of and** - ((alpha and beta) and gamma) === (alpha and (beta and gamma))\n",
       "* **Associative of or** - ((alpha or beta) or gamma) === (alpha or (beta or gamma))\n",
       "* **Double negation elimination** - not (not alpha) === alpha\n",
       "* **Contraposition** - (alpha => beta) === (not Beta => not alpha)\n",
       "* **Implication elimination** - (alpha => beta) === (not alpha or beta)\n",
       "* **Biconditional elimination** - (alpha <=> beta) === ((alpha => beta) and (beta => alpha))\n",
       "* **Demorgan** - not(alpha or beta) === ( not alpha and not beta)\n",
       "* **Distribute of and over or** - (alpha and ( beta or gamma)) === ((alpha and beta) or (alpha and gamma))\n",
       "* **Distribute of or over and** - (alpha or ( beta and gamma)) === ((alpha or beta) and (alpha or gamma))\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "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))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
