当前位置: 首页 > 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.jsqmd.com/news/21551/

    相关文章:

  • 2025 OSCAR丨与创新者同频!Apache RocketMQ 邀您共赴开源之约
  • 2025年PSA制氮设备厂家权威推荐榜单:电解水制氢设备/氦气纯化系统/氘气回收纯化源头厂家精选
  • 解决git clone只有master分支的问题
  • 一文读懂循环神经网络(RNN):原理、局限与LSTM解决方案 - 指南
  • 2025年搬家纸箱权威推荐榜单:物流包装/电商纸箱/平口纸箱源头厂家精选
  • 大数据案例 -2025/10/24
  • 2025年北京cppm认证培训公司权威推荐榜单:cppm考前培训/cppm证书培训/cppm课程培训源头公司精选
  • 详细介绍:记一次达梦数据库的查询异常
  • 从价值直觉到价值理性:AI元人文演进路径解读
  • 【LTDC】在 RGBLCD 屏上实现任意位置画点和读点
  • 2025年阳台壁挂太阳能厂家权威推荐榜单:分体式阳台太阳能/阳台壁挂太阳能热水器/分体式阳台太阳能源头厂家精选
  • 使用C# 控制ethercat从站设备
  • 0273-GRPC-tonic 进行编解码
  • 0271-GRPC-prost 带长度的编解码
  • 2025 年坡口机源头厂家最新推荐排行榜:欧盟 CE 认证企业领衔,含 15 年工业服务经验品牌,自走式/自动/板材/管道坡口机厂家推荐
  • 0270-GRPC-使用 prost 解码
  • 完整教程:Java开发者进阶之路
  • 动手动脑4
  • 2025 年保温涂料厂家最新推荐排行榜:聚焦技术专利与管理体系认证的优质品牌耐高温/防火耐热/防腐/纳米介孔微珠中空粒子保温涂料公司推荐
  • 实战练习:小软件页面间跳转传值 子页面数据渲染
  • 2025年云南独立成团游公司权威推荐榜单:云南旅游团/云南私享之旅/云南专属行程游源头公司精选
  • 2025 年气凝胶生产厂家最新推荐排行榜:含气凝胶毡 / 粉 / 隔热板 / 保温罩 / 陶瓷板品牌,优质厂家推荐
  • 2025年5.5KW工业吸尘器厂家权威推荐榜单:380V防爆吸尘器/7.5KW工业吸尘器/水浴式吸尘器源头厂家精选
  • 2025 年兰州凯文中学推荐:兰州凯文中学,二十载深耕民办教育 双师赋能全维育人 以低进高出成效书写成长答卷
  • 详细介绍:Uvicorn - Python ASGI Web 服务器
  • OpenEuler 22.03 手动升级 OpenSSH 至 10.2p1 完整方案
  • 配置GOPRIVATE引用私有仓库
  • 2025年3d全息投影生产厂家权威推荐榜单:全息投影展厅/全息投影沙盘/全息投影源头厂家精选
  • github克隆别人的项目并创建环境安装子模块 - 教程
  • JMeter Plugin Manager Linux 插件安装命令行