├── .gitignore ├── README.md ├── README_en.md ├── attachments ├── README-1.png └── README.png ├── materials ├── course_page │ ├── CS 188 Spring 2024 _ Introduction to Artificial Intelligence at UC Berkeley.html │ └── CS 188 Spring 2024 _ Introduction to Artificial Intelligence at UC Berkeley_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── logo.png │ │ ├── lunr.min.js.下载 │ │ └── tocbot.min.js.下载 ├── disc&hw │ ├── disc01-regular-sols.pdf │ ├── disc02-regular-sols.pdf │ ├── hw01-sols.pdf │ └── hw02-sols.pdf ├── original_note │ ├── cs188-sp24-note01.pdf │ ├── cs188-sp24-note02.pdf │ ├── cs188-sp24-note03.pdf │ ├── cs188-sp24-note04.pdf │ ├── cs188-sp24-note05.pdf │ ├── cs188-sp24-note06.pdf │ ├── cs188-sp24-note07.pdf │ ├── cs188-sp24-note08.pdf │ ├── cs188-sp24-note09.pdf │ ├── cs188-sp24-note10.pdf │ ├── cs188-sp24-note11.pdf │ ├── cs188-sp24-note12.pdf │ ├── cs188-sp24-note13.pdf │ ├── cs188-sp24-note14.pdf │ ├── cs188-sp24-note15.pdf │ ├── cs188-sp24-note16.pdf │ ├── cs188-sp24-note17.pdf │ ├── cs188-sp24-note18.pdf │ ├── cs188-sp24-note19.pdf │ ├── cs188-sp24-note20.pdf │ ├── cs188-sp24-note21.pdf │ ├── cs188-sp24-note22.pdf │ ├── cs188-sp24-note24.pdf │ └── cs188-sp24-note25.pdf └── project │ ├── intro_page │ ├── Project 0 _ CS 188 Spring 2024.html │ ├── Project 0 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── ml_check_dependencies.png │ │ └── tocbot.min.js.下载 │ ├── Project 1 _ CS 188 Spring 2024.html │ ├── Project 1 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── maze.png │ │ └── tocbot.min.js.下载 │ ├── Project 2 _ CS 188 Spring 2024.html │ ├── Project 2 _ CS 188 Spring 2024_files │ │ ├── alpha_beta_impl.png │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── minimax_depth.png │ │ ├── pacman_multi_agent.png │ │ └── tocbot.min.js.下载 │ ├── Project 3 _ CS 188 Spring 2024.html │ ├── Project 3 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── bottom_left_logic.png │ │ ├── conjoin_diagram.png │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── logic_tree.png │ │ ├── logical_pacman.png │ │ ├── lunr.min.js.下载 │ │ └── tocbot.min.js.下载 │ ├── Project 4 _ CS 188 Spring 2024.html │ ├── Project 4 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── busters.png │ │ ├── busters_bayes_net_simplified.png │ │ ├── busters_greedy_pacman.png │ │ ├── busters_hmm_time_elapse.png │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ └── tocbot.min.js.下载 │ ├── Project 5 _ CS 188 Spring 2024.html │ ├── Project 5 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── ml_check_dependencies.png │ │ ├── ml_chrome_translate.png │ │ ├── ml_project_teaser.png │ │ ├── ml_rnn.png │ │ └── tocbot.min.js.下载 │ ├── Project 6 _ CS 188 Spring 2024.html │ ├── Project 6 _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── q_learning.png │ │ ├── tocbot.min.js.下载 │ │ ├── value_2_paths.png │ │ └── value_iter_diagram.png │ ├── Projects _ CS 188 Spring 2024.html │ └── Projects _ CS 188 Spring 2024_files │ │ ├── auto-render.min.js.下载 │ │ ├── jquery.min.js.下载 │ │ ├── just-the-docs-default.css │ │ ├── just-the-docs-head-nav.css │ │ ├── just-the-docs.js.下载 │ │ ├── katex.min.css │ │ ├── katex.min.js.下载 │ │ ├── lunr.min.js.下载 │ │ ├── pacman_game.gif │ │ └── tocbot.min.js.下载 │ └── original_zip │ ├── 0_tutorial.zip │ ├── 1_search.zip │ ├── 2_multiagent.zip │ ├── 3_logic.zip │ ├── 4_tracking.zip │ ├── 5_machinelearning.zip │ ├── 5_machinelearningpytorch.zip │ ├── 6_reinforcement.zip │ └── 6_reinforcement_pytorch.zip ├── note ├── 01-Intro_to_AI_Rational_Agents.md ├── 02-State_Spaces_Uninformed_Search.md ├── 03-Informed_Search_Astar_and_Heuristics.md ├── 04-Local_Search.md ├── 05-Trees_Minimax_Pruning.md ├── 06-Expectimax_Monte_Carlo_Tree_Search.md ├── 07-Propositional_Logic_and_Planning.md ├── 08-DPLL&ForwardChaining.md ├── 09-First_Order_Logic.md ├── 10-Intro_to_Probability.md ├── 11-Bayesian_Network_Intro.md ├── 12-Variable_Elimination.md ├── 13-Approximate_Inference.md ├── 14-Markov_Models.md ├── 15-Hidden_Marko_Models.md ├── 16-PF-DN-VPI.md ├── 17-Markov_Decision_Processes.md ├── 18-Iteration.md ├── 19-Navie_Bayes.md ├── 20-Perceptron.md ├── 21-Regression.md ├── 22-Neural_Networks.md ├── 24-Reinforcement_Learnin.md ├── README.md ├── attachments │ ├── 02_Search-State-Spaces-Uninformed-Search-1.png │ ├── 02_Search-State-Spaces-Uninformed-Search-2.png │ ├── 02_Search-State-Spaces-Uninformed-Search-3.png │ ├── 02_Search-State-Spaces-Uninformed-Search.png │ ├── 02_State-Spaces-Uninformed-Search.png │ ├── 03_State-Spaces-Uninformed-Search-1.png │ ├── 03_State-Spaces-Uninformed-Search-2.png │ ├── 03_State-Spaces-Uninformed-Search-3.png │ ├── 03_State-Spaces-Uninformed-Search-4.png │ ├── 03_State-Spaces-Uninformed-Search-5.png │ ├── 03_State-Spaces-Uninformed-Search-6.png │ ├── 03_State-Spaces-Uninformed-Search.png │ ├── 04_Local-Search-1.png │ ├── 04_Local-Search-2.png │ ├── 04_Local-Search-3.png │ ├── 04_Local-Search.png │ ├── 05_Trees-Minimax-Pruning-1.png │ ├── 05_Trees-Minimax-Pruning-2.png │ ├── 05_Trees-Minimax-Pruning-3.png │ ├── 05_Trees-Minimax-Pruning-4.png │ ├── 05_Trees-Minimax-Pruning-5.png │ ├── 05_Trees-Minimax-Pruning-6.png │ ├── 05_Trees-Minimax-Pruning-7.png │ ├── 05_Trees-Minimax-Pruning-8.png │ ├── 05_Trees-Minimax-Pruning.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-1.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-2.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-3.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-4.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-5.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search-6.png │ ├── 06_Expectimax-Monte-Carlo-Tree-Search.png │ ├── 07-Propositional_Logic_and_Planning-1.png │ ├── 07-Propositional_Logic_and_Planning-2.png │ ├── 07-Propositional_Logic_and_Planning.png │ ├── 09-First_Order_Logic.png │ ├── 10-Intro_to_Probability.png │ ├── 11-Bayesian_Network_Intro-1.png │ ├── 11-Bayesian_Network_Intro.png │ ├── 12-Variable_Elimination-1.png │ ├── 12-Variable_Elimination.png │ ├── 13_Approximate Inference.png │ ├── 14-Markov_Models.png │ ├── 15-Hidden_Marko_Models-1.png │ ├── 15-Hidden_Marko_Models-2.png │ ├── 15-Hidden_Marko_Models.png │ ├── 15-PF-DN-OT-VPI.png │ ├── 15-PF-DN-VPI.png │ ├── 15-Particle_Filtering.png │ ├── 17-Markov_Decision_Processes-1.png │ ├── 17-Markov_Decision_Processes-2.png │ ├── 17-Markov_Decision_Processes.png │ ├── 18-Iteration.png │ ├── 19-Machine_Learning.png │ ├── 19-Navie_Bayes.png │ ├── 20-Perceptron-1.png │ ├── 20-Perceptron-2.png │ ├── 20-Perceptron-3.png │ ├── 20-Perceptron.png │ ├── 21-Regression-1.png │ ├── 21-Regression.png │ ├── 22-Neural_Networks-1.png │ ├── 22-Neural_Networks-2.png │ ├── 22-Neural_Networks-3.png │ ├── 22-Neural_Networks.png │ └── 24-Reinforcement_Learnin.png └── problem.md └── project ├── README.md ├── attachments ├── project-0.png ├── project-1-1.png ├── project-1-2.png ├── project-1-3.png ├── project-1-4.png ├── project-1-5.png ├── project-1-6.png ├── project-1-7.png ├── project-1-8.png ├── project-1-9.png ├── project-1.png ├── project-2-1.png ├── project-2-10.png ├── project-2-11.png ├── project-2-12.png ├── project-2-13.png ├── project-2-2.png ├── project-2-3.png ├── project-2-4.png ├── project-2-5.png ├── project-2-6.png ├── project-2-7.png ├── project-2-8.png ├── project-2-9.png ├── project-2.png ├── project-3.png ├── project-4-1.png ├── project-4-2.png ├── project-4-3.png ├── project-4-4.png └── project-4.png ├── project-0.md ├── project-1.md ├── project-2.md ├── project-3.md └── project-4.md /.gitignore: -------------------------------------------------------------------------------- 1 | project/cs188_solution 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cs188 - sp24 2 | 3 | > 中文 | [English](README_en.md) 4 | 5 | > [!warning] 6 | > 7 | > 基于课程代码 License: 8 | > 9 | > ``` 10 | > # Licensing Information: You are free to use or extend these projects for 11 | > # educational purposes provided that (1) you do not distribute or publish 12 | > # solutions, (2) you retain this notice, and (3) you provide clear 13 | > # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 14 | > ``` 15 | > 16 | > 撤去直接可运行代码,project 解释笔记保留,fork 仓库不予负责。 17 | 18 | ## 介绍 19 | 20 | [这个仓库](https://github.com/Darstib/cs188)存放的是 UCB [CS 188 Spring 2024](https://inst.eecs.berkeley.edu/~cs188/sp24/) 的笔记&自学资料(已索引至 [Deepwiki](https://deepwiki.com/darstib/cs188));理论上,你学习该课程所需要的全部资料都可以在这里及给出的外链中找到,项目来自 [ai.berkeley.edu](http://ai.berkeley.edu). 21 | 22 | - 笔记:主体为原课程 notes[^1],加入了自己的思考和排版,在[我的博客](https://darstib.github.io/blog/note/cs188/)上你可以阅读这些笔记;但为了更好的观感,建议使用 obsidian 查看,见使用-阅读。 23 | - 自学资料:由于 UCB 近年的部分课程开始需要 [CalNet Authentication Service](https://auth.berkeley.edu/cas/login?service=https%3a%2f%2finst.eecs.berkeley.edu%2f%7ecs188%2fsp23%2f),为了便于之后的学习,将我认为自学需要的资料存档于[本仓库](https://github.com/darstib/cs188);由于不清楚如何申请转载权限,故若[本项目](https://github.com/darstib/cs188)对[原课程](https://inst.eecs.berkeley.edu/~cs188/sp24/)及其[相关项目](http://ai.berkeley.edu)产生不良影响,请[联系我](https://darstib.github.io/blog/connect_me/) 删除。 24 | - 如果对[搜索算法](https://oi-wiki.org/search/)了然于心、对 ML/DL/RL 知识较为熟悉且希望接触一些小的项目文件,大可直接做 project。 25 | 26 | [^1]: 其一,我不能确保我的翻译正确性;其二,网页/obsidian 阅读已经能够借助很多插件辅组阅读,可参考[读 / 写文章](https://darstib.github.io/blog/collection/Tools/#i4);其三,本人精力有限,恕不能完全打造一个 CS188 全中文阅读环境。 27 | 28 | ## 目录 29 | 30 | ### note&project 31 | 32 | - Intro 33 | - [01-Intro_to_AI_Rational_Agents](note/01-Intro_to_AI_Rational_Agents.md) 34 | - [project-0](project/project-0.md) 35 | - Search 36 | - [02-State_Spaces_Uninformed_Search](note/02-State_Spaces_Uninformed_Search.md) 37 | - [03-Informed_Search_Astar_and_Heuristics](note/03-Informed_Search_Astar_and_Heuristics.md) 38 | - [04-Local_Search](note/04-Local_Search.md) 39 | - [project-1](project/project-1.md) 40 | - Multi-Agent Search 41 | - [05-Trees_Minimax_Pruning](note/05-Trees_Minimax_Pruning.md) 42 | - [06-Expectimax_Monte_Carlo_Tree_Search](note/06-Expectimax_Monte_Carlo_Tree_Search.md) 43 | - [project-2](project/project-2.md) 44 | - Logic and Classical Planning 45 | - [07-Propositional_Logic_and_Planning](note/07-Propositional_Logic_and_Planning.md) 46 | - [08-DPLL&ForwardChaining](note/08-DPLL&ForwardChaining.md) 47 | - [09-First_Order_Logic](note/09-First_Order_Logic.md) 48 | - [project-3](project/project-3.md) 49 | - Ghostbusters 50 | - [10-Intro_to_Probability](note/10-Intro_to_Probability.md) 51 | - [11-Bayesian_Network_Intro](note/11-Bayesian_Network_Intro.md) 52 | - [12-Variable_Elimination](note/12-Variable_Elimination.md) 53 | - [13-Approximate_Inference](note/13-Approximate_Inference.md) 54 | - [14-Markov_Models](note/14-Markov_Models.md) 55 | - [15-Hidden_Marko_Models](note/15-Hidden_Marko_Models.md) 56 | - [16-PF-DN-VPI](note/16-PF-DN-VPI.md) 57 | - [17-Markov_Decision_Processes](note/17-Markov_Decision_Processes.md) 58 | - [project-4](project/project-4.md) 59 | - Machine/Reinforcement Learning 60 | - [18-Iteration](note/18-Iteration.md) 61 | - [19-Navie_Bayes](note/19-Navie_Bayes.md) 62 | - [20-Perceptron](note/20-Perceptron.md) 63 | - [21-Regression](note/21-Regression.md) 64 | - [22-Neural_Networks](note/22-Neural_Networks.md) 65 | - [24-Reinforcement_Learnin](note/24-Reinforcement_Learnin.md) 66 | - project5/6 无讲解 67 | - project 6 - Q7 代码已完成,但是训练结果很差,无处调试,遂放弃。 68 | 69 | ### materials 70 | 71 | - course_page 72 | - 课程网站的 calendar,便于查看如何自学; 73 | - disc 74 | - 相关讨论题及其题解; 75 | - origianl_note 76 | - 课程原笔记,理论上查看上述本人 note 足矣; 77 | - project 78 | - original_zip 79 | - 原 project 源码; 80 | - intro_page 81 | - 保留的实验文档的页面文件。 82 | - ~~[solution](https://github.com/Darstib/cs188/tree/main/project/solution)~~ 83 | - ~~参考代码(移动至 `cs188/project/solution/` 中)~~ 84 | - [gradecode](https://www.gradescope.com/) 85 | - 4VK322。 86 | 87 | ## 使用 88 | 89 | ### 下载 90 | 91 | #### 使用 git 92 | 93 | ```shell 94 | git clone https://github.com/Darstib/cs188.git 95 | ``` 96 | 97 | #### 直接全部下载 98 | 99 | ![](attachments/README.png) 100 | 101 | #### 部分下载 102 | 103 | 如果只是想要 note 或者 project 部分或者其他单独一个文件夹,可以使用 [DownGit](https://download-directory.github.io/),输入目标文件夹在此 git 仓库的 url 即可。 104 | 105 | ### 阅读 106 | 107 | > 从头开始获取一个比较好的阅读体验可以看[这里](https://darstib.github.io/blog/tutorial/begin/Obsidian_begin/#ii);要求不高的话简单版如下: 108 | 109 | 1. 获取 [obsidian](https://obsidian.md); 110 | 2. [导入 markdown](https://publish.obsidian.md/help-zh/import/markdown); 111 | 3. 点击右上角进入阅读视图即可。 112 | 113 | ![](attachments/README-1.png) 114 | -------------------------------------------------------------------------------- /README_en.md: -------------------------------------------------------------------------------- 1 | # cs188 - sp24 2 | 3 | > [中文](README.md) | English 4 | 5 | > [!warning] 6 | > 7 | > Based on the course code license, directly runnable code has been removed. Project explanation notes are retained. No responsibility is taken for forked repositories. 8 | 9 | ## Introduction 10 | 11 | [This repository](https://github.com/Darstib/cs188) contains notes and self-study materials for UC Berkeley's [CS 188 Spring 2024](https://inst.eecs.berkeley.edu/~cs188/sp24/). Theoretically, all the materials you need to study this course can be found here and in the provided external links. The projects are from [ai.berkeley.edu](http://ai.berkeley.edu). 12 | 13 | - Notes: Primarily based on the original course notes[^1], with my own thoughts and formatting added. You can read these notes on [my blog](https://darstib.github.io/blog/note/CS188/). However, for a better viewing experience, it's recommended to use Obsidian. See Usage - Reading. 14 | - Self-study materials: Since some of UC Berkeley's recent courses require [CalNet Authentication Service](https://auth.berkeley.edu/cas/login?service=https%3a%2f%2finst.eecs.berkeley.edu%2f%7ecs188%2fsp23%2f), for ease of future study, I've archived the materials I consider necessary for self-study in [this repository](https://github.com/Darstib/cs188). Due to uncertainty about how to request permission for redistribution, if [this project](https://github.com/Darstib/cs188) has any adverse effects on the [original course](https://inst.eecs.berkeley.edu/~cs188/sp24/) and its related projects, please [contact me](https://darstib.github.io/blog/connect_me/) to remove it. 15 | - If you are familiar with [search algorithms](https://oi-wiki.org/search/), have a good understanding of ML/DL/RL concepts, and wish to explore some small project files, you can directly work on the projects. 16 | 17 | [^1]: Firstly, I cannot guarantee the accuracy of my translations. Secondly, reading on the web/Obsidian already allows the use of many plugins to aid reading, see [Reading/Writing Articles](https://darstib.github.io/blog/collection/Tools/#i4). Thirdly, my energy is limited, and I apologize for not being able to completely create a full Chinese reading environment for CS188. 18 | 19 | ## Table of Contents 20 | 21 | ### note&project 22 | 23 | - Intro 24 | - [01-Intro_to_AI_Rational_Agents](note/01-Intro_to_AI_Rational_Agents.md) 25 | - [project-0](project/project-0.md) 26 | - Search 27 | - [02-State_Spaces_Uninformed_Search](note/02-State_Spaces_Uninformed_Search.md) 28 | - [03-Informed_Search_Astar_and_Heuristics](note/03-Informed_Search_Astar_and_Heuristics.md) 29 | - [04-Local_Search](note/04-Local_Search.md) 30 | - [project-1](project/project-1.md) 31 | - Multi-Agent Search 32 | - [05-Trees_Minimax_Pruning](note/05-Trees_Minimax_Pruning.md) 33 | - [06-Expectimax_Monte_Carlo_Tree_Search](note/06-Expectimax_Monte_Carlo_Tree_Search.md) 34 | - [project-2](project/project-2.md) 35 | - Logic and Classical Planning 36 | - [07-Propositional_Logic_and_Planning](note/07-Propositional_Logic_and_Planning.md) 37 | - [08-DPLL&ForwardChaining](note/08-DPLL&ForwardChaining.md) 38 | - [09-First_Order_Logic](note/09-First_Order_Logic.md) 39 | - [project-3](project/project-3.md) 40 | - Ghostbusters 41 | - [10-Intro_to_Probability](note/10-Intro_to_Probability.md) 42 | - [11-Bayesian_Network_Intro](note/11-Bayesian_Network_Intro.md) 43 | - [12-Variable_Elimination](note/12-Variable_Elimination.md) 44 | - [13-Approximate_Inference](note/13-Approximate_Inference.md) 45 | - [14-Markov_Models](note/14-Markov_Models.md) 46 | - [15-Hidden_Marko_Models](note/15-Hidden_Marko_Models.md) 47 | - [16-PF-DN-VPI](note/16-PF-DN-VPI.md) 48 | - [17-Markov_Decision_Processes](note/17-Markov_Decision_Processes.md) 49 | - [project-4](project/project-4.md) 50 | - Machine/Reinforcement Learning 51 | - [18-Iteration](note/18-Iteration.md) 52 | - [19-Navie_Bayes](note/19-Navie_Bayes.md) 53 | - [20-Perceptron](note/20-Perceptron.md) 54 | - [21-Regression](note/21-Regression.md) 55 | - [22-Neural_Networks](note/22-Neural_Networks.md) 56 | - [24-Reinforcement_Learnin](note/24-Reinforcement_Learnin.md) 57 | - project5/6 No explanation provided. 58 | - project 6 - Q7 code is complete, but the training results are very poor and there's nowhere to debug, so I gave up. 59 | 60 | ### materials 61 | 62 | - course_page 63 | - The course website's calendar, for easy reference on how to self-study. 64 | - disc 65 | - Relevant discussion problems and their solutions. 66 | - origianl_note 67 | - The original course notes. Theoretically, reading my notes above should suffice. 68 | - project 69 | - original_zip 70 | - The original project source code. 71 | - intro_page 72 | - Archived page files of the lab documentation. 73 | - ~~[solution](https://github.com/Darstib/cs188/tree/main/project/solution)~~ 74 | - Reference code (moved to `cs188/project/solution/`) 75 | - [gradecode](https://www.gradescope.com/) 76 | - 4VK322. 77 | 78 | Based on the course code license: 79 | 80 | ``` 81 | # Licensing Information: You are free to use or extend these projects for 82 | # educational purposes provided that (1) you do not distribute or publish 83 | # solutions, (2) you retain this notice, and (3) you provide clear 84 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 85 | ``` 86 | 87 | Directly runnable code has been removed. Project explanation notes are retained. No responsibility is taken for forked repositories. 88 | 89 | ## Usage 90 | 91 | ### Download 92 | 93 | #### Using git 94 | 95 | ```shell 96 | git clone https://github.com/Darstib/cs188.git 97 | ``` 98 | 99 | #### Download everything directly 100 | 101 | ![](attachments/README.png) 102 | 103 | #### Partial Download 104 | 105 | If you only want the notes, projects, or another individual folder, you can use [DownGit](https://download-directory.github.io/). Just enter the URL of the target folder within this git repository. 106 | 107 | ### Reading 108 | 109 | > For a good reading experience from scratch, you can look [here](https://darstib.github.io/blog/tutorial/begin/Obsidian_begin/#ii). A simplified version for lower requirements is as follows: 110 | 111 | 1. Get [Obsidian](https://obsidian.md). 112 | 2. [Import Markdown](https://publish.obsidian.md/help-zh/import/markdown). 113 | 3. Click the top-right corner to enter reading view. 114 | 115 | ![](attachments/README-1.png) 116 | 117 | -------------------------------------------------------------------------------- /attachments/README-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/attachments/README-1.png -------------------------------------------------------------------------------- /attachments/README.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/attachments/README.png -------------------------------------------------------------------------------- /materials/course_page/CS 188 Spring 2024 _ Introduction to Artificial Intelligence at UC Berkeley_files/auto-render.min.js.下载: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a{var e={163:e=>{e.exports=function(e){var t,n=[].forEach,l=[].some,o=document.body,i=!0,r=" ";function s(t,l){var o,i,c,d=l.appendChild((o=t,i=document.createElement("li"),c=document.createElement("a"),e.listItemClass&&i.setAttribute("class",e.listItemClass),e.onClick&&(c.onclick=e.onClick),e.includeTitleTags&&c.setAttribute("title",o.textContent),e.includeHtml&&o.childNodes.length?n.call(o.childNodes,(function(e){c.appendChild(e.cloneNode(!0))})):c.textContent=o.textContent,c.setAttribute("href",e.basePath+"#"+o.id),c.setAttribute("class",e.linkClass+r+"node-name--"+o.nodeName+r+e.extraLinkClasses),i.appendChild(c),i));if(t.children.length){var u=a(t.isCollapsed);t.children.forEach((function(e){s(e,u)})),d.appendChild(u)}}function a(t){var n=e.orderedList?"ol":"ul",l=document.createElement(n),o=e.listClass+r+e.extraListClasses;return t&&(o+=r+e.collapsibleClass,o+=r+e.isCollapsedClass),l.setAttribute("class",o),l}function c(t){var n=0;return null!==t&&(n=t.offsetTop,e.hasInnerContainers&&(n+=c(t.offsetParent))),n}function d(t){return t&&-1!==t.className.indexOf(e.collapsibleClass)&&-1!==t.className.indexOf(e.isCollapsedClass)?(t.className=t.className.split(r+e.isCollapsedClass).join(""),d(t.parentNode.parentNode)):t}return{enableTocAnimation:function(){i=!0},disableTocAnimation:function(t){var n=t.target||t.srcElement;"string"==typeof n.className&&-1!==n.className.indexOf(e.linkClass)&&(i=!1)},render:function(e,n){var l=a(!1);if(n.forEach((function(e){s(e,l)})),null!==(t=e||t))return t.firstChild&&t.removeChild(t.firstChild),0===n.length?t:t.appendChild(l)},updateToc:function(s){var a;a=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop,e.positionFixedSelector&&function(){var n;n=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop;var l=document.querySelector(e.positionFixedSelector);"auto"===e.fixedSidebarOffset&&(e.fixedSidebarOffset=t.offsetTop),n>e.fixedSidebarOffset?-1===l.className.indexOf(e.positionFixedClass)&&(l.className+=r+e.positionFixedClass):l.className=l.className.split(r+e.positionFixedClass).join("")}();var u,f=s;if(i&&null!==t&&f.length>0){l.call(f,(function(t,n){return c(t)>a+e.headingsOffset+10?(u=f[0===n?n:n-1],!0):n===f.length-1?(u=f[f.length-1],!0):void 0}));var m=t.querySelectorAll("."+e.linkClass);n.call(m,(function(t){t.className=t.className.split(r+e.activeLinkClass).join("")}));var h=t.querySelectorAll("."+e.listItemClass);n.call(h,(function(t){t.className=t.className.split(r+e.activeListItemClass).join("")}));var p=t.querySelector("."+e.linkClass+".node-name--"+u.nodeName+'[href="'+e.basePath+"#"+u.id.replace(/([ #;&,.+*~':"!^$[\]()=>|/@])/g,"\\$1")+'"]');p&&-1===p.className.indexOf(e.activeLinkClass)&&(p.className+=r+e.activeLinkClass);var C=p&&p.parentNode;C&&-1===C.className.indexOf(e.activeListItemClass)&&(C.className+=r+e.activeListItemClass);var g=t.querySelectorAll("."+e.listClass+"."+e.collapsibleClass);n.call(g,(function(t){-1===t.className.indexOf(e.isCollapsedClass)&&(t.className+=r+e.isCollapsedClass)})),p&&p.nextSibling&&-1!==p.nextSibling.className.indexOf(e.isCollapsedClass)&&(p.nextSibling.className=p.nextSibling.className.split(r+e.isCollapsedClass).join("")),d(p&&p.parentNode.parentNode)}}}}},547:e=>{e.exports={tocSelector:".js-toc",contentSelector:".js-toc-content",headingSelector:"h1, h2, h3",ignoreSelector:".js-toc-ignore",hasInnerContainers:!1,linkClass:"toc-link",extraLinkClasses:"",activeLinkClass:"is-active-link",listClass:"toc-list",extraListClasses:"",isCollapsedClass:"is-collapsed",collapsibleClass:"is-collapsible",listItemClass:"toc-list-item",activeListItemClass:"is-active-li",collapseDepth:0,scrollSmooth:!0,scrollSmoothDuration:420,scrollSmoothOffset:0,scrollEndCallback:function(e){},headingsOffset:1,throttleTimeout:50,positionFixedSelector:null,positionFixedClass:"is-position-fixed",fixedSidebarOffset:"auto",includeHtml:!1,includeTitleTags:!1,onClick:function(e){},orderedList:!0,scrollContainer:null,skipRendering:!1,headingLabelCallback:!1,ignoreHiddenElements:!1,headingObjectCallback:null,basePath:"",disableTocScrollSync:!1}},971:function(e,t,n){var l,o,i;o=[],l=function(e){"use strict";var t,l,o,i=n(547),r={},s={},a=n(163),c=n(279),d=n(938),u=!!(e&&e.document&&e.document.querySelector&&e.addEventListener);if("undefined"!=typeof window||u){var f=Object.prototype.hasOwnProperty;return s.destroy=function(){var e=h(r);null!==e&&(r.skipRendering||e&&(e.innerHTML=""),r.scrollContainer&&document.querySelector(r.scrollContainer)?(document.querySelector(r.scrollContainer).removeEventListener("scroll",this._scrollListener,!1),document.querySelector(r.scrollContainer).removeEventListener("resize",this._scrollListener,!1),t&&document.querySelector(r.scrollContainer).removeEventListener("click",this._clickListener,!1)):(document.removeEventListener("scroll",this._scrollListener,!1),document.removeEventListener("resize",this._scrollListener,!1),t&&document.removeEventListener("click",this._clickListener,!1)))},s.init=function(e){if(u){r=function(){for(var e={},t=0;t{e.exports=function(e){var t=[].reduce;function n(e){return e[e.length-1]}function l(e){return+e.nodeName.toUpperCase().replace("H","")}function o(t){if(!(t instanceof window.HTMLElement))return t;if(e.ignoreHiddenElements&&(!t.offsetHeight||!t.offsetParent))return null;const n=t.getAttribute("data-heading-label")||(e.headingLabelCallback?String(e.headingLabelCallback(t.textContent)):t.textContent.trim());var o={id:t.id,children:[],nodeName:t.nodeName,headingLevel:l(t),textContent:n};return e.includeHtml&&(o.childNodes=t.childNodes),e.headingObjectCallback?e.headingObjectCallback(o,t):o}return{nestHeadingsArray:function(l){return t.call(l,(function(t,l){var i=o(l);return i&&function(t,l){for(var i=o(t),r=i.headingLevel,s=l,a=n(s),c=r-(a?a.headingLevel:0);c>0&&(!(a=n(s))||r!==a.headingLevel);)a&&void 0!==a.children&&(s=a.children),c--;r>=e.collapseDepth&&(i.isCollapsed=!0),s.push(i)}(i,t.nest),t}),{nest:[]})},selectHeadings:function(t,n){var l=n;e.ignoreSelector&&(l=n.split(",").map((function(t){return t.trim()+":not("+e.ignoreSelector+")"})));try{return t.querySelectorAll(l)}catch(e){return console.warn("Headers not found with selector: "+l),null}}}}},374:(e,t)=>{t.initSmoothScrolling=function(e){var t=e.duration,n=e.offset,l=location.hash?o(location.href):location.href;function o(e){return e.slice(0,e.lastIndexOf("#"))}document.body.addEventListener("click",(function(i){var r;"a"!==(r=i.target).tagName.toLowerCase()||!(r.hash.length>0||"#"===r.href.charAt(r.href.length-1))||o(r.href)!==l&&o(r.href)+"#"!==l||i.target.className.indexOf("no-smooth-scroll")>-1||"#"===i.target.href.charAt(i.target.href.length-2)&&"!"===i.target.href.charAt(i.target.href.length-1)||-1===i.target.className.indexOf(e.linkClass)||function(e,t){var n,l,o=window.pageYOffset,i={duration:t.duration,offset:t.offset||0,callback:t.callback,easing:t.easing||function(e,t,n,l){return(e/=l/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t}},r=document.querySelector('[id="'+decodeURI(e).split("#").join("")+'"]')||document.querySelector('[id="'+e.split("#").join("")+'"]'),s="string"==typeof e?i.offset+(e?r&&r.getBoundingClientRect().top||0:-(document.documentElement.scrollTop||document.body.scrollTop)):e,a="function"==typeof i.duration?i.duration(s):i.duration;function c(e){l=e-n,window.scrollTo(0,i.easing(l,o,s,a)),l{e.exports=function(e){var t=e.tocElement||document.querySelector(e.tocSelector);if(t&&t.scrollHeight>t.clientHeight){var n=t.querySelector("."+e.activeListItemClass);n&&(t.scrollTop=n.offsetTop)}}}},t={};function n(l){var o=t[l];if(void 0!==o)return o.exports;var i=t[l]={exports:{}};return e[l].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(971)})(); -------------------------------------------------------------------------------- /materials/project/intro_page/Project 1 _ CS 188 Spring 2024_files/auto-render.min.js.下载: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a{var e={163:e=>{e.exports=function(e){var t,n=[].forEach,l=[].some,o=document.body,i=!0,r=" ";function s(t,l){var o,i,c,d=l.appendChild((o=t,i=document.createElement("li"),c=document.createElement("a"),e.listItemClass&&i.setAttribute("class",e.listItemClass),e.onClick&&(c.onclick=e.onClick),e.includeTitleTags&&c.setAttribute("title",o.textContent),e.includeHtml&&o.childNodes.length?n.call(o.childNodes,(function(e){c.appendChild(e.cloneNode(!0))})):c.textContent=o.textContent,c.setAttribute("href",e.basePath+"#"+o.id),c.setAttribute("class",e.linkClass+r+"node-name--"+o.nodeName+r+e.extraLinkClasses),i.appendChild(c),i));if(t.children.length){var u=a(t.isCollapsed);t.children.forEach((function(e){s(e,u)})),d.appendChild(u)}}function a(t){var n=e.orderedList?"ol":"ul",l=document.createElement(n),o=e.listClass+r+e.extraListClasses;return t&&(o+=r+e.collapsibleClass,o+=r+e.isCollapsedClass),l.setAttribute("class",o),l}function c(t){var n=0;return null!==t&&(n=t.offsetTop,e.hasInnerContainers&&(n+=c(t.offsetParent))),n}function d(t){return t&&-1!==t.className.indexOf(e.collapsibleClass)&&-1!==t.className.indexOf(e.isCollapsedClass)?(t.className=t.className.split(r+e.isCollapsedClass).join(""),d(t.parentNode.parentNode)):t}return{enableTocAnimation:function(){i=!0},disableTocAnimation:function(t){var n=t.target||t.srcElement;"string"==typeof n.className&&-1!==n.className.indexOf(e.linkClass)&&(i=!1)},render:function(e,n){var l=a(!1);if(n.forEach((function(e){s(e,l)})),null!==(t=e||t))return t.firstChild&&t.removeChild(t.firstChild),0===n.length?t:t.appendChild(l)},updateToc:function(s){var a;a=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop,e.positionFixedSelector&&function(){var n;n=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop;var l=document.querySelector(e.positionFixedSelector);"auto"===e.fixedSidebarOffset&&(e.fixedSidebarOffset=t.offsetTop),n>e.fixedSidebarOffset?-1===l.className.indexOf(e.positionFixedClass)&&(l.className+=r+e.positionFixedClass):l.className=l.className.split(r+e.positionFixedClass).join("")}();var u,f=s;if(i&&null!==t&&f.length>0){l.call(f,(function(t,n){return c(t)>a+e.headingsOffset+10?(u=f[0===n?n:n-1],!0):n===f.length-1?(u=f[f.length-1],!0):void 0}));var m=t.querySelectorAll("."+e.linkClass);n.call(m,(function(t){t.className=t.className.split(r+e.activeLinkClass).join("")}));var h=t.querySelectorAll("."+e.listItemClass);n.call(h,(function(t){t.className=t.className.split(r+e.activeListItemClass).join("")}));var p=t.querySelector("."+e.linkClass+".node-name--"+u.nodeName+'[href="'+e.basePath+"#"+u.id.replace(/([ #;&,.+*~':"!^$[\]()=>|/@])/g,"\\$1")+'"]');p&&-1===p.className.indexOf(e.activeLinkClass)&&(p.className+=r+e.activeLinkClass);var C=p&&p.parentNode;C&&-1===C.className.indexOf(e.activeListItemClass)&&(C.className+=r+e.activeListItemClass);var g=t.querySelectorAll("."+e.listClass+"."+e.collapsibleClass);n.call(g,(function(t){-1===t.className.indexOf(e.isCollapsedClass)&&(t.className+=r+e.isCollapsedClass)})),p&&p.nextSibling&&-1!==p.nextSibling.className.indexOf(e.isCollapsedClass)&&(p.nextSibling.className=p.nextSibling.className.split(r+e.isCollapsedClass).join("")),d(p&&p.parentNode.parentNode)}}}}},547:e=>{e.exports={tocSelector:".js-toc",contentSelector:".js-toc-content",headingSelector:"h1, h2, h3",ignoreSelector:".js-toc-ignore",hasInnerContainers:!1,linkClass:"toc-link",extraLinkClasses:"",activeLinkClass:"is-active-link",listClass:"toc-list",extraListClasses:"",isCollapsedClass:"is-collapsed",collapsibleClass:"is-collapsible",listItemClass:"toc-list-item",activeListItemClass:"is-active-li",collapseDepth:0,scrollSmooth:!0,scrollSmoothDuration:420,scrollSmoothOffset:0,scrollEndCallback:function(e){},headingsOffset:1,throttleTimeout:50,positionFixedSelector:null,positionFixedClass:"is-position-fixed",fixedSidebarOffset:"auto",includeHtml:!1,includeTitleTags:!1,onClick:function(e){},orderedList:!0,scrollContainer:null,skipRendering:!1,headingLabelCallback:!1,ignoreHiddenElements:!1,headingObjectCallback:null,basePath:"",disableTocScrollSync:!1}},971:function(e,t,n){var l,o,i;o=[],l=function(e){"use strict";var t,l,o,i=n(547),r={},s={},a=n(163),c=n(279),d=n(938),u=!!(e&&e.document&&e.document.querySelector&&e.addEventListener);if("undefined"!=typeof window||u){var f=Object.prototype.hasOwnProperty;return s.destroy=function(){var e=h(r);null!==e&&(r.skipRendering||e&&(e.innerHTML=""),r.scrollContainer&&document.querySelector(r.scrollContainer)?(document.querySelector(r.scrollContainer).removeEventListener("scroll",this._scrollListener,!1),document.querySelector(r.scrollContainer).removeEventListener("resize",this._scrollListener,!1),t&&document.querySelector(r.scrollContainer).removeEventListener("click",this._clickListener,!1)):(document.removeEventListener("scroll",this._scrollListener,!1),document.removeEventListener("resize",this._scrollListener,!1),t&&document.removeEventListener("click",this._clickListener,!1)))},s.init=function(e){if(u){r=function(){for(var e={},t=0;t{e.exports=function(e){var t=[].reduce;function n(e){return e[e.length-1]}function l(e){return+e.nodeName.toUpperCase().replace("H","")}function o(t){if(!(t instanceof window.HTMLElement))return t;if(e.ignoreHiddenElements&&(!t.offsetHeight||!t.offsetParent))return null;const n=t.getAttribute("data-heading-label")||(e.headingLabelCallback?String(e.headingLabelCallback(t.textContent)):t.textContent.trim());var o={id:t.id,children:[],nodeName:t.nodeName,headingLevel:l(t),textContent:n};return e.includeHtml&&(o.childNodes=t.childNodes),e.headingObjectCallback?e.headingObjectCallback(o,t):o}return{nestHeadingsArray:function(l){return t.call(l,(function(t,l){var i=o(l);return i&&function(t,l){for(var i=o(t),r=i.headingLevel,s=l,a=n(s),c=r-(a?a.headingLevel:0);c>0&&(!(a=n(s))||r!==a.headingLevel);)a&&void 0!==a.children&&(s=a.children),c--;r>=e.collapseDepth&&(i.isCollapsed=!0),s.push(i)}(i,t.nest),t}),{nest:[]})},selectHeadings:function(t,n){var l=n;e.ignoreSelector&&(l=n.split(",").map((function(t){return t.trim()+":not("+e.ignoreSelector+")"})));try{return t.querySelectorAll(l)}catch(e){return console.warn("Headers not found with selector: "+l),null}}}}},374:(e,t)=>{t.initSmoothScrolling=function(e){var t=e.duration,n=e.offset,l=location.hash?o(location.href):location.href;function o(e){return e.slice(0,e.lastIndexOf("#"))}document.body.addEventListener("click",(function(i){var r;"a"!==(r=i.target).tagName.toLowerCase()||!(r.hash.length>0||"#"===r.href.charAt(r.href.length-1))||o(r.href)!==l&&o(r.href)+"#"!==l||i.target.className.indexOf("no-smooth-scroll")>-1||"#"===i.target.href.charAt(i.target.href.length-2)&&"!"===i.target.href.charAt(i.target.href.length-1)||-1===i.target.className.indexOf(e.linkClass)||function(e,t){var n,l,o=window.pageYOffset,i={duration:t.duration,offset:t.offset||0,callback:t.callback,easing:t.easing||function(e,t,n,l){return(e/=l/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t}},r=document.querySelector('[id="'+decodeURI(e).split("#").join("")+'"]')||document.querySelector('[id="'+e.split("#").join("")+'"]'),s="string"==typeof e?i.offset+(e?r&&r.getBoundingClientRect().top||0:-(document.documentElement.scrollTop||document.body.scrollTop)):e,a="function"==typeof i.duration?i.duration(s):i.duration;function c(e){l=e-n,window.scrollTo(0,i.easing(l,o,s,a)),l{e.exports=function(e){var t=e.tocElement||document.querySelector(e.tocSelector);if(t&&t.scrollHeight>t.clientHeight){var n=t.querySelector("."+e.activeListItemClass);n&&(t.scrollTop=n.offsetTop)}}}},t={};function n(l){var o=t[l];if(void 0!==o)return o.exports;var i=t[l]={exports:{}};return e[l].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(971)})(); -------------------------------------------------------------------------------- /materials/project/intro_page/Project 2 _ CS 188 Spring 2024_files/alpha_beta_impl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/materials/project/intro_page/Project 2 _ CS 188 Spring 2024_files/alpha_beta_impl.png -------------------------------------------------------------------------------- /materials/project/intro_page/Project 2 _ CS 188 Spring 2024_files/auto-render.min.js.下载: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a{var e={163:e=>{e.exports=function(e){var t,n=[].forEach,l=[].some,o=document.body,i=!0,r=" ";function s(t,l){var o,i,c,d=l.appendChild((o=t,i=document.createElement("li"),c=document.createElement("a"),e.listItemClass&&i.setAttribute("class",e.listItemClass),e.onClick&&(c.onclick=e.onClick),e.includeTitleTags&&c.setAttribute("title",o.textContent),e.includeHtml&&o.childNodes.length?n.call(o.childNodes,(function(e){c.appendChild(e.cloneNode(!0))})):c.textContent=o.textContent,c.setAttribute("href",e.basePath+"#"+o.id),c.setAttribute("class",e.linkClass+r+"node-name--"+o.nodeName+r+e.extraLinkClasses),i.appendChild(c),i));if(t.children.length){var u=a(t.isCollapsed);t.children.forEach((function(e){s(e,u)})),d.appendChild(u)}}function a(t){var n=e.orderedList?"ol":"ul",l=document.createElement(n),o=e.listClass+r+e.extraListClasses;return t&&(o+=r+e.collapsibleClass,o+=r+e.isCollapsedClass),l.setAttribute("class",o),l}function c(t){var n=0;return null!==t&&(n=t.offsetTop,e.hasInnerContainers&&(n+=c(t.offsetParent))),n}function d(t){return t&&-1!==t.className.indexOf(e.collapsibleClass)&&-1!==t.className.indexOf(e.isCollapsedClass)?(t.className=t.className.split(r+e.isCollapsedClass).join(""),d(t.parentNode.parentNode)):t}return{enableTocAnimation:function(){i=!0},disableTocAnimation:function(t){var n=t.target||t.srcElement;"string"==typeof n.className&&-1!==n.className.indexOf(e.linkClass)&&(i=!1)},render:function(e,n){var l=a(!1);if(n.forEach((function(e){s(e,l)})),null!==(t=e||t))return t.firstChild&&t.removeChild(t.firstChild),0===n.length?t:t.appendChild(l)},updateToc:function(s){var a;a=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop,e.positionFixedSelector&&function(){var n;n=e.scrollContainer&&document.querySelector(e.scrollContainer)?document.querySelector(e.scrollContainer).scrollTop:document.documentElement.scrollTop||o.scrollTop;var l=document.querySelector(e.positionFixedSelector);"auto"===e.fixedSidebarOffset&&(e.fixedSidebarOffset=t.offsetTop),n>e.fixedSidebarOffset?-1===l.className.indexOf(e.positionFixedClass)&&(l.className+=r+e.positionFixedClass):l.className=l.className.split(r+e.positionFixedClass).join("")}();var u,f=s;if(i&&null!==t&&f.length>0){l.call(f,(function(t,n){return c(t)>a+e.headingsOffset+10?(u=f[0===n?n:n-1],!0):n===f.length-1?(u=f[f.length-1],!0):void 0}));var m=t.querySelectorAll("."+e.linkClass);n.call(m,(function(t){t.className=t.className.split(r+e.activeLinkClass).join("")}));var h=t.querySelectorAll("."+e.listItemClass);n.call(h,(function(t){t.className=t.className.split(r+e.activeListItemClass).join("")}));var p=t.querySelector("."+e.linkClass+".node-name--"+u.nodeName+'[href="'+e.basePath+"#"+u.id.replace(/([ #;&,.+*~':"!^$[\]()=>|/@])/g,"\\$1")+'"]');p&&-1===p.className.indexOf(e.activeLinkClass)&&(p.className+=r+e.activeLinkClass);var C=p&&p.parentNode;C&&-1===C.className.indexOf(e.activeListItemClass)&&(C.className+=r+e.activeListItemClass);var g=t.querySelectorAll("."+e.listClass+"."+e.collapsibleClass);n.call(g,(function(t){-1===t.className.indexOf(e.isCollapsedClass)&&(t.className+=r+e.isCollapsedClass)})),p&&p.nextSibling&&-1!==p.nextSibling.className.indexOf(e.isCollapsedClass)&&(p.nextSibling.className=p.nextSibling.className.split(r+e.isCollapsedClass).join("")),d(p&&p.parentNode.parentNode)}}}}},547:e=>{e.exports={tocSelector:".js-toc",contentSelector:".js-toc-content",headingSelector:"h1, h2, h3",ignoreSelector:".js-toc-ignore",hasInnerContainers:!1,linkClass:"toc-link",extraLinkClasses:"",activeLinkClass:"is-active-link",listClass:"toc-list",extraListClasses:"",isCollapsedClass:"is-collapsed",collapsibleClass:"is-collapsible",listItemClass:"toc-list-item",activeListItemClass:"is-active-li",collapseDepth:0,scrollSmooth:!0,scrollSmoothDuration:420,scrollSmoothOffset:0,scrollEndCallback:function(e){},headingsOffset:1,throttleTimeout:50,positionFixedSelector:null,positionFixedClass:"is-position-fixed",fixedSidebarOffset:"auto",includeHtml:!1,includeTitleTags:!1,onClick:function(e){},orderedList:!0,scrollContainer:null,skipRendering:!1,headingLabelCallback:!1,ignoreHiddenElements:!1,headingObjectCallback:null,basePath:"",disableTocScrollSync:!1}},971:function(e,t,n){var l,o,i;o=[],l=function(e){"use strict";var t,l,o,i=n(547),r={},s={},a=n(163),c=n(279),d=n(938),u=!!(e&&e.document&&e.document.querySelector&&e.addEventListener);if("undefined"!=typeof window||u){var f=Object.prototype.hasOwnProperty;return s.destroy=function(){var e=h(r);null!==e&&(r.skipRendering||e&&(e.innerHTML=""),r.scrollContainer&&document.querySelector(r.scrollContainer)?(document.querySelector(r.scrollContainer).removeEventListener("scroll",this._scrollListener,!1),document.querySelector(r.scrollContainer).removeEventListener("resize",this._scrollListener,!1),t&&document.querySelector(r.scrollContainer).removeEventListener("click",this._clickListener,!1)):(document.removeEventListener("scroll",this._scrollListener,!1),document.removeEventListener("resize",this._scrollListener,!1),t&&document.removeEventListener("click",this._clickListener,!1)))},s.init=function(e){if(u){r=function(){for(var e={},t=0;t{e.exports=function(e){var t=[].reduce;function n(e){return e[e.length-1]}function l(e){return+e.nodeName.toUpperCase().replace("H","")}function o(t){if(!(t instanceof window.HTMLElement))return t;if(e.ignoreHiddenElements&&(!t.offsetHeight||!t.offsetParent))return null;const n=t.getAttribute("data-heading-label")||(e.headingLabelCallback?String(e.headingLabelCallback(t.textContent)):t.textContent.trim());var o={id:t.id,children:[],nodeName:t.nodeName,headingLevel:l(t),textContent:n};return e.includeHtml&&(o.childNodes=t.childNodes),e.headingObjectCallback?e.headingObjectCallback(o,t):o}return{nestHeadingsArray:function(l){return t.call(l,(function(t,l){var i=o(l);return i&&function(t,l){for(var i=o(t),r=i.headingLevel,s=l,a=n(s),c=r-(a?a.headingLevel:0);c>0&&(!(a=n(s))||r!==a.headingLevel);)a&&void 0!==a.children&&(s=a.children),c--;r>=e.collapseDepth&&(i.isCollapsed=!0),s.push(i)}(i,t.nest),t}),{nest:[]})},selectHeadings:function(t,n){var l=n;e.ignoreSelector&&(l=n.split(",").map((function(t){return t.trim()+":not("+e.ignoreSelector+")"})));try{return t.querySelectorAll(l)}catch(e){return console.warn("Headers not found with selector: "+l),null}}}}},374:(e,t)=>{t.initSmoothScrolling=function(e){var t=e.duration,n=e.offset,l=location.hash?o(location.href):location.href;function o(e){return e.slice(0,e.lastIndexOf("#"))}document.body.addEventListener("click",(function(i){var r;"a"!==(r=i.target).tagName.toLowerCase()||!(r.hash.length>0||"#"===r.href.charAt(r.href.length-1))||o(r.href)!==l&&o(r.href)+"#"!==l||i.target.className.indexOf("no-smooth-scroll")>-1||"#"===i.target.href.charAt(i.target.href.length-2)&&"!"===i.target.href.charAt(i.target.href.length-1)||-1===i.target.className.indexOf(e.linkClass)||function(e,t){var n,l,o=window.pageYOffset,i={duration:t.duration,offset:t.offset||0,callback:t.callback,easing:t.easing||function(e,t,n,l){return(e/=l/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t}},r=document.querySelector('[id="'+decodeURI(e).split("#").join("")+'"]')||document.querySelector('[id="'+e.split("#").join("")+'"]'),s="string"==typeof e?i.offset+(e?r&&r.getBoundingClientRect().top||0:-(document.documentElement.scrollTop||document.body.scrollTop)):e,a="function"==typeof i.duration?i.duration(s):i.duration;function c(e){l=e-n,window.scrollTo(0,i.easing(l,o,s,a)),l{e.exports=function(e){var t=e.tocElement||document.querySelector(e.tocSelector);if(t&&t.scrollHeight>t.clientHeight){var n=t.querySelector("."+e.activeListItemClass);n&&(t.scrollTop=n.offsetTop)}}}},t={};function n(l){var o=t[l];if(void 0!==o)return o.exports;var i=t[l]={exports:{}};return e[l].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(971)})(); -------------------------------------------------------------------------------- /materials/project/intro_page/Project 3 _ CS 188 Spring 2024_files/auto-render.min.js.下载: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a [!PREREQUISITE] 10 | > 11 | > - [有限状态机](https://www.wikiwand.com/zh/articles/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA) 12 | 13 | ## note 14 | 15 | ### Agents 16 | 17 | - rational agent 18 | - an entity that has goals or preferences and tries to perform a series of actions that yield the best/optimal expected outcome given these goals. 19 | - reflex agent 20 | - one that doesn’t think about the consequences of its actions, but rather selects an action based solely on the current state of the world. 21 | - PEAS (Performance Measure, Environment, Actuators, Sensors) 22 | 23 | The design of an agent heavily depends on the type of environment the agents acts upon . We can characterize the types of environments in the following ways: 24 | 25 | - In **partially observable environments(部分可观测环境)**, the agent does not have full information about the state and thus the agent must have an internal estimate of the state of the world. This is in contrast to fully observable environments, where the agent has full information about their state. 26 | - **Stochastic environments(随机环境)** have uncertainty in the transition model, i.e. taking an action in a specific state may have multiple possible outcomes with different probabilities. This is in contrast to **deterministic environments(确定环境)**, where taking an action in a state has a single outcome that is guaranteed to happen. 27 | - In **multi-agent environments(多智能体环境)** the agent acts in the environments along with other agents. For this reason the agent might need to randomize its actions in order to avoid being “predictable" by other agents. 28 | - If the environment does not change as the agent acts on it, then this **environment is called static**. This is contrast to **dynamic environments** that change as the agent interacts with it. 29 | - If an environment has **known physics**, then the transition model (even if stochastic) is known to the agent and it can use that when planning a path. If the **physics are unknown** the agent will need to take actions deliberately to learn the unknown dynamics. 30 | 31 | > [!HELP] 32 | > 33 | > 在这里,`know physics` 应该是指已经被人类探索出来的规律;而 `unknown physics` 则是指尚且没有得知的规律。 34 | 35 | ## link 36 | 37 | - [cs188-sp24-note01](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note01.pdf) 38 | -------------------------------------------------------------------------------- /note/03-Informed_Search_Astar_and_Heuristics.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | > [!PREREQUISITE] 10 | > 11 | > - [范数](https://www.wikiwand.com/zh/articles/%E8%8C%83%E6%95%B0) 12 | > - [序关系](https://darstib.github.io/blog/note/cs70/note/18-Misc/#_5) 13 | 14 | ## note 15 | ### Informed Search 16 | 17 | _Uniform cost search_ is good because it’s both complete and optimal, but it can be **fairly slow** because it expands in every direction from the start state while searching for a goal. If we have some notion of the direction in which we should focus our search , we can significantly improve performance and "hone in" on a goal **much more quickly**. This is exactly the focus of _informed search_. 18 | 19 | ### Heuristics(启发式) 20 | 21 | Heuristics are the driving force that allow estimation of distance to goal states - they’re functions that take in a state as input and output a corresponding estimate. 22 | 23 | > The computation performed by such a function is **specific to the search problem** being solved. For reasons that we’ll see in A* search, below. 24 | 25 | we usually want heuristic functions to be a lower bound on this remaining distance to the goal , and so heuristics are typically solutions to **relaxed problems** (where some of the constraints of the original problem have been removed). 26 | 27 | Turning to our Pacman example, let’s consider the pathing problem described earlier. A common heuristic that’s used to solve this problem is the **Manhattan distance**, which for two points (x1, y1) and (x2, y2) is defined as: Manhattan(x1, y1, x2, y2) = |x1 −x2|+|y1 −y2| 28 | 29 | ![](attachments/03_State-Spaces-Uninformed-Search.png) 30 | 31 | > [!HELP] 32 | > 33 | > 也就是说,我们先将条件放宽松(在上图中就是先无视墙体)来“试探”着解决 relaxed problem,得到待解决问题的下界。 34 | 35 | This concept of preference is very powerful, and is utilized by the following two search algorithms that implement heuristic functions: **greedy search and A*.** 36 | 37 | ### Greedy Search 38 | 39 | - Description - Greedy search is a strategy for exploration that always selects the frontier node with the lowest heuristic value for expansion , which corresponds to the state it believes is nearest to a goal. 40 | - Frontier Representation - Greedy search operates identically to UCS, with a priority queue , while using **estimated forward cost** in the form of heuristic values. 41 | - Completeness and Optimality - Greedy search is not guaranteed to find a goal state if one exists, nor is it optimal, particularly in cases where a very bad heuristic function is selected. 42 | 43 | ![](attachments/03_State-Spaces-Uninformed-Search-1.png) 44 | 45 | ### A* Search 46 | 47 | - Description - A* search is a strategy for exploration that always selects the frontier node with the lowest estimated total cost for expansion , where total cost is the entire cost from the start node to the goal node. 48 | - Frontier Representation - Just like greedy search and UCS, A* search also uses a priority queue to represent its frontier. However, A* Search uses **estimated total cost** (= total backward cost + estimated forward cost) 49 | - Completeness and Optimality - A* search is both complete and optimal, given an appropriate heuristic (which we’ll cover in a minute). 50 | 51 | ### Admissibility and Consistency 52 | 53 | Now, let’s spend some time discussing what constitutes a good heuristic. 54 | 55 | > [!QUESTION] 56 | > 57 | > Why? 58 | > 59 | > Let’s first reformulate the methods used for determining priority queue ordering in UCS, greedy search, and A* with the following definitions: 60 | > 61 | > - g(n) - The function representing total backwards cost computed by UCS. 62 | > - h(n) - The heuristic value function, or estimated forward cost, used by greedy search. 63 | > - f(n) - The function representing estimated total cost, used by A* search. f(n) = g(n) +h(n). 64 | > 65 | > Indeed, it’s very easy to find heuristics that break these two coveted properties. As an example, consider the heuristic function **h(n) = 1−g(n).** Such a heuristic reduces A* search to BFS. 66 | 67 | > [!DEFINITION ] 68 | > 69 | > The condition required for optimality when using A* tree search is known as **admissibility**. The admissibility constraint states that the value estimated by an admissible heuristic is neither negative nor an overestimate, that is: $∀n, 0 ≤ h(n) ≤ h^∗ (n)$, ($h^∗(n)$ is the true optimal forward cost to reach a goal state from a given node n). 70 | 71 | > [!THEOREM] 72 | > 73 | > For a given search problem, if the admissibility constraint is satisfied by a heuristic function h, using A* tree search with h on that search problem will yield an optimal solution. 74 | > 75 | > ![](attachments/03_State-Spaces-Uninformed-Search-2.png) 76 | 77 | And in case of revisiting the same node multiple times, the natural solution is to simply keep track of which states you’ve already expanded, and never expand them again. Tree search with this added optimization is known as **graph search**, and the pseudocode for it is presented below: 78 | 79 | ```python title="pseudocode for graph search" 80 | function GRAPH-SEARCH(problem, frontier) return a solution or failure 81 | reached ← an empty set 82 | frontier ← INSERT(MAKE-NODE(INITIAL-STATE[problem]), frontier) 83 | while not IS-EMPTY(frontier) do 84 | node ← POP(frontier) 85 | if problem.IS-GOAL(node.STATE) then 86 | return node 87 | end 88 | if node.STATE is not in reached then 89 | add node.STATE in reached 90 | for each child-node in EXPAND(problem, node) do 91 | frontier ← INSERT(child-node, frontier) 92 | end 93 | end 94 | end 95 | return failure 96 | ``` 97 | 98 | > [!EXAMPLE] Bad example 99 | > 100 | > However, just consider the following simple state space graph and corresponding search tree, annotated with weights and heuristic values: 101 | > 102 | > ![](attachments/03_State-Spaces-Uninformed-Search-3.png) 103 | > 104 | > In the above example, it’s clear that the optimal route is to follow S → A →C → G, yielding a total path cost of 1+1+3 = 5. The only other path to the goal, S → B →C → G has a path cost of 1+2+3 = 6. However, because the heuristic value of node A is so much larger than the heuristic value of node B, node C is first expanded along the second, suboptimal path as a child of node B. It’s then placed into the "reached" set, and so A* graph search fails to reexpand it when it visits it as a child of A, so **it never finds the optimal solution.** Hence, to maintain optimality under A* graph search, we need an even stronger property than admissibility. 105 | 106 | > [!DEFINITION ] 107 | > 108 | > **consistency.** The central idea of consistency is that we enforce not only that a heuristic underestimates the total distance to a goal from any given node, but also the cost/weight of each edge in the graph. The cost of an edge as measured by the heuristic function is simply the difference in heuristic values for two connected nodes. Mathematically, the consistency constraint can be expressed as follows: $∀A,C\quad h(A)−h(C) ≤ cost(A,C)$ 109 | 110 | > [!THEOREM] 111 | > 112 | > For a given search problem, if the consistency constraint is satisfied by a heuristic function h, using A* graph search with h on that search problem will yield an optimal solution. 113 | > 114 | > ![](attachments/03_State-Spaces-Uninformed-Search-4.png) 115 | 116 | A couple of important highlights from the discussion above before we proceed: for heuristics that are **either admissible/consistent to be valid**, it must by definition be the case that **h(G) = 0** for any goal state G. 117 | 118 | Additionally, Additionally, consistency is not just a stronger constraint than admissibility, consistency implies admissibility. This stems simply from the fact that if no edge costs are overestimates (as guaranteed by consistency), the total estimated cost from any node to a goal will also fail to be an overestimate. This stems simply from the fact that if no edge costs are overestimates (as guaranteed by consistency), the total estimated cost from any node to a goal will also fail to be an overestimate. 119 | 120 | > [!HELP] 121 | > 122 | > 简单来说,**admissible** 要求 heuristic function 即 h(n) 低估到达目标的 cost,而 **consitency** 要求 h(n) 低估任意两个 state 之间的 cost 差。在 consitency 中 $h(A)−h(C) ≤ cost(A,C)$,那么对于任意一条 path,将有 $h(A) - h(G)= \sum (h(A)−h(C)) \leq \sum cost(A, C) = h^*(A)$,而 h(G)=0,故 admissible 条件也满足了。 123 | > 124 | > note3 给出了一个 admissible but inconsitency 的 h(n),如果没看懂可见原 [note3#p7](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note03.pdf) 125 | > 126 | > ![](attachments/03_State-Spaces-Uninformed-Search-5.png) 127 | 128 | ### Dominance(优势度) 129 | 130 | The standard metric for this(creating "good" heuristics, and how to tell if one heuristic is better than another) is that of **dominance**. If heuristic a is dominant over heuristic b, then the estimated goal distance for a is greater than the estimated goal distance for b for every node in the state space graph. Mathematically, $∀n : h_{a}(n) ≥ h_{b}(n)$ . 131 | 132 | > [!INFO] 133 | > 134 | > Additionally, the **trivial heuristic is defined as h(n) = 0**, and using it reduces A* search to UCS. All admissible heuristics dominate the trivial heuristic. The trivial heuristic is often incorporated at the base of a **semi-lattice** for a search problem, a dominance hierarchy of which it is located at the bottom. 135 | > 136 | >> [!HELP] 137 | >> 138 | >> 关键是理解这个 semi-lattice,用序关系来理解就很不错,下面的例子也很好地帮助我们理解。 139 | > 140 | > Below is an example of a semi-lattice that incorporates various heuristics ha,hb, and hc ranging from the trivial heuristic at the bottom to the exact goal distance at the top: 141 | > 142 | > ![](attachments/03_State-Spaces-Uninformed-Search-6.png) 143 | 144 | > 很显然,在 dominance 的度量标准下,所有满足我们先前要求的 heuristics 都“不大于” exact 即正确的情况,那么“越大”的 heuristics 越接近于 exact,自然是我们越想要的。 145 | 146 | ### Search: Summary 147 | 148 | Regarding the search problems, they can be solved using a variety of search techniques, including but not limited to the five we study in CS 188: 149 | 150 | - Breadth-first Search 151 | - Depth-first Search 152 | - Uniform Cost Search 153 | - Greedy Search 154 | - A* Search 155 | 156 | ## link 157 | 158 | - [cs188-sp24-note03](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note03.pdf) -------------------------------------------------------------------------------- /note/04-Local_Search.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Local Search 12 | 13 | > In the previous note, we wanted to find the goal state, along with the optimal path to get there. But in some problems, we only care about finding the goal state — reconstructing the path can be trivial. 14 | 15 | Local search algorithms allow us to find goal states without worrying about the path to get there. 16 | 17 | ![](attachments/04_Local-Search.png) 18 | 19 | The figure above shows the one dimensional plot of an objective function on the state space. For that function we wish to find the state that corresponds to the highest objective value. The basic idea of local search algorithms is that from each state they locally move towards states that have a higher objective value until a maximum (hopefully the global) is reached. 20 | 21 | We will be covering four such algorithms, **hill-climbing, simulated annealing, local beam search and genetic algorithms** 22 | 23 | ### Hill-Climbing Search 24 | 25 | > [!DEFINITION] 26 | > 27 | > The **hill-climbing search** algorithm (or _steepest-ascent_) moves from the current state towards the neighboring state that increases the objective value the most. 28 | 29 | ```python title="pseudocode for hill-climbing" 30 | function HILL-CLIMBING(problem) returns a state 31 | current <- make-node(problem.initial-state) 32 | loop do 33 | neighbor <- a highest-valued successor of current 34 | if neighbor.value ≤ current.value then 35 | return current.state 36 | current <- neighbor 37 | ``` 38 | 39 | The “greediness" of hill-climbing makes it vulnerable to being trapped in local maxima (see figure 4.1), as locally those points appear as global maxima to the algorithm, and plateaus (see figure 4.1). 40 | 41 | Variants of hill-climbing, like **stochastic hill-climbing** which selects an action randomly among the possible uphill moves, have been proposed. 42 | 43 | Another variant, **random sideways moves**, allows moves that don’t strictly increase the objective, allowing the algorithm to escape “shoulders". 44 | 45 | Hill-climbing is incomplete. **Random-restart hill-climbing** on the other hand, which conducts a number of hill-climbing searches from randomly chosen initial states, is trivially complete as at some point a randomly chosen initial state can converge to the global maximum. 46 | 47 | > [!SUMMARY] 48 | > 49 | > 简单来说,hill-climbing 始终向着目前上升倾向最大的方向;sotchastic hill-climbing 在上升的方向中随机选取一个方向;random sideways moves 则不再拘泥于上升;Random-restart hill-climbing 选择了随机选取多个起点执行 hill-climbing 算法,除去少数极端情况,总能够有一个起点能够到达期望的终点。 50 | 51 | ### Simulated Annealing Search 52 | 53 | **Simulated annealing** aims to combine random walk (randomly moves to nearby states) and hill-climbing to obtain a complete and efficient search algorithm. In simulated annealing we allow moves to states that can decrease the objective. 54 | 55 | The algorithm chooses a random move at each timestep. If the move leads to higher objective value, it is always accepted. If it leads to a smaller objective value, then the move is accepted with some probability . This probability is determined by the temperature parameter, which initially is high (more “bad" moves allowed) and gets decreased according to some “schedule". 56 | 57 | Theoretically, if temperature is decreased slowly enough, the simulated annealing algorithm will reach the global maximum with probability approaching 1. 58 | 59 | ```python title="pseudocode for simulated annealing" 60 | function SIMULATED-ANNEALING(problem, schedule) returns a state 61 | current ← problem.initial-state 62 | for t = 1 to ∞ do 63 | T ← schedule(t) 64 | if T = 0 then return current 65 | next ← a randomly selected successor of current 66 | ΔE ← next.value - current.value 67 | if ΔE > 0 then 68 | current ← next 69 | else 70 | current ← next only with probability e^(ΔE/T) 71 | ``` 72 | 73 | ### Local Beam Search 74 | 75 | Local beam search is another variant of the hill-climbing search algorithm. The key difference between the two is that local beam search keeps track of k states (threads) at each iteration. 76 | 77 | > [!TIP] 78 | > 79 | > Local Beam 相比于 Hill-Climbing 就是“不在一棵树上吊死”的思路,其同样可以有 stochastic beam search 等变体。 80 | 81 | ### Genetic Algorithms 82 | 83 | Genetic algorithms begin as beam search with k randomly initialized states called the population. States (called individuals) are represented as a string over a finite alphabet. 84 | 85 | > note04 讲的比较啰嗦,但是我觉得先大致看懂伪代码,再结合下面的例子即可。 86 | 87 | ```python title="pseudocode for genetic algorithm" 88 | function GENETIC-ALGORITHM(population, FITNESS-FN) returns an individual 89 | inputs: population, a set of individuals 90 | FITNESS-FN, a function that measures the fitness of an individual 91 | repeat # 反复“繁衍、进化”,直到子代适应性足够强,或者时间足够长 92 | new_population ← empty set # 初始化新生代为空集 93 | for i = 1 to SIZE(population) do # 使子代与父代数相同 94 | # 基于适应度选择 x/y,适应度越高,选中可能性越大 95 | x ← RANDOM-SELECTION(population, FITNESS-FN) 96 | y ← RANDOM-SELECTION(population, FITNESS-FN) 97 | child ← REPRODUCE(x, y) # “繁育”子代 98 | if (small random probability) then #小概率情况下 99 | child ← MUTATE(child) # 子代突变 100 | add child to new_population # 将子代纳入新生代 101 | population ← new_population # 换代 102 | until some individual is fit enough, or enough time has elapsed 103 | return the best individual in population, according to FITNESS-FN 104 | 105 | function REPRODUCE(x, y) returns an individual 106 | inputs: x, y, parent individuals # x/y 为父代 107 | n ← LENGTH(x); c ← random number from 1 to n # 随机取一个断点 c,交换片段 108 | return APPEND(SUBSTRING(x, 1, c), SUBSTRING(y, c + 1, n)) 109 | ``` 110 | 111 | > 上图中映照伪代码,向我们展示了遗传算法是如何“传宗接代”的;需要注意的是,在 (b) 中有两列数字,第一列表示其 FITNESS,第二列表示其选中为“父代”的概率,这个概率与 FITNESS 线性相关。 112 | 113 | > [!EXAMPLE] 8-Queens problem 114 | > 115 | > ![](attachments/04_Local-Search-1.png) 116 | 117 | ![](attachments/04_Local-Search-2.png) 118 | 119 | ![](attachments/04_Local-Search-3.png) 120 | 121 | ### Summary 122 | 123 | In this note, we discussed local search algorithms and their motivation. We can use these approaches when we don’t care about the path to some goal state, and want to satisfy constraints or optimize some objective. Local search approaches allow us to save space and find adequate solutions when working in large state spaces! 124 | 125 | ## link 126 | 127 | - [Leetcode => N-Queens](https://leetcode.com/problems/n-queens/) 128 | - [cs188-sp24-note04](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note02.pdf) -------------------------------------------------------------------------------- /note/06-Expectimax_Monte_Carlo_Tree_Search.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Expectimax 12 | 13 | Because minimax believes it is responding to an optimal opponent, it’s often overly pessimistic in situations where optimal responses to an agent’s actions are not guaranteed. Such situations include scenarios with inherent randomness such as card or dice games or unpredictable opponents that move randomly or suboptimally. This randomness can be represented through a generalization of minimax known as **expectimax**. 14 | 15 | Expectimax introduces **chance nodes** into the game tree, which instead of considering the worst case scenario as minimizer nodes do, considers the **average case**. More specifically, while minimizers simply compute the minimum utility over their children, chance nodes compute the expected utility or expected value. 16 | 17 | > [!NOTE] 18 | > 19 | > Our rule for determining values of nodes with **expectimax** is as follows:[^1] 20 | > 21 | > $$V(s) = 22 | \begin{cases} 23 | \max \limits_{s' \in \text{successors}(s)} V(s') & \text{if } s \text{ is an agent-controlled state} \\ 24 | \sum \limits_{s' \in \text{successors}(s)} p(s'|s)V(s') & \text{if } s \text{ is a chance state} \\ 25 | \text{\quad \quad known} & \text{if } s \text{ is a terminal state} 26 | \end{cases}$$ 27 | 28 | [^1]: In the below formulation, p(s′ |s) refers to either the probability that a given nondeterministic action results in moving from state s to s′ , or the probability that an opponent chooses an action that results in moving from state s to s′ , depending on the specifics of the game and the game tree under consideration. 29 | 30 | From this definition, we can see that minimax is simply a special case of expectimax . Minimizer nodes are simply chance nodes that assign a probability of 1 to their lowest-value child and probability 0 to all other children. 31 | 32 | The pseudocode for expectimax is quite similar to minimax, since we’re replacing minimizing nodes with chance nodes: 33 | 34 | ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search.png) 35 | 36 | > [!EXAMPLE] 37 | > 38 | > Consider the following expectimax tree, where chance nodes are represented by circular nodes instead of the upward/downward facing triangles for maximizers/minimizers. 39 | > 40 | > Assume for simplicity that all children of each chance node have a probability of occurrence of 1/3 . 41 | > 42 | > ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-1.png) 43 | 44 | ### Mixed Layer Types 45 | 46 | Though minimax and expectimax call for alternating maximizer/minimizer nodes and maximizer/chance nodes respectively, many games still don’t follow the exact pattern of alternation that these two algorithms mandate. 47 | 48 | Even in Pacman, after Pacman moves, there are usually multiple ghosts that take turns making moves, not a single ghost. We can account for this by very fluidly adding layers into our game trees as necessary. 49 | 50 | In the Pacman example for a game with four ghosts, this can be done by having a maximizer layer followed by 4 consecutive ghost/minimizer layers before the second Pacman/maximizer layer. 51 | 52 | In fact, doing so inherently gives rise to cooperation across all minimizers, as they alternatively take turns further minimizing the utility attainable by the maximizer(s). It’s even possible to combine chance node layers with both minimizers and maximizers. 53 | 54 | If we have a game of Pacman with two ghosts, where one ghost behaves randomly and the other behaves optimally, we could simulate this with alternating groups of maximizerchance-minimizer nodes. 55 | 56 | ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-2.png) 57 | 58 | ### General Games 59 | 60 | Not all games are zero-sum. Indeed, different agents may have have distinct tasks in a game that don’t directly involve strictly competing with one another. Such games can be set up with trees characterized by **multi-agent utilities**. 61 | 62 | Such utilities, rather than being a single value that alternating agents try to minimize or maximize, are represented as tuples with different values within the tuple corresponding to unique utilities for different agents. Each agent then attempts to maximize their own utility at each node they control, ignoring the utilities of other agents . 63 | 64 | > [!EXAMPLE] 65 | > 66 | > ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-3.png) 67 | > 68 | >> [!HELP] 69 | >> 70 | >> 每层 agent 对应 utility tuples 中相同颜色的数字;在经过该层时,它们只考虑与他们有关的数字;对于 maximizer,既是取其最大者。 71 | >> 72 | 73 | ### Monte Carlo Tree Search 74 | 75 | For applications with a large branching factor, like playing Go, minimax can no longer be used. For such applications we use the **Monte Carlo Tree Search (MCTS)** algorithm. 76 | 77 | MCTS is based on two ideas: 78 | 79 | - **Evaluation by rollouts**: From state s play many times using a policy (e.g. random) and count wins/losses. 80 | - **Selective search**: explore parts of the tree, without constraints on the horizon, that will improve decision at the root. 81 | 82 | In the Go example, from a given state, we play until termination according to a policy multiple times. We record **the fraction of wins**, which correlates well with the value of the state[^2]. 83 | 84 | > [!EXAMPLE] 85 | > 86 | > From the current state we have three different available actions (left, middle and right). We take each action 100 times and we record the percentage of wins for each one. 87 | > 88 | > ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-4.png) 89 | > 90 | > After the simulations, we are fairly confident that the right action is the best one. 91 | > 92 | > In this scenario, we allocated the same amount of simulations to each alternative action. However, it might become clear after a few simulations that a certain action does not return many wins and thus we might choose to allocate this computational effort in doing more simulations for the other actions. 93 | > 94 | > ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-5.png) 95 | > 96 | > An interesting case arises when some actions yield similar percentages of wins but one of them has used much fewer simulations to estimate that percentage, as shown in the next figure. 97 | > 98 | > ![](attachments/06_Expectimax-Monte-Carlo-Tree-Search-6.png) 99 | > 100 | > In this case the estimate of the action that used fewer simulations will have higher variance and hence we might want to allocate a few more simulations to that action to be more confident about the true percentage of wins. 101 | 102 | [^2]: the value of the state 越大,在该决策下的模拟胜利可能性(即下图中的 x/y)也就越大。 103 | 104 | > [!INFO] 105 | > 106 | > The **UCB algorithm** captures this trade-off between “promising" and “uncertain’ actions by using the following criterion at each node n:[^3] 107 | > 108 | > [^3]: where N(n) denotes the total number of rollouts from node n and U(n) the total number of wins for Player(Parent(n)). 109 | > 110 | > $$UCB1(n)=\frac{U(n)}{N(n)}+C\times\sqrt{\frac{\log N(PARENT(n))}{N(n)}}$$ 111 | > 112 | > The first term captures how promising the node is, while the second captures how uncertain we are about that node’s utility. The user-specified parameter C balances the weight we put in the two terms (“exploration" and “exploitation") and depends on the application and perhaps the stage of the task (in later stages when we have accumulated many trials, we would probably explore less and exploit more). 113 | > 114 | >> [!HELP] 115 | >> 116 | >> 我们暂时不必理解这个公式是如何计算以及为什么这么计算;明白这个算法帮助我们决定是要 "explore new moves (exploration) or use moves that have worked well in the past (exploitation)" 即可。 117 | >> 118 | >> > 在前期学习过程中,这些算法都是“函数”,我们只需要知道其“输入-功能-输出”就好了。 119 | 120 | The **MCTS UCT algorithm** uses the UCB criterion in tree search problems. More specifically, it repeats the following three steps multiple times: 121 | 122 | 1. The UCB criterion is used to move down the layers of a tree from the root node until an unexpanded leaf node is reached. 123 | 2. A new child is added to that leaf, and we run a rollout from that child to determine the number of wins from that node. 124 | 3. We update the numbers of wins from the child back up to the root node. 125 | 126 | Once the above three steps are sufficiently repeated, we choose the action that leads to the child with the highest N. 127 | 128 | > Note that because UCT inherently explores more promising children a higher number of times, as N → ∞, UCT approaches the behavior of a minimax agent. 129 | 130 | ### Summary 131 | 132 | In this note, we shifted gears from considering standard search problems where we simply attempt to find a path from our starting point to some goal, to considering adversarial search problems where we may have opponents that attempt to hinder us from reaching our goal. 133 | 134 | - **Minimax** - Used when our opponent(s) behaves optimally, and can be optimized using **α-β pruning**. Minimax provides more conservative actions than expectimax, and so tends to yield favorable results when the opponent is unknown as well. 135 | - **Expectimax** - Used when we facing a suboptimal opponent(s), using a **probability distribution** over the moves we believe they will make to compute the expectated value of states. 136 | - In most cases, it’s too computationally expensive to run the above algorithms all the way to the level of terminal nodes in the game tree under consideration, and so we introduced the notion of **evaluation functions** for early termination. 137 | - For problems with large branching factors we described the **MCTS and UCT algorithms**. Such algorithms are easily parallelizable, allowing for a large number of rollouts to take place using modern hardware. 138 | - We considered the problem of general games with multi-agent, where the rules are not necessarily zero-sum. 139 | 140 | ## link 141 | 142 | - [cs188-sp24-note06](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note06.pdf) 143 | -------------------------------------------------------------------------------- /note/07-Propositional_Logic_and_Planning.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | ### A Knowledge Based Agent 11 | 12 | Imagine a dangerous world filled with lava, the only respite a far away oasis. We would like our agent to be able to safely navigate from its current position to the oasis. 13 | 14 | > In reinforcement learning, we assume that the only guidance we can give is a reward function which will try to nudge the agent in the right direction, like a game of ’hot or cold’. 15 | > 16 | > However, we might consider an alternative strategy, instead. 17 | 18 | Let’s tell the agent some facts about the world and allow it to reason about what to do based on the information at hand. 19 | 20 | This alternative type of agent is known as a **knowledge based agent**. Such an agent maintains a knowledge base, which is a collection of logical sentences that encodes what we have told the agent and what it has observed . The agent is also able to perform logical inference to draw new conclusions. 21 | 22 | ### The Language of Logic 23 | 24 | > 在[cs70](https://darstib.github.io/blog/note/cs70/01-Propositional_Logic/) 中我们已经学习了解过了,这里简单回顾一下。 25 | 26 | 1. **Conjunction(合取)**: P∧Q (“P and Q”). True only when both P and Q are true. 27 | - conjunctive normal form or CNF[^1] 28 | 2. **Disjunction(析取)**: P∨Q (“P or Q”). True when at least one of P and Q is true. 29 | 3. **Negation(取反 / 否)**: ¬P (“not P”). True when P is false. 30 | 4. **Implication(蕴涵词)**: P ⇒ Q (“P implies Q”). This is the same as “If P, then Q.” 31 | 5. **two-way implication** or **biconditional** : p↔q. 32 | 6. **quantifiers(量词)**: The universal quantifier ∀ (“for all”) and the existential quantifier ∃ (“there exists”). 33 | 34 | [^1]: **CNF** is a conjunction of **clauses**, each of which a disjunction of literals. It has the general form (P1 ∨ ··· ∨Pi)∧ ··· ∧ (Pj ∨··· ∨Pn), i.e. it is an **‘AND’ of ‘OR’s**. 35 | 36 | ![|650](attachments/07-Propositional_Logic_and_Planning.png) 37 | 38 | ![](attachments/07-Propositional_Logic_and_Planning-1.png) 39 | 40 | ![](attachments/07-Propositional_Logic_and_Planning-2.png) 41 | ## link 42 | 43 | - [cs188-sp24-note07](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note07.pdf) -------------------------------------------------------------------------------- /note/09-First_Order_Logic.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | > [!PREREQUISITE] 10 | > 11 | > - [cs70-Propositional_Logic](https://darstib.github.io/blog/note/cs70/01-Propositional_Logic/) 12 | 13 | ## note 14 | ### First-Order Logic 15 | 16 | The second dialect of logic, **first-order logic (FOL)**, is more expressive than propositional logic and uses objects as its basic components. With first-order logic we can describe relationships between objects and apply functions to them. Each object is represented by a constant symbol, each relationship by a predicate symbol, and each function by a function symbol. 17 | 18 | > [!NOTE] 19 | > 20 | > - **Terms** in first-order logic are logical expressions that refer to an object. The simplest form of terms are constant symbols. However we don’t want to define distinct constant symbols for every possible object.[^1] 21 | > - **Atomic sentences** in first-order logic are descriptions of relationships between objects, and are true if the relationship holds.[^2] 22 | > - **Complex sentences** of first order logic are analogous to those in propositional logic and are atomic sentences connected by logical connectives. 23 | > - **Quantifiers**: The **universal quantifier ∀**, has the meaning “for all,” and the **existential quantifier ∃,**, has the meaning “there exists.” 24 | > - **Equality symbol**: signify that two symbols refer to the same object.[^3] 25 | 26 | [^1]: For example, if we want to refer to John’s left leg and Richard’s left leg, we can do so by using function symbols like **Leftleg(John)** and **Leftleg(Richard)**. Function symbols are just another way to name objects and are not actual functions. 27 | [^2]: An example of an atomic sentence is **Brother(John,Richard)** which is formed by a predicate symbol followed by a list of terms inside the parentheses. 28 | [^3]: For example, the incredible sentence (不懂的可以自行了解 Einstein)(Wife(Einstein)=FirstCousin(Einstein)∧Wife(Einstein)=SecondCousin(Einstein)) is true. 29 | 30 | > [!TIP] 31 | > 32 | > With propositional logic, we model our world as a set of symbols that are true or false. Under this assumption, we can represent a possible world as a vector, with a 1 or 0 for every symbol. 33 | > 34 | > - This binary view of the world is what is known as a **factored representation**. With first-order logic, our world consists of objects that relate to one another. 35 | > - This second object-oriented view of the world is known as a **structured representation**, is in many ways more expressive and is more closely aligned with the language we naturally use to speak about the world. 36 | 37 | The following table summarizes the first order logic syntax: 38 | 39 | ![|300](attachments/09-First_Order_Logic.png) 40 | 41 | ### First Order Logical Inference 42 | 43 | With first order logic we formulate inference exactly the same way. We’d like to find out if KB ⊨ q, that is if q is true in all models under which KB is true. One approach to finding a solution is propositionalization or translating the problem into propositional logic so that it can be solved with techniques we have already laid out. 44 | 45 | Each universal (existential) quantifier sentence can be converted to a conjunction (disjunction) of sentences with a clause for each possible object that could be substituted in for the variable. Then, we can use a SAT[^6] solver, like DPLL or Walk-SAT, (un)satisfiability of (KB∧¬q). 46 | 47 | [^6]: "SAT"是布尔可满足性问题(Boolen Satisfiability Problem)的缩写。 48 | 49 | One problem with this approach is there are an infinite number of substitutions that we could make , since there is no limit to how many times we can apply a function to a symbol. For example, we can nest the function Classmate(···Classmate(Austen)···) as many times as we’d like, until we reference the whole school. 50 | 51 | - A theorem proved by Jacques Herbrand (1930) tells us that if a sentence is entailed by a knowledge base that there is a proof involving just a finite subset of the propositionalized knowledge base . Therefore, we can try iterating through finite subsets, specifically searching via iterative deepening through nested function applications[^4]. 52 | - Another approach is to directly do inference with first-order logic, also known as lifted inference[^5].This rule is known as **Generalized Modus Ponens**. The forward chaining algorithm for first order logic repeatedly applies generalized Modus Ponens and substitution to infer q or show that it cannot be inferred. 53 | 54 | [^4]: i.e. first search through substitutions with constant symbols, then substitutions with Classmate(Austen), then substitutions with Classmate(Classmate(Austen)), ... 55 | [^5]: For example, we are given (∀x HasAbsolutePower(x)∧Person(x) ⇒Corrupt(x))∧Person(John)∧HasAbsolutePower(John) ("absolute power corrupts absolutely"). We can infer Corrupt(John) by substituting x for John. 56 | 57 | ### Logical Agents 58 | 59 | > Now that we understand how to formulate what we know and how to reason with it, we will talk about how to incorporate the power of deduction into our agents. 60 | 61 | One obvious ability an agent should have is the ability to figure out what state it is in, based on a history of observations and what it knows about the world (state-estimation). 62 | 63 | To incorporate its past observations into an estimate of where it currently is, an agent will need to have a notion of time and transitions between states . We call state attributes that vary with time fluents and write a fluent with an index for time , e.g. $Hot^t$ = the air is hot at time t. 64 | 65 | > [!KNOWLEDGE]- Successor-state axiom 66 | > 67 | > $F^{t+1} ⇔ ActionCausesF^t ∨(F^t ∧ ¬ActionCausesNotF^t )$, and in our world, the transition could be formulated as $Hot^{t+1} ⇔StepCloseToLava^t∨(Hot^t ∧¬StepAwayFromLava^t)$. 68 | 69 | Having written out the rules of the world in logic, we can now actually do planning by checking the satisfiability of some logic proposition! 70 | 71 | To do this, we construct a sentence that includes information about the initial state, the transitions (successor-state axioms), and the goal. (e.g. $InOasis^T∧Alive^T$ encodes the objective of surviving and ending up in the oasis by time T). 72 | 73 | If the rules of the world have been properly formulated, then finding a satisfying assignment to all the variables will allow us to extract a sequence of actions that will carry the agent to the goal. 74 | 75 | ## link 76 | 77 | - [cs188-sp24-note09](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note09.pdf) -------------------------------------------------------------------------------- /note/10-Intro_to_Probability.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | > [!PREREQUISITE] 10 | > 11 | > - [CS70-13-Introduction_of_Discrete_Probability](https://darstib.github.io/blog/note/cs70/13-Introduction_of_Discrete_Probability/) 12 | > - [CS70-14-Conditional_Probability](https://darstib.github.io/blog/note/cs70/14-Conditional_Probability/) 13 | 14 | ## note 15 | 16 | ### Probability Rundown 17 | 18 | - **Probability** 19 | 20 | A random variable represents an event whose outcome is unknown. 21 | A probability distribution is an assignment of weights to outcomes, which must satisfies the following conditions: 22 | (1) 0 $\leq P(\omega)\leq1$ (2) $\sum_\omega P(\omega)=1$ 23 | 24 | - **Conditional Probability** 25 | $P(A|B)=\sum_{\omega\in A\cap B}P(\omega|B=\frac{P(A\cap B)}{P(B)}=\frac{P(B|A)P(A)}{P(B)}$ 26 | 27 | - **Independent** 28 | - When A and B are mutually independent, P(A,B) = P(A)P(B), we write A⫫B. This is equivalent to B⫫A. 29 | - If A and B are conditionally independent given C, then P(A,B|C) = P(A|C)P(B|C), we write A ⫫ B|C. This is also equivalent to B⫫A|C. 30 | 31 | ### Inference By Enumeration (IBE) 32 | 33 | Given a joint PDF[^1], we can trivially compute any desired probability distribution P($Q_1...Q_m|e_1...e_n$) using a simple and intuitive procedure known as **inference by enumeration**, for which we define three types of variables we will be dealing with: 34 | 35 | 1. **Query variables** $Q_i$ , which are unknown and appear on the left side of the conditional bar(|) in the desired probability distribution. 36 | 2. **Evidence variables** $e_{i}$ , which are observed variables whose values are known and appear on the right side of the conditional bar(|) in the desired probability distribution. 37 | 3. **Hidden variables**, which are values present in the overall joint distribution but not in the desired distribution. 38 | 39 | [^1]: PDF指的是概率密度函数(Probability Density Function),用于描述连续随机变量在某个特定值附近的相对可能性。 40 | 41 | In **Inference By Enumeration**, we follow the following algorithm: 42 | 43 | 1. Collect all the rows consistent with the observed evidence variables. 44 | 2. Sum out (marginalize) all the hidden variables. 45 | 3. Normalize the table so that it is a probability distribution (i.e. values sum to 1) 46 | 47 | > [!EXAMPLE] 48 | > 49 | > ![](attachments/10-Intro_to_Probability.png) 50 | > 51 | > If we wanted to compute P(W | S=winter) using the above joint distribution, we’d select the four rows where S is winter, then sum out over T and normalize. 52 | > 53 | > Hence P(W=sun | S=winter) = 0.5 and P(W=rain | S=winter) = 0.5, and we learn that in winter there’s a 50% chance of sun and a 50% chance of rain. 54 | 55 | ## link 56 | 57 | - [cs188-sp24-note10](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note10.pdf) -------------------------------------------------------------------------------- /note/11-Bayesian_Network_Intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Bayesian Network Representation 12 | 13 | If IBE used, each of n variables we wish to represent can take on d possible values (it has a domain of size d), then our joint distribution table will have $d^n$ entries, exponential in the number of variables and quite impractical to store! 14 | 15 | Bayes nets avoid this issue by taking advantage of the idea of conditional probability. 16 | 17 | > [!DEFINITION] Bayes Net 18 | > 19 | > We formally define a Bayes Net as consisting of: 20 | > ![](attachments/11-Bayesian_Network_Intro.png) 21 | > 22 | > **example:** ![](attachments/11-Bayesian_Network_Intro-1.png) 23 | 24 | ### Structure of Bayes Nets 25 | 26 | Two rules for Bayes Net independences 27 | 28 | - Each node is conditionally independent of all its ancestor nodes (non-descendants) in the graph, given all of its parents. 29 | - Each node is conditionally independent of all other variables given its Markov blanket[^1]. 30 | 31 | [^1]: A variable’s Markov blanket consists of parents, children, children’s other parents. 32 | 33 | > [!HELP] 34 | > 35 | > 这两个规则即是利用了条件概率的局部性,帮助我们将判断一个事件所需要考虑的其他事件的数量大大减少。 36 | 37 | ## link 38 | 39 | - [cs188-sp24-note11](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note11.pdf) -------------------------------------------------------------------------------- /note/12-Variable_Elimination.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### variable elimination 12 | 13 | An alternate approach is to eliminate hidden variables one by one. To eliminate a variable X, we: 14 | 1. Join (multiply together) all factors[^1] involving X. 15 | 2. Sum out X. 16 | 17 | [^1]: A factor is defined simply as an unnormalized probability 18 | 19 | ```python title="variable elimination" 20 | def elimination_ask(X, e, bn): 21 | """ 22 | Returns a distribution over X given evidence e using variable elimination. 23 | 24 | Parameters: 25 | X: Query variable 26 | e: Observed values for evidence variables 27 | bn: Bayesian network specifying joint distribution P(X1, ..., Xn) 28 | 29 | Returns: 30 | Normalized distribution over X 31 | """ 32 | factors = [] # Initialize an empty list for factors 33 | for var in order(bn.VARS): # Iterate over variables in a specified order 34 | factors = make_factor(var, e, factors) # Create a factor for the current variable 35 | if var is a hidden variable: # Check if the variable is hidden 36 | factors = sum_out(var, factors) # Sum out the hidden variable from factors 37 | return normalize(pointwise_product(factors)) # Normalize the final distribution 38 | ``` 39 | 40 | > [!EXAMPLE] 41 | > 42 | > ```mermaid 43 | > graph LR 44 | > T ---> A 45 | > T ---> B 46 | > A ---> C 47 | > B ---> C 48 | > ``` 49 | > 50 | > ![](attachments/12-Variable_Elimination-1.png) 51 | 52 | ### IBE vs. VE 53 | 54 | ![](attachments/12-Variable_Elimination.png) 55 | 56 | ## link 57 | 58 | - [cs188-sp24-note12](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note12.pdf) -------------------------------------------------------------------------------- /note/13-Approximate_Inference.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | An alternate approach for probabilistic reasoning is to implicitly calculate the probabilities for our query by simply counting samples. This will not yield the exact solution, as in IBE or Variable Elimination, but this approximate inference is often good enough, especially when taking into account **massive savings in computation.** 10 | 11 | ## note 12 | 13 | ### Prior Sampling 14 | 15 | Given a Bayes Net model, we can easily write a simulator. For example, consider the CPTs given below for the simplified model with only two variables T and C. We call this simple approach **prior sampling**. 16 | 17 | ![](attachments/13_Approximate%20Inference.png) 18 | 19 | ```python title="prior sampling" 20 | import random 21 | 22 | def get_t(): 23 | if random.random() < 0.99: 24 | return True 25 | return False 26 | 27 | def get_c(t): 28 | if t and random.random() < 0.95: 29 | return True 30 | return False 31 | 32 | def get_sample(): 33 | t = get_t() 34 | c = get_c(t) 35 | return [t, c] 36 | ``` 37 | 38 | The downside of this approach is that it may require the generation of a very large number of samples in order to perform analysis of unlikely scenarios. If we wanted to compute P(C| −t), we’d have to throw away 99% of our samples. 39 | 40 | ### Rejection Sampling 41 | 42 | One way to mitigate the previously stated problem is to modify our procedure to early reject any sample inconsistent with our evidence. Namly if we want to generate P(C|-t), we don't generate c if T=+t so we can throw most of bad samples to faster generating. 43 | 44 | ### Likelihood weighting 45 | 46 | A more exotic approach is **likelihood weighting,** which ensures that we never generate a bad sample. In this approach, we manually set all variables equal to the evidence in our query. 47 | 48 | For example, if we wanted to compute P(C|−t), we’d simply declare that t is false. The problem here is that this may yield samples that are inconsistent with the correct distribution. If we simply force some variables to be equal to the evidence, then our samples occur with probability only equal to the products of the CPTs of the non-evidence variables. This means the joint PDF has no guarantee of being correct (though may be for some cases like our two variable Bayes Net). 49 | 50 | Likelihood weighting solves this issue by using a weight for each sample, which is the probability of the evidence variables given the sampled variables. 51 | 52 | ```python title="Likelihood weighting" 53 | def likelihood_weighting(X, e, bn, N): 54 | """ 55 | Calculate the posterior probability P(X | e) for the query variable X given evidence e. 56 | 57 | Parameters: 58 | X: Query variable 59 | e: Observed values for evidence variables 60 | bn: Bayesian network specifying the joint distribution P(X1, ..., Xn) 61 | N: Total number of samples to be generated 62 | 63 | Returns: 64 | Normalized weight vector W 65 | """ 66 | W = {value: 0 for value in X.values()} # Initialize weight vector 67 | 68 | for j in range(N): 69 | x, w = weighted_sample(bn, e) # Generate sample and weight 70 | W[x] += w # Update weight 71 | 72 | return normalize(W) # Normalize weights 73 | 74 | def weighted_sample(bn, e): 75 | """ 76 | Generate an event and a weight. 77 | 78 | Parameters: 79 | bn: Bayesian network 80 | e: Observed values for evidence variables 81 | 82 | Returns: 83 | x: Generated event 84 | w: Weight 85 | """ 86 | w = 1 # Initialize weight to 1 87 | x = {} # Initialize event 88 | 89 | for Xi in bn.variables: # Iterate over all variables 90 | if Xi in e: # If it is an evidence variable 91 | w *= P(Xi | parents(Xi)) # Update weight 92 | x[Xi] = e[Xi] # Set event value to the evidence value 93 | else: 94 | x[Xi] = random_sample(P(Xi | parents(Xi))) # Sample from the conditional distribution 95 | 96 | return x, w # Return event and weight 97 | 98 | def normalize(W): 99 | """ 100 | Normalize the weight vector. 101 | 102 | Parameters: 103 | W: Weight vector 104 | 105 | Returns: 106 | Normalized weight vector 107 | """ 108 | total_weight = sum(W.values()) 109 | return {key: value / total_weight for key, value in W.items()} # Normalize 110 | ``` 111 | 112 | For all three of our sampling methods (prior sampling, rejection sampling, and likelihod weighting), we can get increasing amounts of accuracy by generating additional samples. However, of the three, likelihood weighting is the most computationally efficient , for reasons beyond the scope of this course. 113 | 114 | ### Gibbs Sampling 115 | 116 | **Gibbs Sampling** is a fourth approach for sampling. In this approach, we first set all variables to some totally random value (not taking into account any CPTs). We then repeatedly pick one variable at a time, clear its value, and resample it given the values currently assigned to all other variables. 117 | 118 | ```python title="Gibbs sampling" 119 | def gibbs_ask(X, e, bn, N): 120 | """ 121 | Returns an estimate of P(X | e) using Gibbs sampling. 122 | 123 | Parameters: 124 | X: Query variable 125 | e: Observed values for evidence variables 126 | bn: Bayesian network 127 | N: Total number of samples to be generated 128 | 129 | Returns: 130 | Normalized count vector N 131 | """ 132 | N = {value: 0 for value in X.values()} # Initialize count vector for each value of X 133 | Z = get_non_evidence_variables(bn) # Get non-evidence variables in the Bayesian network 134 | x = initialize_with_random_values(e, Z) # Initialize x with random values for variables in Z 135 | 136 | for j in range(N): # Loop for N samples 137 | for Zi in Z: # Iterate over each non-evidence variable 138 | # Set the value of Zi in x by sampling from P(Zi | mb(Zi)) 139 | x[Zi] = sample_from_conditional_distribution(Zi, x) 140 | N[x] += 1 # Increment the count for the current value of X 141 | 142 | return normalize(N) # Normalize the count vector 143 | ``` 144 | 145 | ## link 146 | 147 | - [cs188-sp24-note13](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note13.pdf) 148 | - [A Gentle Introduction to Bayesian Deep Learning](https://towardsdatascience.com/a-gentle-introduction-to-bayesian-deep-learning-d298c7243fd6) -------------------------------------------------------------------------------- /note/14-Markov_Models.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | We’ll now cover a very intrinsically related structure called a Markov model, which for the purposes of this course can be thought of as analogous to a chain-like, infinite-length Bayes’ net. Now, we'll take a weather prediction example. 12 | 13 | ![](attachments/14-Markov_Models.png) 14 | 15 | $$ 16 | P(W_0,W_1,...,W_n)=P(W_0)P(W_1|W_0)P(W_2|W_1)...P(W_n|W_{n-1})=P(W_0)\prod_{i=0}^{n-1}P(W_{i+1}|W_i) 17 | $$ 18 | 19 | To track how our quantity under consideration (in this case, the weather) changes over time, we need to know both it’s **initial distribution** at time t = 0 and some sort of **transition model** that characterizes the probability of moving from one state to another between timesteps. 20 | 21 | ### mini-forward algothrim 22 | 23 | By properties of marginalization, we know that: 24 | 25 | $$ 26 | P(W_{i+1})=\sum_{w_i}P(w_i,W_{i+1}) \overset{\text{chain rule}}{\implies} P(W_{i+1})=\sum_{w_i}P(W_{i+1}|w_i)P(w_i) 27 | $$ 28 | 29 | To compute the distribution of the weather at timestep i+1, we look at the probability distribution at timestep i given by $P(W_i)$ and "advance" this model a timestep with our transition model $P(W_{i+1}|W_i)$. 30 | 31 | ### Stationary Distribution 32 | 33 | A new question: does the probability of being in a state at a given timestep ever converge? 34 | 35 | To solve this problem, we must compute the stationary distribution of the weather. As the name suggests, the stationary distribution is one that remains the same after the passage of time, i.e. $P(W_{i+1})=P(W_{i})$. 36 | 37 | So we have $P(W_{t})=\sum_{w_{t}}P(W_{t+1}|w_{t})P(w_{t})$, in our weather forecast, that is: 38 | 39 | $$ 40 | \begin{cases} 41 | P(W_t=sun)=P(W_{t+1}=sun|W_t=sun)P(W_t=sun)+P(W_{t+1}=sun|W_t=rain)P(W_t=rain) \\ 42 | P(W_t=rain)=P(W_{t+1}=rain|W_t=sun)P(W_t=sun)+P(W_{t+1}=rain|W_t=rain)P(W_t=rain) 43 | \end{cases} 44 | $$ 45 | 46 | Since we know $P(w_{t+1}|w_{t})$ (namly the transition model), then we can solve binary first order equations and get $P(W_{t})$. 47 | 48 | As expected, $P(W_{\infty+1}) = P(W_{\infty})$. In general, if $W_{t}$ had a domain of size k, the equivalence $P(W_{t})=\sum_{w_{t}}P(W_{t+1}|w_{t})P(w_{t})$ yields a system of k equations, which we can use to solve for the stationary distribution. 49 | 50 | ## link 51 | 52 | - [cs188-sp24-note14](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note14.pdf) -------------------------------------------------------------------------------- /note/15-Hidden_Marko_Models.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | We may collect new meteorological evidence that might affect our belief of the probability distribution in the process of predicting what the weather will be like on a given day from the initial state. 12 | 13 | **Hidden Markov Model (HMM)** allows us to observe some evidence at each timestep, which can potentially affect the belief distribution at each of the states. Compared to the Markov model, the Hidden Markov model requires not only the initial distribution, the transition model, but also the **sensor model.** 14 | 15 | ![](attachments/15-Hidden_Marko_Models.png) 16 | 17 | To make distinction, we’ll call each $W_i$ a state variable and each weather forecast $F_i$ an evidence variable. 18 | 19 | The model implies similar conditional indepencence relationships as standard Markov models, with an additional set of relationships for the evidence variables[^1]: 20 | 21 | [^1]: 表达式 A⫫B∣C 表示在给定条件 C 的情况下,变量 A 和 B 是相互独立的 22 | 23 | $$ 24 | \begin{aligned}&F_{1}\quad\perp\!\!\!\perp\quad W_{0}|W_{1}\\& 25 | \forall i\quad=\quad2,\ldots,n;\quad W_{i}\perp\!\!\!\perp v\{W_{0},\ldots,W_{i-2},F_{1},\ldots,F_{i-1}\}|W_{i-1}\\& 26 | \forall i\quad=\quad2,\ldots,n;\quad F_{i}\perp\!\!\!\perp\{W_{0},\ldots,W_{i-1},F_{1},\ldots,F_{i-1}\}|W_{i}\end{aligned} 27 | $$ 28 | 29 | Just like Markov models, Hidden Markov Models make the assumption that the transition model $P(W_{i+1}|W_i)$ is stationary. Hidden Markov Models make the additional simplifying assumption that the sensor model $P(F_i|W_i)$ is stationary as well. 30 | 31 | ### notation 32 | 33 | - $e_{i}$ : evidence observed at timestep i 34 | - $e_{1:t} := e_{1}, e_{2} \dots e_{t}$ 35 | - $B(W_{i})=P(W_{i}|f_{1},\dots f_{t})=P(W_{i}|f_{1:t})$ : the belief distribution at time i with all evidence $F1,\dots,Fi$ observed up to date 36 | - $B'(W_{i})=P(W_{i}|f_{1},\dots f_{t-1})=P(W_{i}|f_{1:(t-1)})$ : the belief distribution at time i with evidence $f_{1},\dots, f_{i−1}$ observed. 37 | 38 | ### Forward Algothrim 39 | 40 | Noting that $B^{\prime}(W_{i+1})=P(W_{i+1}|f_1,\ldots,f_i)=\sum_{w_i}P(W_{i+1}|w_i,f_1,\ldots,f_i)P(w_i|f_1,\ldots,f_i)$ and $W_{i+1} \perp\!\!\!\perp f_{1: i} | W_{i}$, we can easily get: $\boxed{B^{\prime}(W_{i+1})=\sum_{{w_{i}}}P(W_{i+1}|w_{i})B(w_{i})}$. 41 | 42 | After some derivation (see original note), we get: $B(W_{i+1})\propto P(f_{i+1}|W_{i+1})B^{\prime}(W_{i+1})$ , so we get $B(W_{i+1}) \sim B(W_{i})$. 43 | 44 | > 根据原笔记,我认为应当是:$\boxed{B(W_{i+1}) = \frac{P(f_{i+1}|W_{i+1})\sum_{{w_{i}}}P(W_{i+1}|w_{i})B(w_{i})}{P(f_{i+1}|f_{1:i})}}$ ,这就是 hidden marko model's forward algorithm. 45 | 46 | ### Viterbi Algorithm 47 | 48 | The problem can also be solved for using **dynamic programming** with the **Viterbi algorithm**. To visualize the algorithm, consider the following state trellis, a graph of states and transitions over time: 49 | 50 | ![](attachments/15-Hidden_Marko_Models-1.png) 51 | 52 | In this HMM with two possible hidden states, sun or rain, we would like to compute **the highest probability path** (assignment of a state for every timestep) from $X_1$ to $X_N$. 53 | 54 | The weights on an edge from $X_{t−1}$ to $X_t$ is equal to $P(X_t | X_{t−1})P(E_t | X_t)$[^2], and the probability of a path is computed by taking the product of its edge weights. 55 | 56 | [^2]: The first term in the weight formula represents how likely a particular transition is and the second term represents how well the observed evidence fits the resulting state. 57 | 58 | If $P(X_{1}|X_{0}) := P(X_{1})$, we have $P(X_{1:N}, e_{1:N}) = \prod_{t=1}^NP(X_t|X_{t-1})P(e_t|X_t)$. In the Viberbi Algothrim, we want to compute $\arg\max_{x_1,..,x_N}P(x_{1:N},e_{1:N})$ to find the maximum likelihood estimate of the sequence of hidden states. 59 | 60 | The algorithm consists of **two passes:** 61 | - the first runs forward in time and computes the probability of the best path to each (state, time) tuple given the evidence observed so far. 62 | - The second pass runs backwards in time: first it finds the terminal state that lies on the path with the highest probability, and then traverses backward through time along the path that leads into this state (which must be the best path). 63 | 64 | Define $m_{t}[x_{t}] =\max_{x_{1}:t-1}P(x_{1:t}, e_{1: t})$, so we get: 65 | 66 | $$ 67 | \begin{aligned}m_t[x_t]&=\max_{x_{1:t-1}}P(e_t|x_t)P(x_t|x_{t-1})P(x_{1:t-1},e_{1:t-1})\\&=P(e_t|x_t)\max_{x_{t-1}}P(x_t|x_{t-1})\max_{x_{1:t-2}}P(x_{1:t-1},e_{1:t-1})\\&=P(e_t|x_t)\max_{x_{t-1}}P(x_t|x_{t-1})m_{t-1}[x_{t-1}].\end{aligned} 68 | $$ 69 | 70 | Using $a_t[x_t]=P(e_t|x_t)\arg\max_{x_{t-1}}P(x_t|x_{t-1})m_{t-1}[x_{t-1}]=\arg\max_{x_{t-1}}P(x_t|x_{t-1})m_{t-1}[x_{t-1}]$to keep track of the last transition, the pseudo-code is as follows: 71 | 72 | ![](attachments/15-Hidden_Marko_Models-2.png) 73 | 74 | ## link 75 | 76 | - [cs188-sp24-note15](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note15.pdf) -------------------------------------------------------------------------------- /note/16-PF-DN-VPI.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Particle Filtering 12 | 13 | #### Introduction 14 | 15 | Hidden Markov Models have the same drawback as bayes net - the time it takes to run exact inference with the forward algorithm scales with the number of values in the domains of the random variables. 16 | 17 | The Hidden Markov Model analog to Bayes’ net sampling is called **particle filtering**, and involves simulating the motion of a set of particles through a state graph to approximate the probability (belief) distribution of the random variable in question. Our belief that a particle is in any given state at any given timestep is dependent entirely on the number of particles in that state at that timestep in our simulation. To recover a belief distribution from a particle list, all you need to do is count the number of particles and normalize them. 18 | 19 | This solves the same question as the Forward Algorithm: it gives us an approximation of $P(X_{N}|e_{1:N})$ . 20 | 21 | #### Simulation 22 | 23 | - Particle Initialization 24 | - Time Elapse Update - Update the value of each particle according to the transition model. 25 | - Observation Update - During the observation update for particle filtering, we use the sensor model $P(F_{i}|T_{i})$ to weight each particle according to the probability dictated by the observed evidence and the particle’s state. 26 | - ![](attachments/15-Particle_Filtering.png) 27 | 28 | #### Utilities 29 | 30 | Rational agents must follow the principle of maximum utility - they must always select the action that maximizes their expected utility. However, obeying this principle only benefits agents that have rational preferences. 31 | 32 | > [!DEFINITION] The mathematical language of preferences: 33 | > 34 | >- If an agent prefers receiving a prize A to receiving a prize B, this is written $A \succ B$ . 35 | >- If an agent is indifferent between receiving A or B, this is written as $A \sim B$ 36 | >- A lottery is a situation with different prizes resulting with different probabilities. To denote lottery where A is received with probability p and B is received with probability (1− p), we write $L = [p, A; (1-p), B]$. 37 | 38 | In order for a set of preferences to be rational, they must follow the five **Axioms of Rationality**: 39 | - Orderability: $(A\succ B)\lor(B\succ A)\lor(A\sim B)$ 40 | - Transitivity: $(A\succ B)\land(B\succ C)\Rightarrow(A\succ C)$ 41 | - Continuity: $A\succ B\succ C\Rightarrow\exists p, \left[p,A;(1-p),C\right]\sim B$ 42 | - Substitutability: $A\sim B\Rightarrow[p,A;(1-p),C]\sim[p,B;(1-p),C]$ 43 | - Monotonicity: $A\succ B\Rightarrow(p\geq q\Leftrightarrow[p,A;\mathrm{~(1-p),B]\succeq[q,A;~(1-q),B]}$ 44 | 45 | If all five axioms are satisfied by an agent, there exists a real-valued utility function U that: $\begin{array}{rcl}U(A)\geq U(B)&\Leftrightarrow&A\succeq B&\text{(1)}\\U([p_1,S_1;\ldots;p_n,S_n])&=&\sum_ip_iU(S_i)&(2)\end{array}$ , examples omitted here. 46 | 47 | ### Decision Network 48 | 49 | Now we’ll discuss a combination of both Bayes’ nets and expectimax known as a **decision network** that we can use to model the effect of various actions on utilities based on an overarching graphical probabilistic model. 50 | 51 | In decision network: 52 | - Chance node (ovals) 53 | - Chance nodes in a decision network behave identically to Bayes’ nets. 54 | - Action node (rectangles) 55 | - Action nodes are nodes that we have complete control over. 56 | - Utility node (diamonds) 57 | - Utility nodes are children of some combination of action and chance nodes. 58 | 59 | > [!EXAMPLE] 60 | > 61 | > Let's say we're deciding whether or not to bring an umbrella 62 | > ![](attachments/15-PF-DN-OT-VPI.png) 63 | 64 | Our goal with decision networks is again to select the action which yields the **maximum expected utility**(MEU), and the expected utility of taking an action a given evidence e and n chance nodes is computed with 65 | 66 | $$EU(a|e)=\sum_{x_1,...,x_n}P(x_1,...,x_n|e)U(a,x_1,...,x_n)$$ 67 | 68 | ![](attachments/15-PF-DN-VPI.png) 69 | 70 | ### The Value of Perfect Information (VPI) 71 | 72 | We’ve generally always assumed that our agent has all the information it needs for a particular problem and/or has no way to acquire new information. In practice, this is hardly the case, and one of the most important parts of decision making is knowing whether or not it’s worth gathering more evidence to help decide which action to take. 73 | 74 | In this section, we’ll talk about a very important concept - **the value of perfect information (VPI)** - which mathematically quantifies the amount an agent’s maximum expected utility is expected to increase if it observes some new evidence. 75 | 76 | Mathematically, we represent it as: 77 | 78 | $$ 79 | \begin{cases} 80 | MEU(e)=\max_a\sum_sP(s|e)U(s,a) \\ 81 | MEU(e,e^{\prime})=\max_a\sum_sP(s|e,e^{\prime})U(s,a) 82 | \end{cases} \implies VPI(e^{\prime}|e)=MEU(e,e^{\prime})-MEU(e) 83 | $$ 84 | 85 | However, note that we don’t know what new evidence we’ll get, we use E' to represent e', so $MEU(e,E^{\prime})=\sum_{e^{\prime}}P(e^{\prime}|e)MEU(e,e^{\prime})$ and $\boxed{VPI(E^{\prime}|e)=MEU(e,E^{\prime})-MEU(e)}$. 86 | 87 | Properties of VPI: 88 | - Nonnegativity - $\forall E^{\prime},e\text{ VPI}(E^{\prime}|e)\geq0$ 89 | - Nonadditivity - $VPI(E_j,E_k|e)\neq VPI(E_j|e)+VPI(E_k|e)$ in general. 90 | - Order-independence - $VPI(E_j,E_k|e)=VPI(E_j|e)+VPI(E_k|e_j)=VPI(E_k|e)+VPI(E_j|e,E_k)$ 91 | 92 | ## link 93 | 94 | - [cs188-sp24-note16](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note16.pdf) -------------------------------------------------------------------------------- /note/17-Markov_Decision_Processes.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | A Markov Decision Process is defined by several properties: 12 | 13 | - a set of states S and a start state, possibly one or more terminal states. 14 | - a set of actions A. 15 | - a transiton function $T(s, a, s')$ 16 | - represents the **probability** tha an agent taking an action $a \in A$ from state $s \in S$ end up in a state $s' \in S$. 17 | - a reward function $R(s, a, s')$ 18 | - the agent’s objective is naturally to acquire the maximum reward possible before arriving at some terminal state. 19 | - a utility function $U([s_{0}, a_{0}, s_{1}, a_{1}, s_{2}, \dots])$ for $s_0\xrightarrow{a_0}s_1\xrightarrow{a_1}s_2\xrightarrow{a_2}s_3\xrightarrow{a_3}...$ 20 | - possibly a discount factor $\gamma$ (set 1 if not mentioned) 21 | - $U([s_0,a_0,s_1,a_1,s_2,...])=R(s_0,a_0,s_1)+\gamma R(s_1,a_1,s_2)+\gamma^2R(s_2,a_2,s_3)+...$ 22 | - **markovianess** 23 | - if we know the present state, knowing the past doesn’t give us any more information about the future 24 | - $P(S_{t+1}=s_{t+1}|S_t=s_t,A_t=a_t,...,S_0=s_0) = P(S_{t+1}=s_{t+1}|S_{t}=s_{t}, A_{t}=a_{t})$ 25 | - $T(s,a,s')=P(s'|s,a)$ 26 | 27 | Consider the motivating example of a racecar: 28 | 29 | ![](attachments/17-Markov_Decision_Processes.png) 30 | 31 | - S = {cool, warm, overheated} 32 | - A = {slow, fast} 33 | - ![](attachments/17-Markov_Decision_Processes-1.png) 34 | 35 | ![](attachments/17-Markov_Decision_Processes-2.png) 36 | 37 | ### Finite Horizons and Discount factors 38 | 39 | We haven't placed any time constraints on the number of timesteps for which a race car can take actions and collect rewards. 40 | 41 | - **Finite horizons** (n) 42 | - it essentially defines a "lifetime" for agents, which gives them some set number of timesteps n to accrue as much reward as they can before being automatically terminated. 43 | - **Discount factors** ($\gamma$) 44 | - if $\gamma < 1$, the discounted utility won't increse indefinitely, since: 45 | - $\begin{aligned}U([s_0,s_1,s_2,...])&=\quad R(s_0,a_0,s_1)+\gamma R(s_1,a_1,s_2)+\gamma^2R(s_2,a_2,s_3)+...\\&=\quad\sum_{t=0}^\infty\gamma^tR(s_t,a_t,s_{t+1})\leq\sum_{t=0}^\infty\gamma^tR_{max}=\boxed{\frac{R_{max}}{1-\gamma}}\end{aligned}$ 46 | 47 | ### Solving MDP with the Bellman Equation 48 | 49 | Solving a MDP means finding an optimal policy $\pi^{*}: S \rightarrow A$ , a function mapping each state $s \in S$ to an action $a \in A$. 50 | 51 | Marko $U^*(s)=\max_aQ^*(s,a)$ v decision processes, like state-space graphs, can be unraveled into search trees. Uncertainty is modeled in these search trees with **Q-states**, also known as **action states**, essentially identical to expectimax chance nodes. 52 | 53 | Let's efine the equation for the optimal value of a Q-state (a.k.a. optimal Q-value): 54 | 55 | $Q^*(s,a)=\sum_{s^{\prime}}T(s,a,s^{\prime})[R(s,a,s^{\prime})+\boldsymbol{\gamma}U^*(s^{\prime})]$ 56 | 57 | where $U^*(s)=\max_aQ^*(s,a)$ (namly the bellman equation - the optimal value of every state $s \in S$). 58 | 59 | ## link 60 | 61 | - [cs188-sp24-note17](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note17.pdf) -------------------------------------------------------------------------------- /note/18-Iteration.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Value Iteration 12 | 13 | Considering finite horizons, The time-limited value for a state s with a time-limit of k timesteps is denoted $U_k(s)$, 14 | 15 | Value iteration is a dynamic programming algorithm that uses an iteratively longer time limit to compute time-limited values until convergence[^1] , operating as follows: 16 | 17 | [^1]: convergence means that $\forall s \in S, U_{k+1}(s) = U_{k}(s)$. 18 | 19 | 1. $\forall s \in S$, initialze $U_{0}(s)=0$, since no actions can be taken to acquire rewards. 20 | 2. repear the following update rule until convergence (B is called the Bellman operator): 21 | 22 | $$ 23 | \forall s\in S,U_{k+1}(s)\leftarrow\max_{a}\sum_{s^{\prime}}T(s,a,s^{\prime})[R(s,a,s^{\prime})+\gamma U_{k}(s^{\prime})] ~~ (or \ \ U_{k+1} \leftarrow BU_{k}) 24 | $$ 25 | 26 | When convergence is reached, the Bellman equation will hold for every state: $\forall s \in S, U_{k+1}(s)=U_{k}(s) = U^*(s)$. 27 | 28 | ### Q-value Iteration 29 | 30 | Q-value iteration is a dynamic programming algorithm that computes time-limited Q-values. It is described in the following equation: $Q_{k+1}(s,a)\leftarrow\sum_{s^{\prime}}T(s,a,s^{\prime})[R(s,a,s^{\prime})+\gamma\max_{a^{\prime}}Q_k(s^{\prime},a^{\prime})]$. 31 | 32 | ### Policy Iteration 33 | 34 | #### policy extraction 35 | 36 | $$\forall s\in S,\:\boldsymbol{\pi}^{*}(s)=\underset{a}{\operatorname*{\operatorname*{\operatorname*{argmax}}}}Q^{*}(s,a)=\underset{a}{\operatorname*{\operatorname*{\arg\max}}}\sum_{{s^{\prime}}}T(s,a,s^{\prime})[R(s,a,s^{\prime})+\boldsymbol{\gamma}U^{*}(s^{\prime})]$$ 37 | 38 | #### policy evaluation 39 | 40 | For a policy π, policy evaluation means computing $U^π(s)$ for all states s, where $U^π(s)$ is expected utility of starting in state s when following π : 41 | 42 | $$U^{\boldsymbol{\pi}}(s)=\sum_{s^{\prime}}T(s,\boldsymbol{\pi}(s),s^{\prime})[R(s,\boldsymbol{\pi}(s),s^{\prime})+\boldsymbol{\gamma}U^{\boldsymbol{\pi}}(s^{\prime})]$$ 43 | #### policy improvement 44 | 45 | Once we’ve evaluated the current policy, use policy improvement to generate a better policy. 46 | 47 | Define the policy at iteration i of policy iteration as $\pi_{i}$ , we have 48 | 49 | $$U_{k+1}^{{\boldsymbol{\pi}_{i}}}(s)\leftarrow\sum_{{s^{\prime}}}T(s,\boldsymbol{\pi}_{i}(s),s^{\prime})[R(s,\boldsymbol{\pi}_{i}(s),s^{\prime})+\boldsymbol{\gamma}U_{k}^{{\boldsymbol{\pi}_{i}}}(s^{\prime})]$$ 50 | 51 | finally improve policy with: 52 | 53 | $$\boldsymbol{\pi}_{i+1}(s)=\underset a{\operatorname*{argmax}}\sum_{s^{\prime}}T(s,a,s^{\prime})[R(s,a,s^{\prime})+\boldsymbol{\gamma}U^{\pi_i}(s^{\prime})]$$ 54 | 55 | ### summary 56 | 57 | ![](attachments/18-Iteration.png) 58 | 59 | ## link 60 | 61 | - [cs188-sp24-note18](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note18.pdf) -------------------------------------------------------------------------------- /note/19-Navie_Bayes.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | > [!ATTENTION] 12 | > 13 | > 本人有些许机器学习基础,此处笔记对于从未接触过的人来说可能些许简略,建议查看原笔记;粗略但完整的讲解推荐 [Hung-yi Lee (李宏毅)](https://speech.ee.ntu.edu.tw/~hylee/index.html) 在國立臺灣大學开设的 [Introduction to Generative AI 2024 Spring](https://speech.ee.ntu.edu.tw/~hylee/genai/2024-spring.php)。 14 | 15 | Until now, we’ve assumed that the probabilistic models we’ve worked with can be taken 16 | for granted, and the methods by which the underlying probability tables we worked with were generated have been abstracted away[^1]. We’ll begin to break down this abstraction barrier as we delve into our discussion of **machine learning**. 17 | 18 | [^1]: 这个长难句也是难绷的;参考翻译:直到现在,我们一直假设我们所使用的概率模型是理所当然的,而生成我们所用的概率表的那些方法也已经被抽象掉了。 19 | 20 | Two primary subgroups of machine learning algorithms are **supervised learning algorithms** and **unsupervised learning algorithms**. We discuss the former now. 21 | 22 | Once you have a dataset that you’re ready to learn with, the machine learning process usually involves splitting your dataset into three distinct subsets. 23 | - The first, **training data**, is used to actually generate a model mapping inputs to outputs. 24 | - Then, **validation data** (also known as hold-out or development data) is used to measure your model’s performance by making predictions on inputs and generating an accuracy score, 25 | - If your model doesn’t perform as well as you’d like it to, it’s always okay to go back and train again, either by adjusting special model-specific values called hyperparameters or by using a different learning algorithm altogether until you’re satisfied with your results. 26 | - Finally, use your model to make predictions on the third and final subset of your data, the **test set**. The test set is the portion of your data that’s never seen by your agent until the very end of development, and is the equivalent of a "final exam" to gauge performance on real-world data. 27 | 28 | ![](attachments/19-Machine_Learning.png) 29 | 30 | ### Naive Bayes (classification problem) 31 | 32 | Let’s consider the common problem of building an email spam filter which sorts messages into spam (unwanted email) or ham (wanted email). Such a problem is called a classification problem 33 | 34 | To train a model to classify emails as spam or ham, we need some training data consisting of preclassified emails that we can learn from. However, emails are simply strings of text, and in order to learn anything useful, we need to extract certain attributes from each of them known as **features**. Features can be anything ranging from specific word counts to text patterns (e.g. whether words are in all caps or not) to pretty much any other attribute of the data that you can imagine. In this note, f(x) refers to a feature function applied to all inputs x before putting them in the model. 35 | 36 | Now let’s say you have a dictionary of n words, and from each email you extract a feature vector $F\in\mathbb{R}^n$ where the $i^{th}$ entry in F is a random variable $F_i$ which can take on a value of either a 0 or a 1 depending on whether the $i^{th}$ word in your dictionary appears in the email under consideration. Then we just compute the probability: 37 | 38 | $$P(Y=spam|F_1=f_1,\ldots,F_n=f_n) \quad and\quad P(Y=ham|F_1=f_1,\ldots,F_n=f_n)$$ 39 | 40 | > 即,我们用布尔列表代表某个词是否出现在邮件中,以此作为特征向量;但是记住这一计算是 $O(2^n)$ 的,我们使用 bayes' net 来进行简化,时间复杂度降低至 $O(n)$. 41 | 42 | This is solved by modeling the joint probability table with a Bayes’ net, making the critical simplifying assumption that each feature Fi is independent of all other features given the class label. This is a very strong modeling assumption (and the reason that **Naive Bayes** is called naive), but it simplifies inference and usually works well in practice. Then we get: 43 | 44 | $$ 45 | \begin{aligned}prediction(F) = prediction(f_1,\cdots f_n)&=\underset{y}{\operatorname*{argmax~}}P(Y=y|F_1=f_1,\ldots F_N=f_n)\\&=\underset{y}{\operatorname*{argmax~}}P(Y=y,F_1=f_1,\ldots F_N=f_n)\\&=\underset{y}{\operatorname*{argmax~}}P(Y=y)\prod_{i=1}^{n}P(F_i=f_i|Y=y)\end{aligned} 46 | $$ 47 | 48 | ### Parameter Estimation 49 | 50 | Assume you have a set of N sample points or observations, $x_1,\dots, x_N$, and you believe that this data was drawn from a distribution parametrized by an unknown value θ. 51 | 52 | One answer to this question is to infer that θ is equal to the value that maximizes the probability of having selected your sample $x_1,\dots, x_N$ from your assumed probability distribution. A frequently used and fundamental method in machine learning known as **maximum likelihood estimation (MLE)** does exactly this. 53 | 54 | Maximum likelihood estimation typically makes the following simplifying assumptions: 55 | - Each sample is drawn from the same distribution. In other words, each $x_i$ is identically distributed. 56 | - Each sample $x_i$ is conditionally independent of the others, given the parameters for our distribution. 57 | - All possible values of θ are equally likely before we’ve seen any data (this is known as a uniform prior). 58 | 59 | The first two assumptions above are often referred to as **independent, identically distributed (i.i.d.).** The third assumption above makes the MLE method a special case of the maximum a priori (MAP) method, which allows for non-uniform priors 60 | 61 | ![](attachments/19-Navie_Bayes.png) 62 | 63 | ### Maximum Likelihood for Naive Bayes 64 | 65 | Considering $f_{i}^{(j)}$ is a 1 if word i appeared in $j_th$ email under consideration and 0 otherwise, we get: 66 | 67 | 68 | $$ 69 | \mathscr{L}(\boldsymbol{\theta})=\prod_{j=1}^{N_h}P(F_i=f_i^{(j)}|Y=ham)=\prod_{j=1}^{N_h}\theta^{f_i^{(j)}}(1-\theta)^{1-f_i^{(j)}} 70 | $$ 71 | 72 | To simplify the problem, we use monotonic transformation, that is, taking the logarithm of $\mathscr{L}(\theta)$ : 73 | 74 | $$ 75 | \begin{aligned}\log\mathscr{L}(\theta)&=\quad\log\left(\prod_{j=1}^{N_h}\theta^{f_i^{(j)}}(1-\boldsymbol{\theta})^{1-f_i^{(j)}}\right)\\&=\quad\sum_{j=1}^{N_h}\log\left(\theta^{f_i^{(j)}}(1-\boldsymbol{\theta})^{1-f_i^{(j)}}\right)\\&=\quad\sum_{j=1}^{N_h}\log\left(\theta^{f_i^{(j)}}\right)+\sum_{j=1}^{N_h}\log\left((1-\boldsymbol{\theta})^{1-f_i^{(j)}})\right)\\&=\quad\log(\theta)\sum_{j=1}^{N_h}f_i^{(j)}+\log(1-\boldsymbol{\theta})\sum_{j=1}^{N_h}(1-f_i^{(j)})\end{aligned} 76 | $$ 77 | 78 | N - the number of observations (emails) you have for training. For our upcoming discussion, let’s also define $N_h$ as the number of training samples labeled as ham and $N_s$ as the number of training samples labeled as spam. Note $N_h +N_s = N$. 79 | 80 | $$ 81 | \begin{aligned} 82 | \frac\partial{\partial\boldsymbol{\theta}}\left(\log(\boldsymbol{\theta})\sum_{j=1}^{N_h}f_i^{(j)}+\log(1-\boldsymbol{\theta})\sum_{j=1}^{N_h}(1-f_i^{(j)})\right)&=0\\ 83 | \frac1\theta\sum_{j=1}^{N_h}f_i^{(j)}-\frac1{(1-\boldsymbol{\theta})}\sum_{j=1}^{N_h}f_i^{(j)}&=0\\ 84 | \frac1{\theta}\sum_{j=1}^{N_h}f_i^{(j)}&=\frac1{(1-\boldsymbol{\theta})}\sum_{j=1}^{N_h}(1-f_i^{(j)})\\ 85 | (1-\boldsymbol{\theta}\sum_{j=1}^{N_h}f_i^{(j)}&=\theta\sum_{j=1}^{N_h}(1-f_i^{(j)})\\\sum_{j=1}^{N_h}f_i^{(j)}-\boldsymbol{\theta}\sum_{j=1}^{N_h}f_i^{(j)}&=\theta\cdot N_h\\ 86 | \theta&=\frac1{N_h}\sum_{j=1}^{N_h}f_i^{(j)}=\theta\cdot N_h\\ 87 | \theta&=\frac1{N_h}\sum_{j=1}^{N_h}f_i^{(j)}\end{aligned} 88 | $$ 89 | 90 | We’ve arrived at a remarkably simple final result! 91 | 92 | ### Laplace smoothing 93 | 94 | Though maximum likelihood estimation is a very powerful method for parameter estimation, bad training data can often lead to unfortunate consequences. For example, if every time the word "minute" appears in an email in our training set, that email is classified as spam, our trained model will learn that $\boldsymbol{P}(F_{minute}=1|Y=ham)=0$; then every time "minute" appears, our model must consider it as spam. This is a classic example of **overfitting**, or building a model that doesn’t generalize well to previously unseen data. 95 | 96 | Overfitting with Naive Bayes’ classifiers can be mitigated by Laplace smoothing. Conceptually, Laplace smoothing with strength k assumes having seen k extra of each outcome. 97 | 98 | In N mails with |X| kinds of mails, $\forall x \in X$, if using MLE, we get $P_{MLE}(x)=\frac{count(x)}N$. And then let's assume that there are k more of each of these messages in the sample. So we get: 99 | 100 | $$P_{LAP,k}(x)=\frac{count(x)+k}{N+k|X|} \implies P_{LAP,k}(x|y)=\frac{count(x,y)+k}{count(y)+k|X|}$$ 101 | The specific value of k that’s appropriate to use in our model is typically determined by trial-and-error. k is a hyperparameter in our model, which means that we can set it to whatever we want and see which value yields the best prediction accuracy/performance on our validation data. 102 | 103 | - $P_{LAP,k}(x)=\frac{count(x)+k}{N+k|X|}$ 104 | - $P_{LAP,0}(x)=\frac{count(x)}{N} = P_{MEL}(x)$ 105 | - $P_{LAP,\infty}(x)=\frac{1}{|X|}$ 106 | 107 | ## link 108 | 109 | - [cs188-sp24-note19](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note19.pdf) -------------------------------------------------------------------------------- /note/20-Perceptron.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Linear Classifiers 12 | 13 | The basic idea of a linear classifier is to do classification using a linear combination of the features– a value which we call the activation. Concretely, the activation function takes in a data point, multiplies each feature of our data point, $f_i(x)$, by a corresponding weight, wi , and outputs the sum of all the resulting values. In vector form, we can also write this as a dot product of our weights as a vector, w, and our featurized data point as a vector f(x): 14 | 15 | $$\mathrm{activation}_{w}(\mathbf{x})=h_{{\mathbf{w}}}(\mathbf{x})=\sum_{i}w_{i}f_{i}(\mathbf{x})=\mathbf{w}^{T}\mathbf{f}(\mathbf{x})=\mathbf{w}\cdot\mathbf{f}(\mathbf{x})$$ 16 | 17 | ### Binary Perceptron 18 | 19 | $$ 20 | \text{classify}(\mathbf{x})=\begin{cases} 21 | +&\mathrm{if~}h_{\mathbf{w}}(\mathbf{x})>0 \iff \cos{\theta } > 0 \iff 0<\theta < \frac{\pi}{2} \\ 22 | -&\mathrm{if~}h_{\mathbf{w}}(\mathbf{x})<0 \iff \cos{\theta } < 0 \iff \frac{\pi}{2} < \theta < \pi \\ 23 | \end{cases} 24 | $$ 25 | 26 | ![](attachments/20-Perceptron.png) 27 | 28 | We call this blue line the **decision boundary** because it is the boundary that separates the region where we classify data points as positive from the region of negatives. In higher dimensions, a linear decision boundary is generically called a **hyperplane**. 29 | 30 | ![](attachments/20-Perceptron-1.png) 31 | 32 | $$ 33 | \mathbf{h_{w+y^{*}f(x)}(x)= (w+y^{*}f(x))^T f(x)=h_{w}(x)+y^{*}f(x)^T f(x)} 34 | $$ 35 | 36 | where $\mathbf{f(x)^T f(x)}$ is a positive number, so the $\mathbf{h_{w}(x)}$ changes in the direction of $y^*$. 37 | 38 | #### Bias 39 | 40 | Any decision boundary that you end up drawing will be crossing the origin. Basically, our perceptron can only produce a decision boundary that could be represented by the function $\mathbf{w}^\top\mathbf{f}(\mathbf{x})=0,\mathbf{w},\mathbf{f}(\mathbf{x})\in\mathbb{R}^n$. We will modify our feature and weights to add a bias term $\mathbf{b}$. 41 | 42 | ![](attachments/20-Perceptron-2.png) 43 | 44 | If $\mathbf{w'=w+\{1\}, f'(x)=f(x)+\{b\}}$, we also have: $\mathbf{w'^T f'(x)=0}$ . 45 | 46 | ### Multiclass Perceptron 47 | 48 | For the multi-class case, we will have one weight vector for each class. In order to classify a sample, we compute a score for each class by taking the dot product of the feature vector with each of the weight vectors. Whichever class yields the highest score is the one we choose as our prediction. 49 | 50 | Instead of doing as many dot products as there are classes, we can instead do a single matrix-vector multiplication. This tends to be much more efficient in practice (because matrix-vector multiplication usually has a highly optimized implementation). 51 | 52 | ![](attachments/20-Perceptron-3.png) 53 | 54 | ## link 55 | 56 | - [cs188-sp24-note0](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note0.pdf) -------------------------------------------------------------------------------- /note/21-Regression.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Linear Regression 12 | 13 | Regression problems are a form of machine learning problem in which the output is a continuous variable (denoted with y). The features can be either continuous or categorical. We will denote a set of features with $x \in \mathbb{R}^n$ for n features, i.e. $\mathbf{x} = (x_1 , \dots, x_n)$. 14 | 15 | The quantities y, X and w are defined as follows: 16 | 17 | $$ 18 | \mathbf{y}=\begin{bmatrix}y^1\\y^2\\\vdots\\y^n\end{bmatrix},\:\mathbf{X}=\begin{bmatrix}1&x_1^1&\cdots&x_1^n\\1&x_2^1&\cdots&x_2^n\\\vdots&\vdots&\cdots&\vdots\\1&x_N^1&\cdots&x_N^n\end{bmatrix},\:\mathbf{w}=\begin{bmatrix}w_0\\w_1\\\vdots\\w_n\end{bmatrix} \leftrightarrow \mathbf{\hat{y}=Xw} 19 | $$ 20 | 21 | If we use the L2 loss function which penalizes the difference of the predicted from the actual output using the L2 norm: 22 | 23 | $$ 24 | Loss(h_{\mathbf{w}})=\frac{1}{2}\sum_{j=1}^{N}L2(y^{j},h_{\mathbf{w}}(\mathbf{x}^{j}))=\frac{1}{2}\sum_{j=1}^{N}(y^{j}-h_{\mathbf{w}}(\mathbf{x}^{j}))^{2}=\frac{1}{2}\left\|\mathbf{y}-\mathbf{X}\mathbf{w}\right\|_{2}^{2} 25 | $$ 26 | 27 | More specifically, we will find the $\mathbf{\hat{w}}$ that minimizes the loss function by differentiating the loss function and setting the derivative equal to zero: 28 | 29 | $$ 30 | \begin{aligned}\nabla_\mathbf{w}\frac12\left\|\mathbf{y}-\mathbf{X}\mathbf{w}\right\|_2^2&=\nabla_\mathbf{w}\frac12\left(\mathbf{y}-\mathbf{X}\mathbf{w}\right)^T\left(\mathbf{y}-\mathbf{X}\mathbf{w}\right)=\nabla_\mathbf{w}\frac12\left(\mathbf{y}^T\mathbf{y}-\mathbf{y}^T\mathbf{X}^T\mathbf{y}+\mathbf{w}^T\mathbf{X}\mathbf{w}\right)\\&=\nabla_\mathbf{w}\frac12\left(\mathbf{y}^T\mathbf{y}-2\mathbf{w}^T\mathbf{X}^T\mathbf{y}+\mathbf{w}^T\mathbf{X}\mathbf{w}\right)=-\mathbf{X}^T\mathbf{y}+\mathbf{X}^T\mathbf{X}\mathbf{w}\end{aligned} 31 | $$ 32 | 33 | then: 34 | 35 | $$ 36 | \nabla_\mathbf{w}\frac12\left\|\mathbf{y}-\mathbf{X}\mathbf{\hat{w}}\right\|_2^2 = 0 \implies \hat{\mathbf{w}}=(\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y} 37 | $$ 38 | 39 | ### Optimization 40 | 41 | In complicated cases, we can use **gradient-based methods** to find the optimal weights, as shown below ($\alpha$ stands for learning rate). 42 | 43 | ![](attachments/21-Regression.png) 44 | 45 | If our dataset has a large number of n data points then computing the gradient as above in each iteration of the gradient descent algorithm might be too computationally intensive. As such, approaches like stochastic and batch gradient descent have been proposed. 46 | 47 | #### stochastic gradient descent 48 | 49 | In stochastic gradient descent at each iteration of the algorithm we use only one data point to compute the gradient. That one data point is each time randomly sampled form the dataset. Given that we only use one data point to estimate the gradient, stochastic gradient descent can lead to noisy gradients and thus make convergence a bit harder. 50 | 51 | #### Mini-batch gradient descent 52 | 53 | Mini-batch gradient descent uses a batch of size m of data points each time to compute the gradients. The batch size m is a user specified parameter. 54 | 55 | ### Logistic Regression 56 | 57 | Logistic regression allows us to turn a linear combination of our input features into a probability using the logistic function: $h_\mathbf{w}(\mathbf{x})=\frac1{1+e^{-\mathbf{w}^T\mathbf{x}}}$. It is important to note that though logistic regression is named as regression, this is a misnomer. Logistic regression is used to solve classification problems, not regression problems (for its function looks like:) 58 | 59 | ![](attachments/21-Regression-1.png) 60 | 61 | $$ 62 | \begin{cases} 63 | P(y=+1|\mathbf{f}(\mathbf{x});\mathbf{w})=\frac1{1+e^{-\mathbf{w}^T\mathbf{f}(\mathbf{x})}}\quad \\ 64 | P(y=-1|\mathbf{f}(\mathbf{x});\mathbf{w})=1-\frac1{1+e^{-\mathbf{w}^T\mathbf{f}(\mathbf{x})}} 65 | \end{cases} 66 | $$ 67 | 68 | ### Multi-Class Logistic Regression 69 | 70 | We use the **softmax function** in place of the logistic function 71 | 72 | $$ 73 | P(y=i|\mathbf{f}(\mathbf{x});\mathbf{w})=\frac{e^{\mathbf{w}_i^T\mathbf{f}(\mathbf{x})}}{\sum_{k=1}^Ke^{\mathbf{w}_k^T\mathbf{f}(\mathbf{x})}} 74 | $$ 75 | 76 | Hence, we can now express the likelihood as follows: 77 | 78 | $$ 79 | \ell(\mathbf{w}_1,\ldots,\mathbf{w}_K)=\prod_{i=1}^n\prod_{k=1}^K\left(\frac{e^{\mathbf{w}_k^T\mathbf{f}(\mathbf{x}_i)}}{\sum_{\ell=1}^Ke^{\mathbf{w}_\ell^T\mathbf{f}(\mathbf{x}_i)}}\right)^{t_{i,k}} 80 | \implies 81 | \log\ell(\mathbf{w}_1,\ldots,\mathbf{w}_K)=\sum_{i=1}^n\sum_{k=1}^Kt_{i,k}\log\left(\frac{e^{\mathbf{w}_k^T\mathbf{f}(\mathbf{x}_i)}}{\sum_{\ell=1}^Ke^{\mathbf{w}_\ell^T\mathbf{f}(\mathbf{x}_i)}}\right) 82 | $$ 83 | 84 | In the example of the multi-class logistic regression the gradient with respect to $w_j$ is given by: 85 | 86 | $$ 87 | \nabla_{\mathbf{w}_j}\log\ell(\mathbf{w})=\sum_{i=1}^n\nabla_{\mathbf{w}_j}\sum_{k=1}^Kt_{i,k}\log\left(\frac{e^{\mathbf{w}_k^T\mathbf{f}(\mathbf{x}_i)}}{\sum_{\ell=1}^Ke^{\mathbf{w}_\ell^T\mathbf{f}(\mathbf{x}_i)}}\right)=\sum_{i=1}^n\left(t_{i,j}-\frac{e^{\mathbf{w}_j^T\mathbf{f}(\mathbf{x}_i)}}{\sum_{\ell=1}^Ke^{\mathbf{w}_\ell^T\mathbf{f}(\mathbf{x}_i)}}\right)\mathbf{f}(\mathbf{x}_i) 88 | $$ 89 | 90 | where we used the fact that $\sum_{k}{t_{i,k}}=1$. 91 | 92 | ## link 93 | 94 | - [cs188-sp24-note21](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note21.pdf) -------------------------------------------------------------------------------- /note/22-Neural_Networks.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | ### Non-linear Separators 12 | 13 | Consider the following set of data: 14 | 15 | ![](attachments/22-Neural_Networks.png) 16 | 17 | We would like to separate the two colors, and clearly there is no way this can be done in a single dimension (a single dimensional decision boundary would be a point, separating the axis into two regions). To fix this problem, we can add additional (potentially nonlinear) features to construct a decision boundary from. Consider the same dataset with the addition of $x^2$ as a feature: 18 | 19 | ![](attachments/22-Neural_Networks-1.png) 20 | 21 | 22 | With this additional piece of information, we are now able to construct a linear separator in the two dimensional space containing the points. In this case, we were able to fix the problem by mapping our data to a higher dimensional space by manually adding useful features to data points. However, in many highdimensional problems, such as image classification, manually selecting features that are useful is a tedious problem. This requires domain-specific effort and expertise, and works against the goal of generalization across tasks. A natural desire is to learn these featurization or transformation functions as well, perhaps using a nonlinear function class that is capable of representing a wider variety of functions. 23 | 24 | ### Multi-layer Perceptron 25 | 26 | Consider the following setup, a two-layer perceptron, which is a perceptron that takes as input the outputs of another perceptron. 27 | 28 | ![](attachments/22-Neural_Networks-2.png) 29 | 30 | In fact, we can generalize this to an N-layer perceptron. 31 | 32 | > [!THEOREM] Universal Function Approximators 33 | > 34 | > A two-layer neural network with a sufficient number of neurons can approximate any continuous function to any desired accuracy. 35 | 36 | ### Measuring Accuracy 37 | 38 | The accuracy of the binary perceptron after making n predictions can be expressed as: 39 | 40 | $$ 41 | l^{acc}(w)=\frac1n\sum_{i=1}^n(sgn(w\cdot\mathbf{f}(\mathbf{x}_i))==y_i)\quad where\quad 42 | sgn(x)= 43 | \begin{cases} 44 | +1, & x > 0 \\ 45 | 0, & x = 0 \\ 46 | -1, & x < 0 47 | \end{cases} 48 | $$ 49 | 50 | ### Multi-layer Feedforward Neural Networks 51 | 52 | Multi-layer NN is much like the multi-layer perceptron, however, we choose a different non-linearity to apply after the individual perceptron nodes. Non-linearities makes the network as a whole non-linear and more expressive. 53 | 54 | - $\text{Sigmoid: }\sigma(x)=\frac1{1+e^{-x}}$ 55 | - $ReLU{:~}f(x)=max(0, x)=\begin{cases}0&\mathrm{if~}x<0\\x&\mathrm{if~}x\geq0&\end{cases}$ 56 | 57 | ### Backpropagation 58 | 59 | To efficiently calculate the gradients for each parameter in a neural network, we will use an algorithm known as backpropagation. Backpropagation represents the neural network as a dependency graph of operators and operands, called a computational graph, such as the one shown below for computing $(2+3)*4$ ($g=(x+y) \land f = g*z$): 60 | 61 | ![](attachments/22-Neural_Networks-3.png) 62 | 63 | Recall the chain rule in calculus (for $f(x_{1}, x_{2}, \dots x_{n})$ where $x_{k}(t_{1}, t_{2}, \dots , t_{m})$): 64 | 65 | $$ 66 | \frac{\partial f}{\partial t_{i}}=\frac{\partial f}{\partial x_{1}}\cdot\frac{\partial x_{1}}{\partial t_{i}}+\frac{\partial f}{\partial x_{2}}\cdot\frac{\partial x_{2}}{\partial t_{i}}+\ldots+\frac{\partial f}{\partial x_{n}}\cdot\frac{\partial x_{n}}{\partial t_{i}}. 67 | $$ 68 | 69 | Values in green are the outputs of each node, which we compute in the forward pass, where we apply each node’s operation to its input values coming from its parent nodes. 70 | 71 | Values in red after each node give gradients of the function computed by the graph, which are computed in the backward pass: the red `1` after $f$ stands for $\frac{\partial f}{\partial f}$; red `4` after $g / z$ stands for $\frac{\partial f}{\partial g} / \frac{\partial f}{\partial z}$. Then gets $\frac{\partial f}{\partial x} / \frac{\partial f}{\partial y}$ . 72 | 73 | Computation graphs are a great way to visualize repeated application of the chain rule from calculus, as this process is required for backpropagation in neural networks. 74 | 75 | ## link 76 | 77 | - [cs188-sp24-note22](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note22.pdf) -------------------------------------------------------------------------------- /note/24-Reinforcement_Learnin.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | - cs188 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | ## note 10 | 11 | In the previous note, solving Markov decision processes is an example of **offline planning**, where agents have full knowledge of both the transition function and the reward function, all the information they need to precompute optimal actions in the world encoded by the MDP without ever actually taking any actions. In this note, we’ll discuss **online planning**, during which an agent has no prior knowledge of rewards or transitions in the world (still represented as a MDP). 12 | 13 | In online planning, an agent must try **exploration**, during which it performs actions and receives feedback in the form of the successor states it arrives in and the corresponding rewards it reaps. The agent uses this feedback to estimate an optimal policy through a process known as **reinforcement learning** before using this estimated policy for exploitation or reward maximization. 14 | 15 | There are two types of reinforcement learning, model-based learning and model-free learning. 16 | - Modelbased learning attempts to estimate the transition and reward functions with the samples attained during exploration before using these estimates to solve the MDP normally with value or policy iteration. 17 | - Modelfree learning, on the other hand, attempts to estimate the values or Q-values of states directly, without ever using any memory to construct a model of the rewards and transitions in the MDP. 18 | 19 | > 内容很紧,原 note 没有啥可以省略的,建议直接看原文,下面是很好的总结: 20 | 21 | ![](attachments/24-Reinforcement_Learnin.png) 22 | 23 | ## link 24 | 25 | - [cs188-sp24-note24](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note24.pdf) 26 | - [cs188-sp24-note25](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/notes/cs188-sp24-note25.pdf) -------------------------------------------------------------------------------- /note/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | comments: true 3 | tags: 4 | - notes 5 | --- 6 | 7 | # cs188 - sp24 8 | 9 | 这里的是 UCB [CS 188 Spring 2024](https://inst.eecs.berkeley.edu/~cs188/sp24/) 的笔记,主体为原课程 notes,加入了自己的思考和排版。 10 | 11 | > 该课程所有资料存放于 [cs188 repo](https://github.com/Darstib/cs188),笔记中部分链接也指向为仓库中的相对路径;所以建议将仓库资料全数获取,并使用 [obsidian](https://obsidian.md/) 打开。 12 | 13 | > [!ATTENTION] 14 | > 15 | > 以下所有讲解默认读者阅读或理解了其中 PREREQUISITE 部分所有内容;python 的使用默认会;至少需要明白类的使用。 16 | 17 | - [01-Intro_to_AI_Rational_Agents](01-Intro_to_AI_Rational_Agents.md) 18 | - [02-State_Spaces_Uninformed_Search](02-State_Spaces_Uninformed_Search.md) 19 | - [03-Informed_Search_Astar_and_Heuristics](03-Informed_Search_Astar_and_Heuristics.md) 20 | - [04-Local_Search](04-Local_Search.md) 21 | - [05-Trees_Minimax_Pruning](05-Trees_Minimax_Pruning.md) 22 | - [06-Expectimax_Monte_Carlo_Tree_Search](06-Expectimax_Monte_Carlo_Tree_Search.md) 23 | - [07-Propositional_Logic_and_Planning](07-Propositional_Logic_and_Planning.md) 24 | - [08-DPLL&ForwardChaining](08-DPLL&ForwardChaining.md) 25 | - [09-First_Order_Logic](09-First_Order_Logic.md) 26 | - [10-Intro_to_Probability](10-Intro_to_Probability.md) 27 | - [11-Bayesian_Network_Intro](11-Bayesian_Network_Intro.md) 28 | - [12-Variable_Elimination](12-Variable_Elimination.md) 29 | - [13-Approximate_Inference](13-Approximate_Inference.md) 30 | - [14-Markov_Models](14-Markov_Models.md) 31 | - [15-Hidden_Marko_Models](15-Hidden_Marko_Models.md) 32 | - [16-PF-DN-VPI](16-PF-DN-VPI.md) 33 | - [17-Markov_Decision_Processes](17-Markov_Decision_Processes.md) 34 | - [18-Iteration](18-Iteration.md) 35 | - [19-Navie_Bayes](19-Navie_Bayes.md) 36 | - [20-Perceptron](20-Perceptron.md) 37 | - [21-Regression](21-Regression.md) 38 | - [22-Neural_Networks](22-Neural_Networks.md) 39 | - [24-Reinforcement_Learnin](24-Reinforcement_Learnin.md) 40 | - [problem](problem.md) 41 | - docs 中比较值得看的题(后来没看了)。 -------------------------------------------------------------------------------- /note/attachments/02_Search-State-Spaces-Uninformed-Search-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/02_Search-State-Spaces-Uninformed-Search-1.png -------------------------------------------------------------------------------- /note/attachments/02_Search-State-Spaces-Uninformed-Search-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/02_Search-State-Spaces-Uninformed-Search-2.png -------------------------------------------------------------------------------- /note/attachments/02_Search-State-Spaces-Uninformed-Search-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/02_Search-State-Spaces-Uninformed-Search-3.png -------------------------------------------------------------------------------- /note/attachments/02_Search-State-Spaces-Uninformed-Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/02_Search-State-Spaces-Uninformed-Search.png -------------------------------------------------------------------------------- /note/attachments/02_State-Spaces-Uninformed-Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/02_State-Spaces-Uninformed-Search.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-1.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-2.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-3.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-4.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-5.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search-6.png -------------------------------------------------------------------------------- /note/attachments/03_State-Spaces-Uninformed-Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/03_State-Spaces-Uninformed-Search.png -------------------------------------------------------------------------------- /note/attachments/04_Local-Search-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/04_Local-Search-1.png -------------------------------------------------------------------------------- /note/attachments/04_Local-Search-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/04_Local-Search-2.png -------------------------------------------------------------------------------- /note/attachments/04_Local-Search-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/04_Local-Search-3.png -------------------------------------------------------------------------------- /note/attachments/04_Local-Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/04_Local-Search.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-1.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-2.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-3.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-4.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-5.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-6.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-7.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning-8.png -------------------------------------------------------------------------------- /note/attachments/05_Trees-Minimax-Pruning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/05_Trees-Minimax-Pruning.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-1.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-2.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-3.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-4.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-5.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search-6.png -------------------------------------------------------------------------------- /note/attachments/06_Expectimax-Monte-Carlo-Tree-Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/06_Expectimax-Monte-Carlo-Tree-Search.png -------------------------------------------------------------------------------- /note/attachments/07-Propositional_Logic_and_Planning-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/07-Propositional_Logic_and_Planning-1.png -------------------------------------------------------------------------------- /note/attachments/07-Propositional_Logic_and_Planning-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/07-Propositional_Logic_and_Planning-2.png -------------------------------------------------------------------------------- /note/attachments/07-Propositional_Logic_and_Planning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/07-Propositional_Logic_and_Planning.png -------------------------------------------------------------------------------- /note/attachments/09-First_Order_Logic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/09-First_Order_Logic.png -------------------------------------------------------------------------------- /note/attachments/10-Intro_to_Probability.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/10-Intro_to_Probability.png -------------------------------------------------------------------------------- /note/attachments/11-Bayesian_Network_Intro-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/11-Bayesian_Network_Intro-1.png -------------------------------------------------------------------------------- /note/attachments/11-Bayesian_Network_Intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/11-Bayesian_Network_Intro.png -------------------------------------------------------------------------------- /note/attachments/12-Variable_Elimination-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/12-Variable_Elimination-1.png -------------------------------------------------------------------------------- /note/attachments/12-Variable_Elimination.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/12-Variable_Elimination.png -------------------------------------------------------------------------------- /note/attachments/13_Approximate Inference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/13_Approximate Inference.png -------------------------------------------------------------------------------- /note/attachments/14-Markov_Models.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/14-Markov_Models.png -------------------------------------------------------------------------------- /note/attachments/15-Hidden_Marko_Models-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-Hidden_Marko_Models-1.png -------------------------------------------------------------------------------- /note/attachments/15-Hidden_Marko_Models-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-Hidden_Marko_Models-2.png -------------------------------------------------------------------------------- /note/attachments/15-Hidden_Marko_Models.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-Hidden_Marko_Models.png -------------------------------------------------------------------------------- /note/attachments/15-PF-DN-OT-VPI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-PF-DN-OT-VPI.png -------------------------------------------------------------------------------- /note/attachments/15-PF-DN-VPI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-PF-DN-VPI.png -------------------------------------------------------------------------------- /note/attachments/15-Particle_Filtering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/15-Particle_Filtering.png -------------------------------------------------------------------------------- /note/attachments/17-Markov_Decision_Processes-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/17-Markov_Decision_Processes-1.png -------------------------------------------------------------------------------- /note/attachments/17-Markov_Decision_Processes-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/17-Markov_Decision_Processes-2.png -------------------------------------------------------------------------------- /note/attachments/17-Markov_Decision_Processes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/17-Markov_Decision_Processes.png -------------------------------------------------------------------------------- /note/attachments/18-Iteration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/18-Iteration.png -------------------------------------------------------------------------------- /note/attachments/19-Machine_Learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/19-Machine_Learning.png -------------------------------------------------------------------------------- /note/attachments/19-Navie_Bayes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/19-Navie_Bayes.png -------------------------------------------------------------------------------- /note/attachments/20-Perceptron-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/20-Perceptron-1.png -------------------------------------------------------------------------------- /note/attachments/20-Perceptron-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/20-Perceptron-2.png -------------------------------------------------------------------------------- /note/attachments/20-Perceptron-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/20-Perceptron-3.png -------------------------------------------------------------------------------- /note/attachments/20-Perceptron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/20-Perceptron.png -------------------------------------------------------------------------------- /note/attachments/21-Regression-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/21-Regression-1.png -------------------------------------------------------------------------------- /note/attachments/21-Regression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/21-Regression.png -------------------------------------------------------------------------------- /note/attachments/22-Neural_Networks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/22-Neural_Networks-1.png -------------------------------------------------------------------------------- /note/attachments/22-Neural_Networks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/22-Neural_Networks-2.png -------------------------------------------------------------------------------- /note/attachments/22-Neural_Networks-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/22-Neural_Networks-3.png -------------------------------------------------------------------------------- /note/attachments/22-Neural_Networks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/22-Neural_Networks.png -------------------------------------------------------------------------------- /note/attachments/24-Reinforcement_Learnin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/note/attachments/24-Reinforcement_Learnin.png -------------------------------------------------------------------------------- /note/problem.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | --- 5 | 6 | 7 | > 这里是一些比较值得看的题目;链接效果只在 obsidian 中可以使用,但仍可根据对应的路径/文件名/题目名找到对应的题目。 8 | 9 | 10 | -------------------------------------------------------------------------------- /project/README.md: -------------------------------------------------------------------------------- 1 | # The Pac-Man Projects 2 | 3 | 这里是CS188 sp24 的 project [The Pac-Man Projects](https://inst.eecs.berkeley.edu/~cs188/sp24/projects/) 的解答。 4 | 5 | 项目实现效果大致如:[pacman_game](https://inst.eecs.berkeley.edu/~cs188/sp24/assets/images/pacman_game.gif)。 6 | 7 | > [!ATTENTION] 8 | > 9 | > 以下所有讲解默认读者阅读或者理解了对应 `[!PREREQUISITE]` 部分的所有内容,且**看懂** python 语法没有问题。 10 | 11 | - [project-0](project-0.md) 12 | - [project-1](project-1.md) 13 | - [project-2](project-2.md) 14 | - [project-3](project-3.md) 15 | - [project-4](project-4.md) 16 | 17 | > [!ENV] 本人 project 环境 18 | > 19 | > - project 0-3 20 | > - WSL ubuntu 22.04; 21 | > - miniconda => python=3.9.19 22 | > - project 4-now 23 | > - MacOS 24 | > - miniforge3 => Python=3.10.16 25 | -------------------------------------------------------------------------------- /project/attachments/project-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-0.png -------------------------------------------------------------------------------- /project/attachments/project-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-1.png -------------------------------------------------------------------------------- /project/attachments/project-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-2.png -------------------------------------------------------------------------------- /project/attachments/project-1-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-3.png -------------------------------------------------------------------------------- /project/attachments/project-1-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-4.png -------------------------------------------------------------------------------- /project/attachments/project-1-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-5.png -------------------------------------------------------------------------------- /project/attachments/project-1-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-6.png -------------------------------------------------------------------------------- /project/attachments/project-1-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-7.png -------------------------------------------------------------------------------- /project/attachments/project-1-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-8.png -------------------------------------------------------------------------------- /project/attachments/project-1-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1-9.png -------------------------------------------------------------------------------- /project/attachments/project-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-1.png -------------------------------------------------------------------------------- /project/attachments/project-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-1.png -------------------------------------------------------------------------------- /project/attachments/project-2-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-10.png -------------------------------------------------------------------------------- /project/attachments/project-2-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-11.png -------------------------------------------------------------------------------- /project/attachments/project-2-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-12.png -------------------------------------------------------------------------------- /project/attachments/project-2-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-13.png -------------------------------------------------------------------------------- /project/attachments/project-2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-2.png -------------------------------------------------------------------------------- /project/attachments/project-2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-3.png -------------------------------------------------------------------------------- /project/attachments/project-2-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-4.png -------------------------------------------------------------------------------- /project/attachments/project-2-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-5.png -------------------------------------------------------------------------------- /project/attachments/project-2-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-6.png -------------------------------------------------------------------------------- /project/attachments/project-2-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-7.png -------------------------------------------------------------------------------- /project/attachments/project-2-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-8.png -------------------------------------------------------------------------------- /project/attachments/project-2-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2-9.png -------------------------------------------------------------------------------- /project/attachments/project-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-2.png -------------------------------------------------------------------------------- /project/attachments/project-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-3.png -------------------------------------------------------------------------------- /project/attachments/project-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-4-1.png -------------------------------------------------------------------------------- /project/attachments/project-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-4-2.png -------------------------------------------------------------------------------- /project/attachments/project-4-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-4-3.png -------------------------------------------------------------------------------- /project/attachments/project-4-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-4-4.png -------------------------------------------------------------------------------- /project/attachments/project-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darstib/cs188/b659b2611289eff384d9aa22d8ac12594f8e4344/project/attachments/project-4.png -------------------------------------------------------------------------------- /project/project-0.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | comments: true 5 | dg-publish: true 6 | --- 7 | 8 | # Tutorial 9 | 10 | > [!PREREQUISITE] 11 | > 12 | > - [project 0](https://inst.eecs.berkeley.edu/~cs188/sp24/projects/proj0/)(若需要认证,可见[仓库](https://github.com/Darstib/cs188/tree/main/materials/project/intro_page)) 13 | 14 | ## explain 15 | 16 | 这个是让我们熟悉项目使用和 python 的考察,没啥好讲的。 17 | 18 | ```shell 19 | python autograder.py # 评分全部 20 | python autograder.py -q q1 # 测试第一问 21 | ``` 22 | 23 | ```python title="addition.py" 24 | def add(a, b): 25 | "Return the sum of a and b" 26 | "*** YOUR CODE HERE ***" 27 | return a + b 28 | ``` 29 | 30 | ```python title="buyLotsOfFruit.py" 31 | def buyLotsOfFruit(orderList): 32 | """ 33 | orderList: List of (fruit, numPounds) tuples 34 | 35 | Returns cost of order 36 | """ 37 | totalCost = 0.0 38 | "*** YOUR CODE HERE ***" 39 | # 对于这道简单的题,下面的条件语句倒是可以省略 40 | for fruit, numPounds in orderList: 41 | if fruit in fruitPrices: 42 | totalCost += fruitPrices[fruit] * numPounds 43 | else: 44 | print("Sorry we don't have %s" % fruit) 45 | return None 46 | return totalCost 47 | ``` 48 | 49 | ```python title="shopSmart.py" 50 | def shopSmart(orderList, fruitShops): 51 | """ 52 | orderList: List of (fruit, numPound) tuples 53 | fruitShops: List of FruitShops 54 | """ 55 | "*** YOUR CODE HERE ***" 56 | best_shop = None 57 | # 将 lowest_cost 初始化为正无穷大,这样第一次循环时,lowest_cost 会被更新为第一个商店的 cost 58 | lowest_cost = float("inf") 59 | for fruitShop in fruitShops: 60 | cost = 0 61 | for fruit, numPounds in orderList: 62 | cost += fruitShop.fruitPrices[fruit] * numPounds 63 | if cost < lowest_cost: 64 | lowest_cost = cost 65 | best_shop = fruitShop 66 | return best_shop 67 | ``` 68 | ## pass 69 | 70 | - [project-0 全部通过](attachments/project-0.png) 71 | - [全代码](https://github.com/Darstib/cs188/tree/main/project/solution) -------------------------------------------------------------------------------- /project/project-3.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: 3 | - notes 4 | data: 2024-08-11 5 | comments: true 6 | dg-publish: true 7 | --- 8 | 9 | # Logic 10 | 11 | > [!PREREQUISITE] 12 | > 13 | > - [07-Propositional_Logic_and_Planning](../note/07-Propositional_Logic_and_Planning.md) 14 | > - [08-DPLL&ForwardChaining](../note/08-DPLL&ForwardChaining.md) 15 | > - [09-First_Order_Logic](../note/09-First_Order_Logic.md) 16 | > - [10-Intro_to_Probability](../note/10-Intro_to_Probability.md) 17 | > - [project 3](https://inst.eecs.berkeley.edu/~cs188/sp24/projects/proj3/)(若需要认证,可见[仓库](https://github.com/Darstib/cs188/tree/main/materials/project/intro_page)) 18 | 19 | ## Quick Review 20 | 21 | - DPLL(Davis-Putnam-Logemann-Loveland 算法) 22 | - DPLL 算法是一种深度优先回溯搜索算法,旨在解决可满足性问题(SAT),即给定一个逻辑句子,找到所有符号的有效赋值。该算法通过三种技巧减少过度回溯:早期终止、纯符号启发式和单元子句启发式。DPLL 处理的输入是合取范式(CNF),并通过不断赋值符号的真值,直到找到满足模型或无法赋值为止。 23 | - Forward Chaining(前向推理) 24 | - 前向推理是一种推理方法,常用于解决可满足性问题(SAT)。它通过从已知的事实出发,逐步应用规则来推导新的事实,直到达到目标或无法再推导出新事实为止。在SAT中,前向推理可以用于从已知的逻辑句子中推导出新的赋值,从而帮助确定是否存在满足条件的模型。 25 | - First-order Logic(第一阶逻辑,FOL) 26 | - 第一阶逻辑是一种形式逻辑系统,使用量词和变量来表达关于对象的命题。与命题逻辑不同,第一阶逻辑允许使用量词(如“对于所有”和“存在”)来处理更复杂的逻辑关系。 27 | 28 | ## explain 29 | 30 | 实话说,project 3 相比于考察逻辑运算,个人感觉考察 python 更加多;因为在讲解实验时,文档中给出了很多伪代码;哪怕我们不知道它在干什么,纯靠 python 编程实现它似乎不是什么难事。 31 | 32 | 同时基于此时其他比较需要花费时间的工作,我更多只是结合 project 3 将 [pavlosdais 的代码](https://github.com/pavlosdais/ai-berkeley/blob/main/Project%203%20-%20Logic/logicPlan.py)自己跑了一遍作罢。该代码基于cs188 sp22 的project 完成,部分函数名和一些些细节与 sp24 的略有不同,但本身讲的比较详细了,仔细读就能找到不同之处。 33 | 34 | - 对于Q1-Q5 看的比较仔细,也赞叹于将逻辑表达式“对象化”的操作; 35 | - 对于Q6-Q8 看的比较粗略;虽然后三问大同小异,还是佩服 pavlosdais 能够很好地将实验文档中的伪代码实例化。 36 | 37 | ## pass 38 | 39 | 我自己略作修改后的代码也会放在 [solution 文件夹](https://github.com/Darstib/cs188/tree/main/project/solution)中,已 [运行全部通过](attachments/project-3.png)。 --------------------------------------------------------------------------------