当前位置: 首页 > news >正文

CS50ai: week2 Uncertainty我的笔记A版 - 实践

该篇文章为随手笔记,如想要阅读更系统与细致的笔记可阅读B版

ω:概率中的一个世界,即一种可能的事件状态组合

  • ω发生的概率为:0 <= P(ω) <=1

  • Σ(ω∈Ω)P(ω) = 1 所有世界发生的概率为1

unconditional probability

degree of belief in a proposition in the absence of any other evidence

conditional probability

degree of belief in a proposition given some evidence that has already been revealed

  • 符号:P(a|b) a given b 在b已知基础上a的概率

  • Eg. 如P(disease | test results),基于实践结果的得病概率

  • P(a|b) =Р(а ^ b)/P(b)我们可以忽略b概率不存在的情况,他是基础。也可以写作Р(а ^ b)=P(b)P(a|b)=P(a)P(b|a)

random variable

a variable in probability theory with a domain of possible values it can take on

  • Eg. Weather {sun, cloud, rain, wind, snow} 后面这些就是对于Weather可以选择的变量

  • 或者 Flight {on time, delayed, cancelled}则又有

probability distribution概率分布

  • P(Flight = on time) = 0.6

  • P(Flight = delayed) = 0.3

  • P(Flight = cancelled) = 0.1

另一种形式:(P要粗体)P(Flight) = <0.6, 0.3, 0.1>(概率的顺序很重要,要和上面的三个状态顺序对应哦)

probability theory

independence

the knowledge that one event occurs does not affect the probability of the other event

