{
  "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 materials 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": "d01fdeb4-e282-46e5-87b6-3080fa265372"
      },
      "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": "56ea8ff3-fbd2-44e2-c158-864a9c0fe18e"
      },
      "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": 3,
      "metadata": {
        "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": [],
      "source": [
        "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
        "\n",
        "chapter1_1 = \"\"\"\n",
        "\\n AI can be defined with two dimensions (human vs. rational and thought vs. behavior) which leads to 4 approaches.\n",
        "\\n 6 main disciplines of AI are NLP, knowledge rep., auto. reasoning, ML, computer vision, and robotics.\n",
        "\\n 3 ways to learn about human thought are introspection, psychological experiments, and brain imaging.\n",
        "\\n Turing test needs NLP, knowledge rep, automated reasoning, ML. Total Turing test additionally needs computer vision, robotics.\n",
        "\\n We rarely know true facts of the world, so probability allows for rigorous reasoning with uncertain info. However, it cannot generate intelligent behavior by itself.\n",
        "\\n Rational agent doesn't just use inferences, is more general/broad. Essentially, do the right thing, according to the current objective.\n",
        "\"\"\" \n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
        "chapter27_1 = \"\"\"\n",
        "\\n Originally weak vs strong AI. Then definition shifted to general vs human-level AI. \n",
        "\\n The only thing programs aren't able to do is to be exactly human.\n",
        "\\n Humans can be wrong too, disproving the Godel's incompleteness theorem. Just because humans and machines can be wrong doesn't mean they can't still adapt and change, or be useful in the first place.\n",
        "\\n Most AI researchers care more about making AI excel at specific games/tasks rather than make them act human in all aspects.\n",
        "\"\"\"\n",
        "chapter27_2 = \"\"\"\n",
        "\\n Polite convention to not worry about simulation or actual thinking/abilities.\n",
        "\\n Chinese room argument is that the human in the room translating Chinese and a program translating Chinese has no true understanding of it.\n",
        "\\n Searle is a proponent of biological naturalism, claiming mental states stem from properties in neurons that machines do not have. Same argument could be used against people and cells though...\n",
        "\\n Strong AI debate is all about consciousness (awareness of outside world, self and living). Can machines have qualia (intrinsic nature of experiences)? Similar questions about animals.\n",
        "\\n Behaving intelligently will require some awareness, and machines interacting with humans need human subjective experience. Machines can't experience it themselves, but they can run others' code.\n",
        "\"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
        "chapter2_1 = \"\"\"\n",
        "\\n We mostly use rational agents.\n",
        "\\n Agent's choice of action depends on built-in knowledge and percept sequence, but not anything it hasn't seen/experienced/sensed yet.\n",
        "\"\"\"\n",
        "chapter2_2 = \"\"\"\n",
        "\\n Humans have desires and preferences, machines don't, so rationality is associated with humans' POV.\n",
        "\\n Generally, it's better to design performance measures according to desired end environment result, not how you think the agent should act (or else vacuum robot would just dump and clean dirt over and over).\n",
        "\\n Rational depends on 4 things: performance measure, agent's prior knowledge of environment, agent's possible actions, agent's percept sequence until now. For possible percept sequence, rational agent should select performance measure maximizing action, given info from percept sequence and build-in knowledge.\n",
        "\\n Ration does NOT equal perfection. Things can still go wrong, unless you are omniscient, which no one is. Rationality maximizes expected performance, perfection maximizes actual performance.\n",
        "\\n Ration agent should learn as much as it can, aka gain information from environment.\n",
        "\\n Autonomous rational agents are way better than non-autonomous.\n",
        "\"\"\"\n",
        "chapter2_3 = \"\"\"\n",
        "\\n Other agents can be recognized if they are maximizing a performance measure whos value depends on our agent's behavior.\n",
        "\\n Randomized behavior can be rational in some multiagent environments.\n",
        "\"\"\"\n",
        "chapter2_4 = \"\"\"\n",
        "\\n agent = architecture + program.\n",
        "\\n Agent program takes in current percept and returns an action. Agent function may depend on entire percept history.\n",
        "\\n Impossible to encode lookup table in reality. Key challenge in AI is to produce rational behavior from small program rather than vast table.\n",
        "\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module1_lecture_notes = \"\"\" Your summary here \"\"\"\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",
        "\"rationality\" : \"doing the right thing\",\n",
        "\"Turing test\" : \"if a human consistently can't tell if an answerer is a human or computer\",\n",
        "\"NLP\" : \"understand human language\",\n",
        "\"knowledge representation\" : \"remember things\",\n",
        "\"automated reasoning\" : \"answer questions, draw conclusions\",\n",
        "\"machine learning\" : \"adapt to new situations, detect + extrapolate patterns\",\n",
        "\"total Turing test\" : \"turint test + interact with environment\",\n",
        "\"computer vision\" : \"perceive the world\",\n",
        "\"robotics\" : \"move stuff and self\",\n",
        "\"introspection\" : \"self-aware about thoughts\",\n",
        "\"psychological experiments\" : \"seeing people in action\",\n",
        "\"brain imaging\" : \"seeing brain in action\",\n",
        "\"cognitive science\" : \"combine AI and psychology to make theories about human mind\",\n",
        "\"syllogisms\" : \"deductive reasoning from given premises. led to field called logic\",\n",
        "\"logicist\" : \"philosophy. way to label rigorous statements about objects in the world\",\n",
        "\"probability\" : \"allows for uncertainty in logic models\",\n",
        "\"agent\" : \"anything that can perceive and act in an environment\",\n",
        "\"rational agent\" : \"an approach to AI. an agent that acts to get the best possible outcome (if uncertain, the best expected outcome).\",\n",
        "\"laws of thought\" : \"an approach to AI that emphasized correct inferences\",\n",
        "\"limited rationality\" : \"impossible to calculate true rationality, so we do our best\",\n",
        "\"perfect rationality\" : \"good for theory, but mostly impossible in complex environments\",\n",
        "\"value alignment problem\" : \"difficult to fully convey our true goals/objectives to a machine\",\n",
        "\"provably beneficial\" : \"we want agents that help humans and don't relentlessly pursue objectives (could have very negative consequences)\",\n",
        "\n",
        "\"weak AI\" : \"machines act as if they were intelligent\",\n",
        "\"strong AI\" : \"machines are consciously thinking not just simulating thinking\",\n",
        "\"GOFAI\" : \"good old-fashioned AI (criticized because difficult to capture set guaranteed logic in rules)\",\n",
        "\"qualification problem\" : \"difficulty of describing all possible proper behavior in a set of logical rules\",\n",
        "\"embodied cognition\" : \"brain is connected to body which is in an environment when decision making\",\n",
        "\n",
        "\"sensor\" : \"things to sense with\",\n",
        "\"actuator\" : \"things to act with\",\n",
        "\"environment\" : \"the surroundings we care about when designing the agent\",\n",
        "\"percept\" : \"content that agents' sensors are perceiving\",\n",
        "\"percept sequence\" : \"history of all percepts the agent has ever had\",\n",
        "\"agent function\" : \"abstract mathmatical concept, maps any given percept sequence to an action\",\n",
        "\"agent program\" : \"concrete implementation that implements an agent function\",\n",
        "\"consequentialism\" : \"evaluate agent's behavior by consequences\",\n",
        "\"performance measure\" : \"evaluates given sequence of environment states\",\n",
        "\"omniscience\" : \"knowing actual outcome of actions\",\n",
        "\"information gathering\" : \"actions to modify future percepts, helps rationality, ex. exploration\",\n",
        "\"autonomy\" : \"how much agent needs to rely on prior knowledge rather than own percepts and learning\",\n",
        "\n",
        "\"task environment\" : \"problem agent must solve\",\n",
        "\"PEAS\" : \"performance, environment, actuators, sensors make up the task environment\",\n",
        "\"software agent/softbot\" : \"agents operating in virtual environment\",\n",
        "\"fully observable\" : \"total access to complete state of environment\",\n",
        "\"partially observable\" : \"some access to complete state of environment\",\n",
        "\"unobservable\" : \"no access to complete state of environment, because agent has no sensors\",\n",
        "\"single-agent\" : \"only 1 agent involved (self)\",\n",
        "\"competitive multi-agent\" : \"more than 1 agent involved, performance measure makes them compete against each other\",\n",
        "\"cooperative multi-agent\" : \"more than 1 agent involved, performance measure makes them cooperate with each other\",\n",
        "\"deterministic\" : \"next environment state is fully determined by current state and agent action\",\n",
        "\"non-deterministic\" : \"next environment state is not fully determined by current state and agent action\",\n",
        "\"stochastic\" : \"mostly synonym for non-deterministic, but more specifically if model explicitly has probabilities listed\",\n",
        "\"episodic\" : \"next episode does not depend on actions in previous episodes. easy, don't need to think ahead\",\n",
        "\"sequential\" : \"current decision can affect all future decisions. ex. chess, driving\",\n",
        "\"static\" : \"environment doesn't change while agent is thinking\",\n",
        "\"dynamic\" : \"environment does change while agent is thinking\",\n",
        "\"semidynamic\" : \"environment doesn't change while agent is thinking but performance score does\",\n",
        "\"discrete\" : \"finite states, percepts, actions. ex: chess\",\n",
        "\"continuous\" : \"continuous states, time, actions. ex: driving\",\n",
        "\"known\" : \"knows about physics of environment, outcomes for actions are given\",\n",
        "\"unknown\" : \"have to learn about how environment works to make good decisions\",\n",
        "\"environment class\" : \"many environents pulled for experimentation\",\n",
        "\"agent architecture\" : \"the physical part of an agent\",\n",
        "\"simple reflex agents\" : \"select action on current percept only. use if-then rules. randomization can help break infinite loops\",\n",
        "\"model-based reflex agents\" : \"maintain internal state/best guess of part of the world it can't see now. need transition and sensor model\",\n",
        "\"transition model\" : \"how world works physically\",\n",
        "\"sensor model\" : \"how world affects percepts\",\n",
        "\"goal-based agents\" : \"actions with specific goal in mind, better long-term/more customizable than reflex\",\n",
        "\"utility-based agents\" : \"internal (expected) utility function represents performance measure, tries to identify best way of getting to goal\",\n",
        "\"model-free agent\" : \"can learn best actions without learning exactly how action changes environment\",\n",
        "\"learning element\" : \"making improvements\",\n",
        "\"performance element\" : \"selecting external actions\",\n",
        "\"critic\" : \"judges learning element by performance standard\",\n",
        "\"problem generator\" : \"suggesting new approaches to improve over time (evolution, experimentation)\",\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": 1000
        },
        "id": "gYYeNcdM_maE",
        "outputId": "0dcd455f-8705-409c-efd9-3445c6c13112"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 1: Rational Agents and Task Environments\n",
              "## AIMA Chapter 1.1 What is AI?\n",
              "\n",
              "\n",
              " AI can be defined with two dimensions (human vs. rational and thought vs. behavior) which leads to 4 approaches.\n",
              "\n",
              " 6 main disciplines of AI are NLP, knowledge rep., auto. reasoning, ML, computer vision, and robotics.\n",
              "\n",
              " 3 ways to learn about human thought are introspection, psychological experiments, and brain imaging.\n",
              "\n",
              " Turing test needs NLP, knowledge rep, automated reasoning, ML. Total Turing test additionally needs computer vision, robotics.\n",
              "\n",
              " We rarely know true facts of the world, so probability allows for rigorous reasoning with uncertain info. However, it cannot generate intelligent behavior by itself.\n",
              "\n",
              " Rational agent doesn't just use inferences, is more general/broad. Essentially, do the right thing, according to the current objective.\n",
              "\n",
              "\n",
              "## AIMA Chapter 27.1 The Limits of AI\n",
              "\n",
              "\n",
              " Originally weak vs strong AI. Then definition shifted to general vs human-level AI. \n",
              "\n",
              " The only thing programs aren't able to do is to be exactly human.\n",
              "\n",
              " Humans can be wrong too, disproving the Godel's incompleteness theorem. Just because humans and machines can be wrong doesn't mean they can't still adapt and change, or be useful in the first place.\n",
              "\n",
              " Most AI researchers care more about making AI excel at specific games/tasks rather than make them act human in all aspects.\n",
              "\n",
              "\n",
              "## AIMA Chapter 27.1 Can Machines Really Think?\n",
              "\n",
              "\n",
              " Polite convention to not worry about simulation or actual thinking/abilities.\n",
              "\n",
              " Chinese room argument is that the human in the room translating Chinese and a program translating Chinese has no true understanding of it.\n",
              "\n",
              " Searle is a proponent of biological naturalism, claiming mental states stem from properties in neurons that machines do not have. Same argument could be used against people and cells though...\n",
              "\n",
              " Strong AI debate is all about consciousness (awareness of outside world, self and living). Can machines have qualia (intrinsic nature of experiences)? Similar questions about animals.\n",
              "\n",
              " Behaving intelligently will require some awareness, and machines interacting with humans need human subjective experience. Machines can't experience it themselves, but they can run others' code.\n",
              "\n",
              "\n",
              "## AIMA 2.1 Agents and Environments\n",
              "\n",
              "\n",
              " We mostly use rational agents.\n",
              "\n",
              " Agent's choice of action depends on built-in knowledge and percept sequence, but not anything it hasn't seen/experienced/sensed yet.\n",
              "\n",
              "\n",
              "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
              "\n",
              "\n",
              " Humans have desires and preferences, machines don't, so rationality is associated with humans' POV.\n",
              "\n",
              " Generally, it's better to design performance measures according to desired end environment result, not how you think the agent should act (or else vacuum robot would just dump and clean dirt over and over).\n",
              "\n",
              " Rational depends on 4 things: performance measure, agent's prior knowledge of environment, agent's possible actions, agent's percept sequence until now. For possible percept sequence, rational agent should select performance measure maximizing action, given info from percept sequence and build-in knowledge.\n",
              "\n",
              " Ration does NOT equal perfection. Things can still go wrong, unless you are omniscient, which no one is. Rationality maximizes expected performance, perfection maximizes actual performance.\n",
              "\n",
              " Ration agent should learn as much as it can, aka gain information from environment.\n",
              "\n",
              " Autonomous rational agents are way better than non-autonomous.\n",
              "\n",
              "\n",
              "## AIMA 2.3 The Nature of Environments\n",
              "\n",
              "\n",
              " Other agents can be recognized if they are maximizing a performance measure whos value depends on our agent's behavior.\n",
              "\n",
              " Randomized behavior can be rational in some multiagent environments.\n",
              "\n",
              "\n",
              "## AIMA 2.4 The Structure of Agents\n",
              "\n",
              "\n",
              " agent = architecture + program.\n",
              "\n",
              " Agent program takes in current percept and returns an action. Agent function may depend on entire percept history.\n",
              "\n",
              " Impossible to encode lookup table in reality. Key challenge in AI is to produce rational behavior from small program rather than vast table.\n",
              "\n",
              "\n",
              "## Module 1 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 1 Definitions\n",
              "* **Rationality** - doing the right thing\n",
              "* **Turing test** - if a human consistently can't tell if an answerer is a human or computer\n",
              "* **Nlp** - understand human language\n",
              "* **Knowledge representation** - remember things\n",
              "* **Automated reasoning** - answer questions, draw conclusions\n",
              "* **Machine learning** - adapt to new situations, detect + extrapolate patterns\n",
              "* **Total turing test** - turint test + interact with environment\n",
              "* **Computer vision** - perceive the world\n",
              "* **Robotics** - move stuff and self\n",
              "* **Introspection** - self-aware about thoughts\n",
              "* **Psychological experiments** - seeing people in action\n",
              "* **Brain imaging** - seeing brain in action\n",
              "* **Cognitive science** - combine AI and psychology to make theories about human mind\n",
              "* **Syllogisms** - deductive reasoning from given premises. led to field called logic\n",
              "* **Logicist** - philosophy. way to label rigorous statements about objects in the world\n",
              "* **Probability** - allows for uncertainty in logic models\n",
              "* **Agent** - anything that can perceive and act in an environment\n",
              "* **Rational agent** - an approach to AI. an agent that acts to get the best possible outcome (if uncertain, the best expected outcome).\n",
              "* **Laws of thought** - an approach to AI that emphasized correct inferences\n",
              "* **Limited rationality** - impossible to calculate true rationality, so we do our best\n",
              "* **Perfect rationality** - good for theory, but mostly impossible in complex environments\n",
              "* **Value alignment problem** - difficult to fully convey our true goals/objectives to a machine\n",
              "* **Provably beneficial** - we want agents that help humans and don't relentlessly pursue objectives (could have very negative consequences)\n",
              "* **Weak ai** - machines act as if they were intelligent\n",
              "* **Strong ai** - machines are consciously thinking not just simulating thinking\n",
              "* **Gofai** - good old-fashioned AI (criticized because difficult to capture set guaranteed logic in rules)\n",
              "* **Qualification problem** - difficulty of describing all possible proper behavior in a set of logical rules\n",
              "* **Embodied cognition** - brain is connected to body which is in an environment when decision making\n",
              "* **Sensor** - things to sense with\n",
              "* **Actuator** - things to act with\n",
              "* **Environment** - the surroundings we care about when designing the agent\n",
              "* **Percept** - content that agents' sensors are perceiving\n",
              "* **Percept sequence** - history of all percepts the agent has ever had\n",
              "* **Agent function** - abstract mathmatical concept, maps any given percept sequence to an action\n",
              "* **Agent program** - concrete implementation that implements an agent function\n",
              "* **Consequentialism** - evaluate agent's behavior by consequences\n",
              "* **Performance measure** - evaluates given sequence of environment states\n",
              "* **Omniscience** - knowing actual outcome of actions\n",
              "* **Information gathering** - actions to modify future percepts, helps rationality, ex. exploration\n",
              "* **Autonomy** - how much agent needs to rely on prior knowledge rather than own percepts and learning\n",
              "* **Task environment** - problem agent must solve\n",
              "* **Peas** - performance, environment, actuators, sensors make up the task environment\n",
              "* **Software agent/softbot** - agents operating in virtual environment\n",
              "* **Fully observable** - total access to complete state of environment\n",
              "* **Partially observable** - some access to complete state of environment\n",
              "* **Unobservable** - no access to complete state of environment, because agent has no sensors\n",
              "* **Single-agent** - only 1 agent involved (self)\n",
              "* **Competitive multi-agent** - more than 1 agent involved, performance measure makes them compete against each other\n",
              "* **Cooperative multi-agent** - more than 1 agent involved, performance measure makes them cooperate with each other\n",
              "* **Deterministic** - next environment state is fully determined by current state and agent action\n",
              "* **Non-deterministic** - next environment state is not fully determined by current state and agent action\n",
              "* **Stochastic** - mostly synonym for non-deterministic, but more specifically if model explicitly has probabilities listed\n",
              "* **Episodic** - next episode does not depend on actions in previous episodes. easy, don't need to think ahead\n",
              "* **Sequential** - current decision can affect all future decisions. ex. chess, driving\n",
              "* **Static** - environment doesn't change while agent is thinking\n",
              "* **Dynamic** - environment does change while agent is thinking\n",
              "* **Semidynamic** - environment doesn't change while agent is thinking but performance score does\n",
              "* **Discrete** - finite states, percepts, actions. ex: chess\n",
              "* **Continuous** - continuous states, time, actions. ex: driving\n",
              "* **Known** - knows about physics of environment, outcomes for actions are given\n",
              "* **Unknown** - have to learn about how environment works to make good decisions\n",
              "* **Environment class** - many environents pulled for experimentation\n",
              "* **Agent architecture** - the physical part of an agent\n",
              "* **Simple reflex agents** - select action on current percept only. use if-then rules. randomization can help break infinite loops\n",
              "* **Model-based reflex agents** - maintain internal state/best guess of part of the world it can't see now. need transition and sensor model\n",
              "* **Transition model** - how world works physically\n",
              "* **Sensor model** - how world affects percepts\n",
              "* **Goal-based agents** - actions with specific goal in mind, better long-term/more customizable than reflex\n",
              "* **Utility-based agents** - internal (expected) utility function represents performance measure, tries to identify best way of getting to goal\n",
              "* **Model-free agent** - can learn best actions without learning exactly how action changes environment\n",
              "* **Learning element** - making improvements\n",
              "* **Performance element** - selecting external actions\n",
              "* **Critic** - judges learning element by performance standard\n",
              "* **Problem generator** - suggesting new approaches to improve over time (evolution, experimentation)\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": {
        "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",
        "\\n Object is deleted by garbage collection once unreachable.\n",
        "\\n Strong typing = every object has a fixed type, doesn't allow things incompatible with that type (like adding string to number).\n",
        "\\n Examples of types: int, float, str, tuple, dict, list, bool, None, generator, function\n",
        "\\n Java has static typing (enforce variable types), Python has dynamic typing (flexible, can assign a new type to a var, however type errors only caught at runtime)\n",
        "\\n Literals: immutable, Ints (1, 2), Floats (1.0, 2e9), Booleans (True, False)\n",
        "\\n Operations: + - * / ** % <= >= == != and or not\n",
        "\\n Assignment operators: += *= /= &= (no ++ or --)\n",
        "\\n References and Mutability: == checks same value, is checks pointing to same obj\n",
        "\\n Sequence types: tuple, strings, list\n",
        "\\n Tuples: immutable, can be of mixed types\n",
        "\\n Strings: immutable, can create with single or double quotes or triple quotes (for multiline strings), can add with '+' (special overload), prefix with r so you don't have to escape chars (ex: r'backn'), string formatting like print(\"hi %s\" % (\"bob\")), mystring.split(\" \"), \" \".join(mystring), mystring.capitalize(), mystring.upper(), mystring.strip(\" -\")\n",
        "\\n Lists: mutable, use slice [:] to get a shallow copy, can have mixed types, mylist.append(thing), mylist.insert(index, thing), mylist.index(thing) (returns first occurance index), mylist.count(thing), mylist.remove(thing) (removes first occurance), mylist.reverse() (modify in place), mylist.sort() (sort in place), sorted(mylist) (returns sorted copy)\n",
        "\\n Dicts: unordered, hashing, keys must be immutable, can mix key and value types, if try to access invalid/missing key throws KeyError, mydict.keys()/.values()/.items() returns list dict_keys/values/items(['hi', 'bye’]) (items are tuples), defaultdict() and Counter() constructors set default values in a dict of \"\" and 0 respectively\n",
        "\\n Sets: unordered, hashing, items must be immutable, if try to remove invalid/missing item throws Error\n",
        "\\n Functions: can be variables themselves (first-class objects), dont have to return, can return tuples with comma separated items, no function overloading like Java with diff arguments so need unique names, operator overloading is possible, default values can be provided but only AFTER non-default ones (otherwise SyntaxError), keyword arguments can put in function arguments out of order but have to be after non-keyword arguments (otherwise SyntaxError), *args for variable number of non-keyword args, **kwargs for dict of keyword args\n",
        "\\n Misc: dynamic scope (sees most current value of vars), default param values are evaluated only when the def statement is first executed (ex: fib set), \n",
        "\\n Classes: every method begins with self argument, extend parent superclass by class AI_Student(Student):, multiple inheritance supported, calling parent constructor/redefined method must be explicit with self as first arg (parentClass.__init__(self,x,y)), redefine method by using same name\n",
        "\\n Magic methods: can overload operators, ex: init, len, copy, cmp, add, neg\n",
        "\\n Main method: if __name__ == '__main__':\n",
        "\\n Loops: range(#) returns a list, when writing double for loops in 1 line just write them out one after another like normal nested loop order and have the first value be the innermost return value like concatenate: [y for x in seqs for y in x]\n",
        "\\n Iterators: iter(t), .next(), no hasnext(), catch StopIteration\n",
        "\\n Generators: yield, iterators, good for infinite\n",
        "\"\"\"\n",
        "\n",
        "# Each definition should be at most 20 words long.\n",
        "module2_definitions = {\n",
        "\"duck typing\" : \"if swims and quacks like duck, it's duck. can call any method on class as long as it has def\",\n",
        "}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 879
        },
        "id": "ydOK__lwWgdp",
        "outputId": "af24076a-69ef-4d12-f55b-6439b75d003e"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 2: Python\n",
              "## Module 2 Lecture Notes\n",
              "\n",
              "\n",
              " Object is deleted by garbage collection once unreachable.\n",
              "\n",
              " Strong typing = every object has a fixed type, doesn't allow things incompatible with that type (like adding string to number).\n",
              "\n",
              " Examples of types: int, float, str, tuple, dict, list, bool, None, generator, function\n",
              "\n",
              " Java has static typing (enforce variable types), Python has dynamic typing (flexible, can assign a new type to a var, however type errors only caught at runtime)\n",
              "\n",
              " Literals: immutable, Ints (1, 2), Floats (1.0, 2e9), Booleans (True, False)\n",
              "\n",
              " Operations: + - * / ** % <= >= == != and or not\n",
              "\n",
              " Assignment operators: += *= /= &= (no ++ or --)\n",
              "\n",
              " References and Mutability: == checks same value, is checks pointing to same obj\n",
              "\n",
              " Sequence types: tuple, strings, list\n",
              "\n",
              " Tuples: immutable, can be of mixed types\n",
              "\n",
              " Strings: immutable, can create with single or double quotes or triple quotes (for multiline strings), can add with '+' (special overload), prefix with r so you don't have to escape chars (ex: r'backn'), string formatting like print(\"hi %s\" % (\"bob\")), mystring.split(\" \"), \" \".join(mystring), mystring.capitalize(), mystring.upper(), mystring.strip(\" -\")\n",
              "\n",
              " Lists: mutable, use slice [:] to get a shallow copy, can have mixed types, mylist.append(thing), mylist.insert(index, thing), mylist.index(thing) (returns first occurance index), mylist.count(thing), mylist.remove(thing) (removes first occurance), mylist.reverse() (modify in place), mylist.sort() (sort in place), sorted(mylist) (returns sorted copy)\n",
              "\n",
              " Dicts: unordered, hashing, keys must be immutable, can mix key and value types, if try to access invalid/missing key throws KeyError, mydict.keys()/.values()/.items() returns list dict_keys/values/items(['hi', 'bye’]) (items are tuples), defaultdict() and Counter() constructors set default values in a dict of \"\" and 0 respectively\n",
              "\n",
              " Sets: unordered, hashing, items must be immutable, if try to remove invalid/missing item throws Error\n",
              "\n",
              " Functions: can be variables themselves (first-class objects), dont have to return, can return tuples with comma separated items, no function overloading like Java with diff arguments so need unique names, operator overloading is possible, default values can be provided but only AFTER non-default ones (otherwise SyntaxError), keyword arguments can put in function arguments out of order but have to be after non-keyword arguments (otherwise SyntaxError), *args for variable number of non-keyword args, **kwargs for dict of keyword args\n",
              "\n",
              " Misc: dynamic scope (sees most current value of vars), default param values are evaluated only when the def statement is first executed (ex: fib set), \n",
              "\n",
              " Classes: every method begins with self argument, extend parent superclass by class AI_Student(Student):, multiple inheritance supported, calling parent constructor/redefined method must be explicit with self as first arg (parentClass.__init__(self,x,y)), redefine method by using same name\n",
              "\n",
              " Magic methods: can overload operators, ex: init, len, copy, cmp, add, neg\n",
              "\n",
              " Main method: if __name__ == '__main__':\n",
              "\n",
              " Loops: range(#) returns a list, when writing double for loops in 1 line just write them out one after another like normal nested loop order and have the first value be the innermost return value like concatenate: [y for x in seqs for y in x]\n",
              "\n",
              " Iterators: iter(t), .next(), no hasnext(), catch StopIteration\n",
              "\n",
              " Generators: yield, iterators, good for infinite\n",
              "\n",
              "\n",
              "## Module 2 Definitions\n",
              "* **Duck typing** - if swims and quacks like duck, it's duck. can call any method on class as long as it has def\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": {
        "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",
        "\\n 6 things needed to define a search problem: State space, Initial state, Goal states, Actions, Transition model, Action cost function\n",
        "\"\"\"\n",
        "chapter3_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter3_4 = \"\"\"\n",
        "\\n BFS : use if possible inf paths, FIFO put successors at the end, expand shallowest first, complete if b is finite, optimal if cost = 1 per step, time = space = O(b^d)\n",
        "\\n DFS : use if space restricted, LIFO put successors at the front, expand deepest first, not complete (fails in inf depth spaces, spaces with loops. if avoid repeated states, then complete in finite spaces), not optimal, time = O(b^m), space = O(b*m)\n",
        "\\n depth-limited search : DFS until limit, l = depth limit, time = O(b^l), space = O(bl), unless lucky l = solution limit, not complete or not optimal\n",
        "\\n iterative deepening search : iterate increasing limit, DFS until limit each time, l = depth limit, time = O(b^d), space = O(bd), complete and optimal (if step cost = 1)\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module3_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions of concepts from Module 3.\n",
        "# You can define any bolded term in the textbook, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 20 words long.\n",
        "module3_definitions = {\n",
        "\"problem-solving agent\" : \"an agent that can formulate a plan via search\", \n",
        "\"search\" : \"computational process\",\n",
        "\"informed\" : \"estimate distance to goal\",\n",
        "\"uninformed\" : \"can't estimate distance to goal\",\n",
        "\"states\" : \"set of possible states of world\",\n",
        "\"state space\" : \"set of all possible states you can reach from initial state by any seq of actions\",\n",
        "\"actions\" : \"set of actions you can take\",\n",
        "\"transition model\" : \"map where actions take you\",\n",
        "\"action cost function\" : \"numeric cost of applying action\",\n",
        "\"path cost\" : \"performance measure, additive, ex: sum of step cost\",\n",
        "\"goal test\" : \"checks if we reached goal\",\n",
        "\"path\" : \"seq of actions from one state to another\",\n",
        "\"solution\" : \"path from initial to goal state\",\n",
        "\"frontier\" : \"states that are available for expanding\",\n",
        "\"optimal\" : \"finds least cost solution first\",\n",
        "\"tree search\" : \"go through all possible paths, don't check for redundant paths\",\n",
        "\"node\" : \"data structure, part of a search tree\",\n",
        "\"graph search\" : \"checks for redundant paths, keeps track of visited nodes\",\n",
        "\"complete\" : \"always finds solution, or halts and says no solution exists\",\n",
        "\"b\" : \"maximum branching factor of search tree\",\n",
        "\"d\" : \"depth of shallowest node\",\n",
        "\"m\" : \"max len of any path in the state space (could be infinite)\",\n",
        "}\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 917
        },
        "id": "lvtN3p7ET3Tx",
        "outputId": "68466404-a485-47eb-a75c-1b5652ee165d"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 3: Search Problems\n",
              "## AIMA Chapter 3.1 Problem-Solving Agents\n",
              "\n",
              "\n",
              " 6 things needed to define a search problem: State space, Initial state, Goal states, Actions, Transition model, Action cost function\n",
              "\n",
              "\n",
              "## AIMA Chapter 3.2 Example Problems\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 3.3 Search Algorithms\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
              "\n",
              "\n",
              " BFS : use if possible inf paths, FIFO put successors at the end, expand shallowest first, complete if b is finite, optimal if cost = 1 per step, time = space = O(b^d)\n",
              "\n",
              " DFS : use if space restricted, LIFO put successors at the front, expand deepest first, not complete (fails in inf depth spaces, spaces with loops. if avoid repeated states, then complete in finite spaces), not optimal, time = O(b^m), space = O(b*m)\n",
              "\n",
              " depth-limited search : DFS until limit, l = depth limit, time = O(b^l), space = O(bl), unless lucky l = solution limit, not complete or not optimal\n",
              "\n",
              " iterative deepening search : iterate increasing limit, DFS until limit each time, l = depth limit, time = O(b^d), space = O(bd), complete and optimal (if step cost = 1)\n",
              "\n",
              "\n",
              "## Module 3 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 3 Definitions\n",
              "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
              "* **Search** - computational process\n",
              "* **Informed** - estimate distance to goal\n",
              "* **Uninformed** - can't estimate distance to goal\n",
              "* **States** - set of possible states of world\n",
              "* **State space** - set of all possible states you can reach from initial state by any seq of actions\n",
              "* **Actions** - set of actions you can take\n",
              "* **Transition model** - map where actions take you\n",
              "* **Action cost function** - numeric cost of applying action\n",
              "* **Path cost** - performance measure, additive, ex: sum of step cost\n",
              "* **Goal test** - checks if we reached goal\n",
              "* **Path** - seq of actions from one state to another\n",
              "* **Solution** - path from initial to goal state\n",
              "* **Frontier** - states that are available for expanding\n",
              "* **Optimal** - finds least cost solution first\n",
              "* **Tree search** - go through all possible paths, don't check for redundant paths\n",
              "* **Node** - data structure, part of a search tree\n",
              "* **Graph search** - checks for redundant paths, keeps track of visited nodes\n",
              "* **Complete** - always finds solution, or halts and says no solution exists\n",
              "* **B** - maximum branching factor of search tree\n",
              "* **D** - depth of shallowest node\n",
              "* **M** - max len of any path in the state space (could be infinite)\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": {
        "id": "tuFC8w7CyCns"
      },
      "outputs": [],
      "source": [
        "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
        "chapter3_5 = \"\"\"\n",
        "\\n A* is complete, cost-optimal, and optimally efficient.\n",
        "\\n Weighted A* search muliplies heuristic. Not as accurate but could be faster in some situations than normal A*.\n",
        "\\n Can save space on A* by storing only frontier in some problems.\n",
        "\\n Reference count, count until state visited through all neighbors, then remove from visited table.\n",
        "\\n Beam search limits size of frontier. Stores only k nodes with best f scores. Saves a lot of memory, but make search suboptimal and incomplete.\n",
        "\\n Iterative deepening search A* is exactly what it sounds like. The cutoff is the first smallest value f-cost (g+h) past the current cutoff cost.\n",
        "\\n Recursive BFS mimics best-first search but saves f-value of best path along nodes as it goes, so it can backtrack and find better alt paths. Optimal if h(n) is admissible. Space is linear to depth of deepest optimal solution.\n",
        "\\n IDA* and RBFS use too little memory, spend too much time reexploring same states.\n",
        "\\n Memory-bounded A* (MA*) and Simplified MA* use all memory we have available, dropping worst f-value nodes if necessary. Complete and optimal if there is such a solution.\n",
        "\\n Bidirectional heuristic search starts same search algo from beginning and goal nodes, operates off max 3 theorem (f2 val function off of this). Not guaranteed optimally efficient. Complete and optimal if admissible heuristic and f2 eval function.\n",
        "\"\"\"\n",
        "chapter3_6 = \"\"\"\n",
        "\\n h2 dominates h1 if for any node h2(n) >= h1(n). Using A* with h2 will never expand more nodes than h1.\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module4_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module4_definitions = {\n",
        "\"greedy best first search\" : \"picks action with lowest h(n)\",\n",
        "\"A* search\" : \"uses eval function g(n) + h(n), pick action with lowest path cost so far and lowest estimate cost to goal\",\n",
        "}\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 616
        },
        "id": "vqtEs0gHs9sO",
        "outputId": "9776e4e4-22b9-4519-c982-54928b9693dc"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 4: Informed Search\n",
              "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
              "\n",
              "\n",
              " A* is complete, cost-optimal, and optimally efficient.\n",
              "\n",
              " Weighted A* search muliplies heuristic. Not as accurate but could be faster in some situations than normal A*.\n",
              "\n",
              " Can save space on A* by storing only frontier in some problems.\n",
              "\n",
              " Reference count, count until state visited through all neighbors, then remove from visited table.\n",
              "\n",
              " Beam search limits size of frontier. Stores only k nodes with best f scores. Saves a lot of memory, but make search suboptimal and incomplete.\n",
              "\n",
              " Iterative deepening search A* is exactly what it sounds like. The cutoff is the first smallest value f-cost (g+h) past the current cutoff cost.\n",
              "\n",
              " Recursive BFS mimics best-first search but saves f-value of best path along nodes as it goes, so it can backtrack and find better alt paths. Optimal if h(n) is admissible. Space is linear to depth of deepest optimal solution.\n",
              "\n",
              " IDA* and RBFS use too little memory, spend too much time reexploring same states.\n",
              "\n",
              " Memory-bounded A* (MA*) and Simplified MA* use all memory we have available, dropping worst f-value nodes if necessary. Complete and optimal if there is such a solution.\n",
              "\n",
              " Bidirectional heuristic search starts same search algo from beginning and goal nodes, operates off max 3 theorem (f2 val function off of this). Not guaranteed optimally efficient. Complete and optimal if admissible heuristic and f2 eval function.\n",
              "\n",
              "\n",
              "## AIMA Chapter 3.6 Heuristic Functions\n",
              "\n",
              "\n",
              " h2 dominates h1 if for any node h2(n) >= h1(n). Using A* with h2 will never expand more nodes than h1.\n",
              "\n",
              "\n",
              "## Module 4 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 4 Definitions\n",
              "* **Greedy best first search** - picks action with lowest h(n)\n",
              "* **A* search** - uses eval function g(n) + h(n), pick action with lowest path cost so far and lowest estimate cost to goal\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": {
        "id": "iEIOpL7vyWcc"
      },
      "outputs": [],
      "source": [
        "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
        "chapter5_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter5_2 = \"\"\"\n",
        "\\n Minimax does depth-first exploration of tree. Time = O(b^m), where m is max depth of tree, space = O(bm) if algo generates all actions at once, or O(m) for algo that generates actions one at a time.\n",
        "\\n For games with more than 2 players, alliances could play a big part. Technically similar minimax problem though.\n",
        "\\n With alpha-beta pruning, if it could be done perfectly, it would only need O(b^(m/2)) nodes to pick best move.\n",
        "\"\"\"\n",
        "chapter5_3 = \"\"\"\n",
        "\\n Eval function returns how \"good\" a state is for the player. Ex: chess board count up value of pieces, maybe take in account positioning. Not accounting for future fatal moves, need cutoff test with a quiescence search.\n",
        "\\n Forward prune to not consider bad moves. Some methods are beam search, ProbCut (based on history, probability, then cut).\n",
        "\\n Computer can hardcode/precompute a table lookup for start and end of games (like chess). Saves computation and can ensure a policy that maps every state to best possible move in that state.\n",
        "\"\"\"\n",
        "chapter5_5 = \"\"\"\n",
        "\\n Stochastic games have probability elements. Need chance nodes to account for this (another layer in tree). Denote possible pathways with expected values. You can still prune with chance nodes, just find their range.\n",
        "\"\"\"\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
        "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module5_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module5_definitions = {\n",
        "\"transposition table\" : \"save computed minimax values of visited states to save repetitive computation\",   \n",
        "}\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 834
        },
        "id": "KUc_LgzDvWf-",
        "outputId": "90a8d0d6-252b-465f-9cba-8733e24c98f2"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 5: Adversarial Search and Games\n",
              "## AIMA Chapter 5.1 Game Theory\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
              "\n",
              "\n",
              " Minimax does depth-first exploration of tree. Time = O(b^m), where m is max depth of tree, space = O(bm) if algo generates all actions at once, or O(m) for algo that generates actions one at a time.\n",
              "\n",
              " For games with more than 2 players, alliances could play a big part. Technically similar minimax problem though.\n",
              "\n",
              " With alpha-beta pruning, if it could be done perfectly, it would only need O(b^(m/2)) nodes to pick best move.\n",
              "\n",
              "\n",
              "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
              "\n",
              "\n",
              " Eval function returns how \"good\" a state is for the player. Ex: chess board count up value of pieces, maybe take in account positioning. Not accounting for future fatal moves, need cutoff test with a quiescence search.\n",
              "\n",
              " Forward prune to not consider bad moves. Some methods are beam search, ProbCut (based on history, probability, then cut).\n",
              "\n",
              " Computer can hardcode/precompute a table lookup for start and end of games (like chess). Saves computation and can ensure a policy that maps every state to best possible move in that state.\n",
              "\n",
              "\n",
              "## AIMA Chapter 5.5 Stochastic Games\n",
              "\n",
              "\n",
              " Stochastic games have probability elements. Need chance nodes to account for this (another layer in tree). Denote possible pathways with expected values. You can still prune with chance nodes, just find their range.\n",
              "\n",
              "\n",
              "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 16.3 Utility Functions\n",
              " Your summary here \n",
              "\n",
              "## Module 5 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 5 Definitions\n",
              "* **Transposition table** - save computed minimax values of visited states to save repetitive computation\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": [],
      "source": [
        "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
        "chapter6_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter6_2 = \"\"\"\n",
        "\\n Path consistency constrains triples of variables.\n",
        "\\n K-consistency: CSP is k-consistent if for any set of k-1 vars, can find a consistent assignment for a kth var. 1,2,3 = node, arc, path.\n",
        "\\n Strongly k-consistent is same concept as strong induction.\n",
        "\\n Global constraint: involving arbitrary number of variables, not necessarily all like AllDiff.\n",
        "\"\"\"\n",
        "chapter6_3 = \"\"\"\n",
        "\\n Keep things commutative (only consider assigning 1 val to 1 variable per node, so we don't get AB BA issue where they end up in same state later. this would be tree search).\n",
        "\\n Constraint learning, no-goods\n",
        "\\n MAC (maintain arc consistency) is a way of interleaving search and inference. AC-3 is pure inference. MAC runs while assigning variables in backtracking search. Instead of queueing all arcs, MAC only queues arcs incident on the assigned variable. Then, it runs identically to AC-3. \n",
        "\"\"\"\n",
        "chapter6_4 = \"\"\"\n",
        "\\n Min-conflicts is really effective for CSPs. Pick and assign values with minimal conflicts. Constraint weighing is also a thing that helps.\n",
        "\"\"\"\n",
        "chapter6_5 = \"\"\"\n",
        "\\n Can use graphs, CCs, topo sort, trees to more efficiently solve CSP.\n",
        "\\n Cycle cutset: make a graph a tree by fulfilling x amount of variables (removing their nodes bc they have value now). Obviously we have to try multiple values, but after we get the tree we can just run the tree algo with topo sort to assign variables through narrowing down parent to child. Saves us time from backtracking.\n",
        "\\n Tree decomposition techniques just turn the CSP into tree with CCs. Nodes in multiple CCs need to be included in all paths between each others' CCs. Tree width = 1 less than size of largest node.\n",
        "\\n Tree is more efficient than cycle. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. Tree decomposition subproblems are efficient if tree width is small.\n",
        "\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module6_lecture_notes = \"\"\"\n",
        "\\n Planning: sequences of actions, the path to the goal is the important thing, paths have various costs, depths, heuristics give problem-specific guidance\n",
        "\\n Identification: assignments to variables, the goal itself is important, not the path, all paths at the same depth (for some formulations). CSP is specialized search for this!\n",
        "\\n Big idea of CSP: no hand-tuning solution, just apply logic constraints to all kinds of problems and plug in generic algorithm\n",
        "\\n Solution to CSP is complete (every var assigned) and consistent (follows all constraints, legal assignment).\n",
        "\\n Example applications: map coloring, scheduling, floor planning for circuitry, sudoku, etc\n",
        "\\n Structure of CSP: Constraint graph, nodes are variables, arcs are (binary) constraints. can be discrete or continuous (lin prog). can have lower/higher order constraints, and even preferences.\n",
        "\\n Default uninformed algo for CSP: backtracking search\n",
        "\\n Improvements: heuristics (which var should be assigned next (most constrained, minimum-remaining-values heuristic (fewest legal vals)), degree heuristic (most arcs)), what order should values be tried (least-constraining-value heuristic), can we detect fails early (forward checks))\n",
        "\\n Forward checking: keep track of remaining legal values for each var. Terminate search when any unassigned var has no possible values left.\n",
        "\\n Constraint propogation & AC-3: repeatedly enforces constraints locally. CSP solvers combine search (assigning vals) and inference (eliminating possible vals).\n",
        "\\n Local consistency: node consistency (unary constraint on self), arc consistency (binary constraints) etc.\n",
        "\\n AC-3: worse case time = O(n^2 * d^3). All nodes can be connected to every other node (num arcs = n^2), d values so checking 1 arc is d^2, each arc can only be inserted to queue d times.\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module6_definitions = {\n",
        "\"concept\" : \"definition\",\n",
        "}\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "kKWbCsbfxL3R",
        "outputId": "101ff305-400a-414a-b107-99263c90c99f"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 6: Constraint Satisfaction Problems\n",
              "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
              "\n",
              "\n",
              " Path consistency constrains triples of variables.\n",
              "\n",
              " K-consistency: CSP is k-consistent if for any set of k-1 vars, can find a consistent assignment for a kth var. 1,2,3 = node, arc, path.\n",
              "\n",
              " Strongly k-consistent is same concept as strong induction.\n",
              "\n",
              " Global constraint: involving arbitrary number of variables, not necessarily all like AllDiff.\n",
              "\n",
              "\n",
              "## AIMA Chapter 6.3 Backtracking Search for CSPs\n",
              "\n",
              "\n",
              " Keep things commutative (only consider assigning 1 val to 1 variable per node, so we don't get AB BA issue where they end up in same state later. this would be tree search).\n",
              "\n",
              " Constraint learning, no-goods\n",
              "\n",
              " MAC (maintain arc consistency) is a way of interleaving search and inference. AC-3 is pure inference. MAC runs while assigning variables in backtracking search. Instead of queueing all arcs, MAC only queues arcs incident on the assigned variable. Then, it runs identically to AC-3. \n",
              "\n",
              "\n",
              "## AIMA Chapter 6.4 Local Search for CSPs\n",
              "\n",
              "\n",
              " Min-conflicts is really effective for CSPs. Pick and assign values with minimal conflicts. Constraint weighing is also a thing that helps.\n",
              "\n",
              "\n",
              "## AIMA Chapter 6.5 The Structure of Problems\n",
              "\n",
              "\n",
              " Can use graphs, CCs, topo sort, trees to more efficiently solve CSP.\n",
              "\n",
              " Cycle cutset: make a graph a tree by fulfilling x amount of variables (removing their nodes bc they have value now). Obviously we have to try multiple values, but after we get the tree we can just run the tree algo with topo sort to assign variables through narrowing down parent to child. Saves us time from backtracking.\n",
              "\n",
              " Tree decomposition techniques just turn the CSP into tree with CCs. Nodes in multiple CCs need to be included in all paths between each others' CCs. Tree width = 1 less than size of largest node.\n",
              "\n",
              " Tree is more efficient than cycle. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. Tree decomposition subproblems are efficient if tree width is small.\n",
              "\n",
              "\n",
              "## Module 6 Lecture Notes\n",
              "\n",
              "\n",
              " Planning: sequences of actions, the path to the goal is the important thing, paths have various costs, depths, heuristics give problem-specific guidance\n",
              "\n",
              " Identification: assignments to variables, the goal itself is important, not the path, all paths at the same depth (for some formulations). CSP is specialized search for this!\n",
              "\n",
              " Big idea of CSP: no hand-tuning solution, just apply logic constraints to all kinds of problems and plug in generic algorithm\n",
              "\n",
              " Solution to CSP is complete (every var assigned) and consistent (follows all constraints, legal assignment).\n",
              "\n",
              " Example applications: map coloring, scheduling, floor planning for circuitry, sudoku, etc\n",
              "\n",
              " Structure of CSP: Constraint graph, nodes are variables, arcs are (binary) constraints. can be discrete or continuous (lin prog). can have lower/higher order constraints, and even preferences.\n",
              "\n",
              " Default uninformed algo for CSP: backtracking search\n",
              "\n",
              " Improvements: heuristics (which var should be assigned next (most constrained, minimum-remaining-values heuristic (fewest legal vals)), degree heuristic (most arcs)), what order should values be tried (least-constraining-value heuristic), can we detect fails early (forward checks))\n",
              "\n",
              " Forward checking: keep track of remaining legal values for each var. Terminate search when any unassigned var has no possible values left.\n",
              "\n",
              " Constraint propogation & AC-3: repeatedly enforces constraints locally. CSP solvers combine search (assigning vals) and inference (eliminating possible vals).\n",
              "\n",
              " Local consistency: node consistency (unary constraint on self), arc consistency (binary constraints) etc.\n",
              "\n",
              " AC-3: worse case time = O(n^2 * d^3). All nodes can be connected to every other node (num arcs = n^2), d values so checking 1 arc is d^2, each arc can only be inserted to queue d times.\n",
              "\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))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "#Module 7 - Logical Agents"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "outputs": [],
      "source": [
        "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
        "\n",
        "chapter7_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter7_5 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module7_lecture_notes = \"\"\"\n",
        "\\n Axioms are given sentences, and there are Derived sentences (what it sounds like)\n",
        "\\n Models are \"possible worlds\" with truth values for each sentence. M(a) means set of all models where sentence a is true. If a is true in m we say m satisfies a or m is a model of a.\n",
        "\\n Entails is basically implies. a entails b iff M(a) is a proper subset of M(b) (a is stronger/more specific than b).\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module7_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 604
        },
        "id": "lXNcHuKjyNXa",
        "outputId": "55e91a35-dec4-49aa-d045-5d3d699cf75c"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 7: Logical Agents\n",
              "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.2 The Wumpus World\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.3 Logic\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
              " Your summary here \n",
              "\n",
              "## AIMA 7.5 Propositional Theorem Proving\n",
              " Your summary here \n",
              "\n",
              "## Module 7 Lecture Notes\n",
              "\n",
              "\n",
              " Axioms are given sentences, and there are Derived sentences (what it sounds like)\n",
              "\n",
              " Models are \"possible worlds\" with truth values for each sentence. M(a) means set of all models where sentence a is true. If a is true in m we say m satisfies a or m is a model of a.\n",
              "\n",
              " Entails is basically implies. a entails b iff M(a) is a proper subset of M(b) (a is stronger/more specific than b).\n",
              "\n",
              "\n",
              "## Module 7 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",
        "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": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "ddc8cb77-b2fd-476f-c56f-df6e233acd8b"
      },
      "outputs": [
        {
          "data": {
            "text/markdown": [
              "# Module 1: Rational Agents and Task Environments\n",
              "## AIMA Chapter 1.1 What is AI?\n",
              "\n",
              "\n",
              " AI can be defined with two dimensions (human vs. rational and thought vs. behavior) which leads to 4 approaches.\n",
              "\n",
              " 6 main disciplines of AI are NLP, knowledge rep., auto. reasoning, ML, computer vision, and robotics.\n",
              "\n",
              " 3 ways to learn about human thought are introspection, psychological experiments, and brain imaging.\n",
              "\n",
              " Turing test needs NLP, knowledge rep, automated reasoning, ML. Total Turing test additionally needs computer vision, robotics.\n",
              "\n",
              " We rarely know true facts of the world, so probability allows for rigorous reasoning with uncertain info. However, it cannot generate intelligent behavior by itself.\n",
              "\n",
              " Rational agent doesn't just use inferences, is more general/broad. Essentially, do the right thing, according to the current objective.\n",
              "\n",
              "\n",
              "## AIMA Chapter 27.1 The Limits of AI\n",
              "\n",
              "\n",
              " Originally weak vs strong AI. Then definition shifted to general vs human-level AI. \n",
              "\n",
              " The only thing programs aren't able to do is to be exactly human.\n",
              "\n",
              " Humans can be wrong too, disproving the Godel's incompleteness theorem. Just because humans and machines can be wrong doesn't mean they can't still adapt and change, or be useful in the first place.\n",
              "\n",
              " Most AI researchers care more about making AI excel at specific games/tasks rather than make them act human in all aspects.\n",
              "\n",
              "\n",
              "## AIMA Chapter 27.1 Can Machines Really Think?\n",
              "\n",
              "\n",
              " Polite convention to not worry about simulation or actual thinking/abilities.\n",
              "\n",
              " Chinese room argument is that the human in the room translating Chinese and a program translating Chinese has no true understanding of it.\n",
              "\n",
              " Searle is a proponent of biological naturalism, claiming mental states stem from properties in neurons that machines do not have. Same argument could be used against people and cells though...\n",
              "\n",
              " Strong AI debate is all about consciousness (awareness of outside world, self and living). Can machines have qualia (intrinsic nature of experiences)? Similar questions about animals.\n",
              "\n",
              " Behaving intelligently will require some awareness, and machines interacting with humans need human subjective experience. Machines can't experience it themselves, but they can run others' code.\n",
              "\n",
              "\n",
              "## AIMA 2.1 Agents and Environments\n",
              "\n",
              "\n",
              " We mostly use rational agents.\n",
              "\n",
              " Agent's choice of action depends on built-in knowledge and percept sequence, but not anything it hasn't seen/experienced/sensed yet.\n",
              "\n",
              "\n",
              "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
              "\n",
              "\n",
              " Humans have desires and preferences, machines don't, so rationality is associated with humans' POV.\n",
              "\n",
              " Generally, it's better to design performance measures according to desired end environment result, not how you think the agent should act (or else vacuum robot would just dump and clean dirt over and over).\n",
              "\n",
              " Rational depends on 4 things: performance measure, agent's prior knowledge of environment, agent's possible actions, agent's percept sequence until now. For possible percept sequence, rational agent should select performance measure maximizing action, given info from percept sequence and build-in knowledge.\n",
              "\n",
              " Ration does NOT equal perfection. Things can still go wrong, unless you are omniscient, which no one is. Rationality maximizes expected performance, perfection maximizes actual performance.\n",
              "\n",
              " Ration agent should learn as much as it can, aka gain information from environment.\n",
              "\n",
              " Autonomous rational agents are way better than non-autonomous.\n",
              "\n",
              "\n",
              "## AIMA 2.3 The Nature of Environments\n",
              "\n",
              "\n",
              " Other agents can be recognized if they are maximizing a performance measure whos value depends on our agent's behavior.\n",
              "\n",
              " Randomized behavior can be rational in some multiagent environments.\n",
              "\n",
              "\n",
              "## AIMA 2.4 The Structure of Agents\n",
              "\n",
              "\n",
              " agent = architecture + program.\n",
              "\n",
              " Agent program takes in current percept and returns an action. Agent function may depend on entire percept history.\n",
              "\n",
              " Impossible to encode lookup table in reality. Key challenge in AI is to produce rational behavior from small program rather than vast table.\n",
              "\n",
              "\n",
              "## Module 1 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 1 Definitions\n",
              "* **Rationality** - doing the right thing\n",
              "* **Turing test** - if a human consistently can't tell if an answerer is a human or computer\n",
              "* **Nlp** - understand human language\n",
              "* **Knowledge representation** - remember things\n",
              "* **Automated reasoning** - answer questions, draw conclusions\n",
              "* **Machine learning** - adapt to new situations, detect + extrapolate patterns\n",
              "* **Total turing test** - turint test + interact with environment\n",
              "* **Computer vision** - perceive the world\n",
              "* **Robotics** - move stuff and self\n",
              "* **Introspection** - self-aware about thoughts\n",
              "* **Psychological experiments** - seeing people in action\n",
              "* **Brain imaging** - seeing brain in action\n",
              "* **Cognitive science** - combine AI and psychology to make theories about human mind\n",
              "* **Syllogisms** - deductive reasoning from given premises. led to field called logic\n",
              "* **Logicist** - philosophy. way to label rigorous statements about objects in the world\n",
              "* **Probability** - allows for uncertainty in logic models\n",
              "* **Agent** - anything that can perceive and act in an environment\n",
              "* **Rational agent** - an approach to AI. an agent that acts to get the best possible outcome (if uncertain, the best expected outcome).\n",
              "* **Laws of thought** - an approach to AI that emphasized correct inferences\n",
              "* **Limited rationality** - impossible to calculate true rationality, so we do our best\n",
              "* **Perfect rationality** - good for theory, but mostly impossible in complex environments\n",
              "* **Value alignment problem** - difficult to fully convey our true goals/objectives to a machine\n",
              "* **Provably beneficial** - we want agents that help humans and don't relentlessly pursue objectives (could have very negative consequences)\n",
              "* **Weak ai** - machines act as if they were intelligent\n",
              "* **Strong ai** - machines are consciously thinking not just simulating thinking\n",
              "* **Gofai** - good old-fashioned AI (criticized because difficult to capture set guaranteed logic in rules)\n",
              "* **Qualification problem** - difficulty of describing all possible proper behavior in a set of logical rules\n",
              "* **Embodied cognition** - brain is connected to body which is in an environment when decision making\n",
              "* **Sensor** - things to sense with\n",
              "* **Actuator** - things to act with\n",
              "* **Environment** - the surroundings we care about when designing the agent\n",
              "* **Percept** - content that agents' sensors are perceiving\n",
              "* **Percept sequence** - history of all percepts the agent has ever had\n",
              "* **Agent function** - abstract mathmatical concept, maps any given percept sequence to an action\n",
              "* **Agent program** - concrete implementation that implements an agent function\n",
              "* **Consequentialism** - evaluate agent's behavior by consequences\n",
              "* **Performance measure** - evaluates given sequence of environment states\n",
              "* **Omniscience** - knowing actual outcome of actions\n",
              "* **Information gathering** - actions to modify future percepts, helps rationality, ex. exploration\n",
              "* **Autonomy** - how much agent needs to rely on prior knowledge rather than own percepts and learning\n",
              "* **Task environment** - problem agent must solve\n",
              "* **Peas** - performance, environment, actuators, sensors make up the task environment\n",
              "* **Software agent/softbot** - agents operating in virtual environment\n",
              "* **Fully observable** - total access to complete state of environment\n",
              "* **Partially observable** - some access to complete state of environment\n",
              "* **Unobservable** - no access to complete state of environment, because agent has no sensors\n",
              "* **Single-agent** - only 1 agent involved (self)\n",
              "* **Competitive multi-agent** - more than 1 agent involved, performance measure makes them compete against each other\n",
              "* **Cooperative multi-agent** - more than 1 agent involved, performance measure makes them cooperate with each other\n",
              "* **Deterministic** - next environment state is fully determined by current state and agent action\n",
              "* **Non-deterministic** - next environment state is not fully determined by current state and agent action\n",
              "* **Stochastic** - mostly synonym for non-deterministic, but more specifically if model explicitly has probabilities listed\n",
              "* **Episodic** - next episode does not depend on actions in previous episodes. easy, don't need to think ahead\n",
              "* **Sequential** - current decision can affect all future decisions. ex. chess, driving\n",
              "* **Static** - environment doesn't change while agent is thinking\n",
              "* **Dynamic** - environment does change while agent is thinking\n",
              "* **Semidynamic** - environment doesn't change while agent is thinking but performance score does\n",
              "* **Discrete** - finite states, percepts, actions. ex: chess\n",
              "* **Continuous** - continuous states, time, actions. ex: driving\n",
              "* **Known** - knows about physics of environment, outcomes for actions are given\n",
              "* **Unknown** - have to learn about how environment works to make good decisions\n",
              "* **Environment class** - many environents pulled for experimentation\n",
              "* **Agent architecture** - the physical part of an agent\n",
              "* **Simple reflex agents** - select action on current percept only. use if-then rules. randomization can help break infinite loops\n",
              "* **Model-based reflex agents** - maintain internal state/best guess of part of the world it can't see now. need transition and sensor model\n",
              "* **Transition model** - how world works physically\n",
              "* **Sensor model** - how world affects percepts\n",
              "* **Goal-based agents** - actions with specific goal in mind, better long-term/more customizable than reflex\n",
              "* **Utility-based agents** - internal (expected) utility function represents performance measure, tries to identify best way of getting to goal\n",
              "* **Model-free agent** - can learn best actions without learning exactly how action changes environment\n",
              "* **Learning element** - making improvements\n",
              "* **Performance element** - selecting external actions\n",
              "* **Critic** - judges learning element by performance standard\n",
              "* **Problem generator** - suggesting new approaches to improve over time (evolution, experimentation)\n",
              "\n",
              "\n",
              "# Module 2: Python\n",
              "## Module 2 Lecture Notes\n",
              "\n",
              "\n",
              " Object is deleted by garbage collection once unreachable.\n",
              "\n",
              " Strong typing = every object has a fixed type, doesn't allow things incompatible with that type (like adding string to number).\n",
              "\n",
              " Examples of types: int, float, str, tuple, dict, list, bool, None, generator, function\n",
              "\n",
              " Java has static typing (enforce variable types), Python has dynamic typing (flexible, can assign a new type to a var, however type errors only caught at runtime)\n",
              "\n",
              " Literals: immutable, Ints (1, 2), Floats (1.0, 2e9), Booleans (True, False)\n",
              "\n",
              " Operations: + - * / ** % <= >= == != and or not\n",
              "\n",
              " Assignment operators: += *= /= &= (no ++ or --)\n",
              "\n",
              " References and Mutability: == checks same value, is checks pointing to same obj\n",
              "\n",
              " Sequence types: tuple, strings, list\n",
              "\n",
              " Tuples: immutable, can be of mixed types\n",
              "\n",
              " Strings: immutable, can create with single or double quotes or triple quotes (for multiline strings), can add with '+' (special overload), prefix with r so you don't have to escape chars (ex: r'backn'), string formatting like print(\"hi %s\" % (\"bob\")), mystring.split(\" \"), \" \".join(mystring), mystring.capitalize(), mystring.upper(), mystring.strip(\" -\")\n",
              "\n",
              " Lists: mutable, use slice [:] to get a shallow copy, can have mixed types, mylist.append(thing), mylist.insert(index, thing), mylist.index(thing) (returns first occurance index), mylist.count(thing), mylist.remove(thing) (removes first occurance), mylist.reverse() (modify in place), mylist.sort() (sort in place), sorted(mylist) (returns sorted copy)\n",
              "\n",
              " Dicts: unordered, hashing, keys must be immutable, can mix key and value types, if try to access invalid/missing key throws KeyError, mydict.keys()/.values()/.items() returns list dict_keys/values/items(['hi', 'bye’]) (items are tuples), defaultdict() and Counter() constructors set default values in a dict of \"\" and 0 respectively\n",
              "\n",
              " Sets: unordered, hashing, items must be immutable, if try to remove invalid/missing item throws Error\n",
              "\n",
              " Functions: can be variables themselves (first-class objects), dont have to return, can return tuples with comma separated items, no function overloading like Java with diff arguments so need unique names, operator overloading is possible, default values can be provided but only AFTER non-default ones (otherwise SyntaxError), keyword arguments can put in function arguments out of order but have to be after non-keyword arguments (otherwise SyntaxError), *args for variable number of non-keyword args, **kwargs for dict of keyword args\n",
              "\n",
              " Misc: dynamic scope (sees most current value of vars), default param values are evaluated only when the def statement is first executed (ex: fib set), \n",
              "\n",
              " Classes: every method begins with self argument, extend parent superclass by class AI_Student(Student):, multiple inheritance supported, calling parent constructor/redefined method must be explicit with self as first arg (parentClass.__init__(self,x,y)), redefine method by using same name\n",
              "\n",
              " Magic methods: can overload operators, ex: init, len, copy, cmp, add, neg\n",
              "\n",
              " Main method: if __name__ == '__main__':\n",
              "\n",
              " Loops: range(#) returns a list, when writing double for loops in 1 line just write them out one after another like normal nested loop order and have the first value be the innermost return value like concatenate: [y for x in seqs for y in x]\n",
              "\n",
              " Iterators: iter(t), .next(), no hasnext(), catch StopIteration\n",
              "\n",
              " Generators: yield, iterators, good for infinite\n",
              "\n",
              "\n",
              "## Module 2 Definitions\n",
              "* **Duck typing** - if swims and quacks like duck, it's duck. can call any method on class as long as it has def\n",
              "\n",
              "\n",
              "# Module 3: Search Problems\n",
              "## AIMA Chapter 3.1 Problem-Solving Agents\n",
              "\n",
              "\n",
              " 6 things needed to define a search problem: State space, Initial state, Goal states, Actions, Transition model, Action cost function\n",
              "\n",
              "\n",
              "## AIMA Chapter 3.2 Example Problems\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 3.3 Search Algorithms\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
              "\n",
              "\n",
              " BFS : use if possible inf paths, FIFO put successors at the end, expand shallowest first, complete if b is finite, optimal if cost = 1 per step, time = space = O(b^d)\n",
              "\n",
              " DFS : use if space restricted, LIFO put successors at the front, expand deepest first, not complete (fails in inf depth spaces, spaces with loops. if avoid repeated states, then complete in finite spaces), not optimal, time = O(b^m), space = O(b*m)\n",
              "\n",
              " depth-limited search : DFS until limit, l = depth limit, time = O(b^l), space = O(bl), unless lucky l = solution limit, not complete or not optimal\n",
              "\n",
              " iterative deepening search : iterate increasing limit, DFS until limit each time, l = depth limit, time = O(b^d), space = O(bd), complete and optimal (if step cost = 1)\n",
              "\n",
              "\n",
              "## Module 3 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 3 Definitions\n",
              "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
              "* **Search** - computational process\n",
              "* **Informed** - estimate distance to goal\n",
              "* **Uninformed** - can't estimate distance to goal\n",
              "* **States** - set of possible states of world\n",
              "* **State space** - set of all possible states you can reach from initial state by any seq of actions\n",
              "* **Actions** - set of actions you can take\n",
              "* **Transition model** - map where actions take you\n",
              "* **Action cost function** - numeric cost of applying action\n",
              "* **Path cost** - performance measure, additive, ex: sum of step cost\n",
              "* **Goal test** - checks if we reached goal\n",
              "* **Path** - seq of actions from one state to another\n",
              "* **Solution** - path from initial to goal state\n",
              "* **Frontier** - states that are available for expanding\n",
              "* **Optimal** - finds least cost solution first\n",
              "* **Tree search** - go through all possible paths, don't check for redundant paths\n",
              "* **Node** - data structure, part of a search tree\n",
              "* **Graph search** - checks for redundant paths, keeps track of visited nodes\n",
              "* **Complete** - always finds solution, or halts and says no solution exists\n",
              "* **B** - maximum branching factor of search tree\n",
              "* **D** - depth of shallowest node\n",
              "* **M** - max len of any path in the state space (could be infinite)\n",
              "\n",
              "\n",
              "# Module 4: Informed Search\n",
              "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
              "\n",
              "\n",
              " A* is complete, cost-optimal, and optimally efficient.\n",
              "\n",
              " Weighted A* search muliplies heuristic. Not as accurate but could be faster in some situations than normal A*.\n",
              "\n",
              " Can save space on A* by storing only frontier in some problems.\n",
              "\n",
              " Reference count, count until state visited through all neighbors, then remove from visited table.\n",
              "\n",
              " Beam search limits size of frontier. Stores only k nodes with best f scores. Saves a lot of memory, but make search suboptimal and incomplete.\n",
              "\n",
              " Iterative deepening search A* is exactly what it sounds like. The cutoff is the first smallest value f-cost (g+h) past the current cutoff cost.\n",
              "\n",
              " Recursive BFS mimics best-first search but saves f-value of best path along nodes as it goes, so it can backtrack and find better alt paths. Optimal if h(n) is admissible. Space is linear to depth of deepest optimal solution.\n",
              "\n",
              " IDA* and RBFS use too little memory, spend too much time reexploring same states.\n",
              "\n",
              " Memory-bounded A* (MA*) and Simplified MA* use all memory we have available, dropping worst f-value nodes if necessary. Complete and optimal if there is such a solution.\n",
              "\n",
              " Bidirectional heuristic search starts same search algo from beginning and goal nodes, operates off max 3 theorem (f2 val function off of this). Not guaranteed optimally efficient. Complete and optimal if admissible heuristic and f2 eval function.\n",
              "\n",
              "\n",
              "## AIMA Chapter 3.6 Heuristic Functions\n",
              "\n",
              "\n",
              " h2 dominates h1 if for any node h2(n) >= h1(n). Using A* with h2 will never expand more nodes than h1.\n",
              "\n",
              "\n",
              "## Module 4 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 4 Definitions\n",
              "* **Greedy best first search** - picks action with lowest h(n)\n",
              "* **A* search** - uses eval function g(n) + h(n), pick action with lowest path cost so far and lowest estimate cost to goal\n",
              "\n",
              "\n",
              "# Module 5: Adversarial Search and Games\n",
              "## AIMA Chapter 5.1 Game Theory\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
              "\n",
              "\n",
              " Minimax does depth-first exploration of tree. Time = O(b^m), where m is max depth of tree, space = O(bm) if algo generates all actions at once, or O(m) for algo that generates actions one at a time.\n",
              "\n",
              " For games with more than 2 players, alliances could play a big part. Technically similar minimax problem though.\n",
              "\n",
              " With alpha-beta pruning, if it could be done perfectly, it would only need O(b^(m/2)) nodes to pick best move.\n",
              "\n",
              "\n",
              "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
              "\n",
              "\n",
              " Eval function returns how \"good\" a state is for the player. Ex: chess board count up value of pieces, maybe take in account positioning. Not accounting for future fatal moves, need cutoff test with a quiescence search.\n",
              "\n",
              " Forward prune to not consider bad moves. Some methods are beam search, ProbCut (based on history, probability, then cut).\n",
              "\n",
              " Computer can hardcode/precompute a table lookup for start and end of games (like chess). Saves computation and can ensure a policy that maps every state to best possible move in that state.\n",
              "\n",
              "\n",
              "## AIMA Chapter 5.5 Stochastic Games\n",
              "\n",
              "\n",
              " Stochastic games have probability elements. Need chance nodes to account for this (another layer in tree). Denote possible pathways with expected values. You can still prune with chance nodes, just find their range.\n",
              "\n",
              "\n",
              "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 16.3 Utility Functions\n",
              " Your summary here \n",
              "\n",
              "## Module 5 Lecture Notes\n",
              " Your summary here \n",
              "\n",
              "## Module 5 Definitions\n",
              "* **Transposition table** - save computed minimax values of visited states to save repetitive computation\n",
              "\n",
              "\n",
              "# Module 6: Constraint Satisfaction Problems\n",
              "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
              "\n",
              "\n",
              " Path consistency constrains triples of variables.\n",
              "\n",
              " K-consistency: CSP is k-consistent if for any set of k-1 vars, can find a consistent assignment for a kth var. 1,2,3 = node, arc, path.\n",
              "\n",
              " Strongly k-consistent is same concept as strong induction.\n",
              "\n",
              " Global constraint: involving arbitrary number of variables, not necessarily all like AllDiff.\n",
              "\n",
              "\n",
              "## AIMA Chapter 6.3 Backtracking Search for CSPs\n",
              "\n",
              "\n",
              " Keep things commutative (only consider assigning 1 val to 1 variable per node, so we don't get AB BA issue where they end up in same state later. this would be tree search).\n",
              "\n",
              " Constraint learning, no-goods\n",
              "\n",
              " MAC (maintain arc consistency) is a way of interleaving search and inference. AC-3 is pure inference. MAC runs while assigning variables in backtracking search. Instead of queueing all arcs, MAC only queues arcs incident on the assigned variable. Then, it runs identically to AC-3. \n",
              "\n",
              "\n",
              "## AIMA Chapter 6.4 Local Search for CSPs\n",
              "\n",
              "\n",
              " Min-conflicts is really effective for CSPs. Pick and assign values with minimal conflicts. Constraint weighing is also a thing that helps.\n",
              "\n",
              "\n",
              "## AIMA Chapter 6.5 The Structure of Problems\n",
              "\n",
              "\n",
              " Can use graphs, CCs, topo sort, trees to more efficiently solve CSP.\n",
              "\n",
              " Cycle cutset: make a graph a tree by fulfilling x amount of variables (removing their nodes bc they have value now). Obviously we have to try multiple values, but after we get the tree we can just run the tree algo with topo sort to assign variables through narrowing down parent to child. Saves us time from backtracking.\n",
              "\n",
              " Tree decomposition techniques just turn the CSP into tree with CCs. Nodes in multiple CCs need to be included in all paths between each others' CCs. Tree width = 1 less than size of largest node.\n",
              "\n",
              " Tree is more efficient than cycle. Whenever you have a cycle-cutset of size cc, there is also a tree of width w<c+1w<c+1, and it may be far smaller in some cases. Tree decomposition subproblems are efficient if tree width is small.\n",
              "\n",
              "\n",
              "## Module 6 Lecture Notes\n",
              "\n",
              "\n",
              " Planning: sequences of actions, the path to the goal is the important thing, paths have various costs, depths, heuristics give problem-specific guidance\n",
              "\n",
              " Identification: assignments to variables, the goal itself is important, not the path, all paths at the same depth (for some formulations). CSP is specialized search for this!\n",
              "\n",
              " Big idea of CSP: no hand-tuning solution, just apply logic constraints to all kinds of problems and plug in generic algorithm\n",
              "\n",
              " Solution to CSP is complete (every var assigned) and consistent (follows all constraints, legal assignment).\n",
              "\n",
              " Example applications: map coloring, scheduling, floor planning for circuitry, sudoku, etc\n",
              "\n",
              " Structure of CSP: Constraint graph, nodes are variables, arcs are (binary) constraints. can be discrete or continuous (lin prog). can have lower/higher order constraints, and even preferences.\n",
              "\n",
              " Default uninformed algo for CSP: backtracking search\n",
              "\n",
              " Improvements: heuristics (which var should be assigned next (most constrained, minimum-remaining-values heuristic (fewest legal vals)), degree heuristic (most arcs)), what order should values be tried (least-constraining-value heuristic), can we detect fails early (forward checks))\n",
              "\n",
              " Forward checking: keep track of remaining legal values for each var. Terminate search when any unassigned var has no possible values left.\n",
              "\n",
              " Constraint propogation & AC-3: repeatedly enforces constraints locally. CSP solvers combine search (assigning vals) and inference (eliminating possible vals).\n",
              "\n",
              " Local consistency: node consistency (unary constraint on self), arc consistency (binary constraints) etc.\n",
              "\n",
              " AC-3: worse case time = O(n^2 * d^3). All nodes can be connected to every other node (num arcs = n^2), d values so checking 1 arc is d^2, each arc can only be inserted to queue d times.\n",
              "\n",
              "\n",
              "## Module 6 Definitions\n",
              "* **Concept** - definition\n",
              "\n",
              "\n",
              "# Module 7: Logical Agents\n",
              "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.2 The Wumpus World\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.3 Logic\n",
              " Your summary here \n",
              "\n",
              "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
              " Your summary here \n",
              "\n",
              "## AIMA 7.5 Propositional Theorem Proving\n",
              " Your summary here \n",
              "\n",
              "## Module 7 Lecture Notes\n",
              "\n",
              "\n",
              " Axioms are given sentences, and there are Derived sentences (what it sounds like)\n",
              "\n",
              " Models are \"possible worlds\" with truth values for each sentence. M(a) means set of all models where sentence a is true. If a is true in m we say m satisfies a or m is a model of a.\n",
              "\n",
              " Entails is basically implies. a entails b iff M(a) is a proper subset of M(b) (a is stronger/more specific than b).\n",
              "\n",
              "\n",
              "## Module 7 Definitions\n",
              "* **Concept** - definition\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))"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [],
      "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