并不绝对,支持的例子如蓝红骰子,反对的如雨和云,根据实际分析

  • 对于P(a ۸ b) = P(a)P(b|a)因为独立,所以a发生和a下b发生相乘得到a^b,因此是相互独立的

  • 不独立的情况:投骰子如果为6则不可能为4,不成立

    Bayes' Rule

    贝叶斯规则,公式由上面的conditional probability转化而来

    $$P(b|a)=\frac {P(a|b)P(b)}{P(a)}$$

    Eg.

    Given clouds in the morning,what's the probability of rain in the afternoon?

    80% of rainy afternoons start with cloudy mornings.

    40% of days have cloudy mornings.

    10% of days have rainy afternoons.

    $$P(rain | clouds) = \frac{P(clouds | rain)P(rain)}{P(clouds)$$

    则我们知道

    Knowing

    $$P(\text{visible effect} | \text{unknown cause}$$

    we can calculate

    $$P(\text{unknown cause} | \text{visible effect}$$

    Joint Probability

    联合概率

    通过此时能够看到,雨和云并非是独立的,因此当两个同时发生可能看到概率并非是两者相乘

    因此$$P(\text{C} | \text{rain})$$可得公式:

    $$P(\text{C} | \text{rain}) = \frac{P(\text{C}, \text{rain})}{P(\text{rain})} = \alpha P(\text{C}, \text{rain}) = \alpha\langle0.08, 0.02\rangle = \langle0.8, 0.2\rangl$$

    • (C, rain)表示C和rain一起发生

    • 乘某个常数让其总值为1

    Probability Rules

    Negation

    很简单的公式

    Inclusion-Exclusion

    减去求和的重复项

    Marginalization

    合并两个式子

    也能够写为,不一定只合并两个

    Conditioning

    P(a)=P(ab)P(b)+P(a∣¬b)Pb)

    等效概率,a概率等于b发生和不发生时a发生的概率

    Bayesian network

    data structure that represents the dependencies among random variables

    • directed graph

    • each node represents a random variable

    • each node X has probability distribution$$\mathbf{P}(X \mid \text{Parents}(X))$$

    Eg. 下面是四个节点。是否能赴约往上取决

    如下图,下雨程度影响了是否需要维护的概率,其他的节点之间也是一样的关系

    因此我们可以得到如下式子:

    P(Appointment | light, no) = α * P(Appointment, light, no)

    P(Appointment, light, no) = P(Appointment, light, no, on time) + P(Appointment, light, no, delayed)

    即——Inference by Enumeration

    • X is the query variable.

    • e is the evidence.

    • y ranges over values of hidden variables.

    • $$\alph$$ normalizes the result.

    在python的实现

    使用pomegranate库,让我们能自己创建节点,将分布的概率填入等等

    Sampling采样(一种Approximate Inference)

    根据最初项的概率分布随机选一个

    后面继续列概率随机选一项继续列

    ......

    得到贝叶斯可能的取值,如果重复进行好多次,那么会生成各种样本

    Eg. 我们假设了10000个样本,让他们寻路,符合条件sample["train"] == "delayed"的记录下来:

    # Rejection sampling
    # Compute distribution of Appointment given that train is delayed
    N = 10000
    data = []
    for i in range(N):sample = generate_sample()if sample["train"] == "delayed":data.append(sample["appointment"])
    print(Counter(data))

    Rejection Sampling

    根据特定条件选取,丢弃样本。但对于一些很苛刻的条件效率很低,因此我们有下面新的采样方法

    Likelihood Weighting

    • Start by fixing the values for evidence variables.

    • Sample the non-evidence variables using conditional probabilities in the Bayesian Network.

    • Weight each sample by its likelihood: the probability of all of the evidence.

    此时对于上面那个例子来说,train delayed是一个固定量,不计入加权。

    对于变量的加权:

    当对于右边的情况,在概率表里面寻找到对应的概率,他就是该样本所占的权重

    此时我们只计算了与具有这些离散值的特定变量有关的概率,但是并不涉及随着时间值会怎么变化,下面将介绍涵盖这一项的Approximate Inference方法

    Markov assumption

    the assumption that the current state depends on only a finite fixed number of previous states

    Markov chain

    a sequence of random variables where the distribution of each variable follows the Markov assumption

    遵从马尔可夫假设的链

    Transition model:

    根据这个推断,我们就得到了如下马尔可夫链

    在python的实现

    起始点:从rain 0.5 sunny 0.5开始

    定义过渡模型,今天sun,明天sun的概率变为0.8......

    抽样,抽取50个状态

    Sensor Models(emission probabilities)

    可以看到我们想要的都在Hidden State但是我们传感器收集到的只有Observation

    Hidden Markov Model属于Sensor Models

    a Markov model for a system with hidden states that generate some observed event

    隐藏马尔可夫模型,根据可检测的条件代替隐藏量

    比如用带伞代替下雨,但也只是假设,比如带伞也可能由于昨天下雨了,今天不一定

    http://www.rkmt.cn/news/29602.html

    相关文章:

  • 2025年搬家纸箱权威推荐榜单:物流包装/电商纸箱/平口纸箱源头厂家精选
  • 【LTDC】在 RGBLCD 屏上实现任意位置画点和读点
  • 使用C# 控制ethercat从站设备
  • 2025 年坡口机源头厂家最新推荐排行榜:欧盟 CE 认证企业领衔,含 15 年工业服务经验品牌,自走式/自动/板材/管道坡口机厂家推荐
  • 实战练习:小软件页面间跳转传值 子页面数据渲染
  • 2025 年气凝胶生产厂家最新推荐排行榜:含气凝胶毡 / 粉 / 隔热板 / 保温罩 / 陶瓷板品牌,优质厂家推荐
  • 详细介绍:Uvicorn - Python ASGI Web 服务器
  • 2025年3d全息投影生产厂家权威推荐榜单:全息投影展厅/全息投影沙盘/全息投影源头厂家精选
  • JMeter Plugin Manager Linux 插件安装命令行
  • 整体理解pai0-具身智能-PyTorch einsum 完全教程-11 - jack
  • 2025年北京奢侈品品牌首饰回收公司权威推荐榜单:钻石回收/黄金回收/钻戒回收源头公司精选
  • 查询每门成绩都大于80分的同学学号
  • NVIDIA与Adobe漏洞深度解析
  • 2025 年退磁器生产厂家最新推荐榜:技术创新、行业适配与服务保障全景对比及权威测评结果强力退磁器/手提退磁器/小型退磁器公司推荐
  • 计算机组成原理:磁盘存储设备 - 实践
  • 题解:P8134 [ICPC 2020 WF] Opportunity Cost
  • 深入解析:数据结构 之 【图的遍历与最小生成树】(广度优先遍历算法、深度优先遍历算法、Kruskal算法、Prim算法实现)
  • qcefview库的使用
  • 2025年项目总延期?这30款项目进度管理软件让我提前交付率85%!
  • STM32软件I2C读写AT24C64 - 指南
  • bcc
  • 2025年自动定量灌装机厂家权威推荐榜单:称重灌装机/膏状灌装机/瓶灌装机源头厂家精选
  • 厨房电子秤芯片方案:SIC8833
  • 深入理解Java线程
  • RFSOC学习记录(六)混频模式分析
  • 每周读书与学习-JMeter主要元件详细介绍(二)函数助手
  • 2025年BPM系统排名深度测评:5大主流厂商哪家适合你?
  • OSI七层网络参考模型(Leo)
  • 实用指南:YOLO系列——实时屏幕检测
  • 在 macOS 中遇到 brew 命令不存在的问题