读书笔记 · 约 18,405 字 · 预计推送 2 部分

《Algorithms to Live By》选读精读:任务调度 · 信息过载 · 最优停止的可执行启发 未开始

目录

题记与说明

阅读方式与来源(本次实际检索与精读清单)

网络可用。以下 6 个来源于本次会话逐一抓取并通读:

#来源用途
1Walter Teng: Algorithms to Live By — Book Summary(2022-12-23)逐章摘要,Optimal Stopping / Caching / Scheduling / Bayes 等章细节与引文最全
2Allison Chen: Algorithms to Live By(读书会笔记)(2020-08-31)逐章要点 + 批评视角(LRU 图书馆的 exploration 损失)
3Wikipedia: Algorithms to Live By书目事实与书评(Kirkus、Berkeley Science Review)
4官网 algorithmstoliveby.com出版方官方简介、媒体评价、作者介绍
5Wikipedia: Secretary problem最优停止的数学内核:1/e 规则推导、变体、实验心理学证据、历史考证
6Wikipedia: Single-machine scheduling + Wikipedia: Cache replacement policy验证书中调度算法(EDD/SPT/WSPT/Moore-Hodgson)与缓存算法(Bélády/LRU)的学术最优性结论
7Insight Books: Algorithms to Live By(Key Insights)主题化综合:37% 变体阈值、Gittins/UCB、bufferbloat、计算善意

抓取失败/不可用的来源(如实记录):

证据等级说明:本书原文页码未逐条核对;笔记中的“原文引述”均来自上述来源的逐字文本,并标注出处;个别凭既有知识补充的书内案例(如 Mars Pathfinder)显式标注为“凭既有知识,本次未复核”。


一、核心问题

出版方简介的开篇即全书问题陈述(官网逐字):

"What should we do, or leave undone, in a day or a lifetime? How much messiness should we accept? What balance of the new and familiar is the most fulfilling? These may seem like uniquely human quandaries, but they are not. Computers, like us, confront limited space and time, so computer scientists have been grappling with similar problems for decades. And the solutions they've found have much to teach us."(官网)

即:人在有限时间、有限注意、有限空间下如何决策与安排——这在数学上与计算机的资源受限问题同构。本书把 12 类经典计算问题逐一映射到生活(章节结构:Optimal Stopping, Explore/Exploit, Sorting, Caching, Scheduling, Bayes' Rule, Overfitting, Relaxation, Randomness, Networking, Game Theory, Computational Kindness,见 Teng 摘要目录)。

本次选读聚焦其中三块:

  1. 最优停止(Ch.1 Optimal Stopping):序列到来的候选只能“要么当场定、要么永远错过”,何时从“看”切换到“跳”?
  2. 任务调度(Ch.5 Scheduling):单处理器(= 你自己)上任务不断到达,先做哪件、何时切换、何时拒收?
  3. 信息过载(Ch.3 Sorting / Ch.4 Caching / Ch.2 Explore-Exploit / Ch.6-7 辅助):空间与注意力有限时,存什么、扔什么、整理到什么程度、忘掉什么?

Walter Teng 对全书挑战的概括:管理 "finite space, finite time, limited attention, unknown unknowns, incomplete information, and an unforeseeable future"(Teng)。


二、主要主张(三大主题逐章精读 + 可执行启发)

2.1 最优停止:Look-Then-Leap 与 37% 规则

问题模型(Wikipedia: Secretary problem 的标准表述):n 个候选随机顺序逐一出现,看完必须立刻决定、拒绝不可撤回,只能比较“相对名次”,目标是选中唯一最佳者的概率最大化。

书中的核心算法(Teng 摘要逐字):

"Apply the 37% Rule and Look-Then-Leap Rule. Gather data and explore your options for the first 37% in which you categorically don't choose anyone, no matter how impressive, then make a decision (leap) as soon as you find an option better than the first 37%."(Teng)

数学依据(Wikipedia 词条):观察期占比 x 时,选中全局最佳的概率 P(x) = −x·ln(x),在 x = 1/e 处取极大值;最优截止点趋于 n/e,成功率收敛于 1/e ≈ 0.368。词条原文:

"The optimal stopping rule prescribes always rejecting the first ~n/e applicants that are interviewed and then stopping at the first applicant who is better than every applicant interviewed so far."

关键洞见(Teng 的 3 人例子,精彩且可复述):第一个候选“无信息”(永远显得最好),最后一个候选“无选择权”(只能被动接受)——37% 正是信息与选择权的最优点。

可执行启发:

场景规则出处
候选总数/总时长已知(招聘、选房、约会池)前 37% 只看不承诺(Look),之后遇到“史上最佳”立刻出手(Leap)Teng;Wikipedia(1/e 推导)
候选数未知、按时间到来(卖房、找停车位、观察窗口期)把时间的 1/e 段设为观察期(1/e-law of best choice,Bruss 1984:无论 N 多少成功率下界仍是 1/e)Wikipedia: Secretary problem
有客观分数/分布先验(满信息情形,如考试成绩可查)放弃“史上最佳”标准,改用阈值规则:过既定百分位就收Teng("Threshold Rule")
要的不是唯一最佳而是期望值(谈判、卖房)设保留价阈值,低于一律拒、高于立即成交;搜索越久阈值应越低(等待有成本)Teng(house-selling 段)
要“尽量好”而非“最好”(基数收益版)观察期缩至 √n 左右(Bearden 2006;比经典版早出手得多)Wikipedia: Secretary problem(Cardinal payoff variant)
可以回头反悔(被拒后 50% 概率仍可得)观察期拉长到约 61%Insight Books Idea 2("when you can recall the best past candidate but half your offers get turned down, optimal exploration rises to about 61%")
可能被对方拒绝反向操作:更早、更频繁出手Teng("Be prepared to propose early and often in case of rejection.")

反人性警告(书引实验,转引 Teng):

"Most people acted in a way that was consistent with the Look-Then-Leap Rule, but they leapt sooner than they should have more than four-fifths of the time. … Fight your urge to commit quickly whenever possible."

Wikipedia 的实验心理学综述独立印证:"This work has shown that people tend to stop searching too soon"(Experimental studies 节,援引 Seale & Rapoport 1997、Stein, Seale & Rapoport 2003)。

2.2 任务调度:先选度量,再选算法

主张:一切排程争论的根源是没先说清优化目标。 Allison Chen 的概括:"Before deciding on a schedule, you need a goal or metric to measure its effectiveness by!"(Chen)

单机调度的四个“教科书级最优解”(书 Ch.5 内容,最优性均经 Wikipedia: Single-machine scheduling 验证):

你的度量最优算法学术确认
最小化最大迟到 L_max(“拖不得”)EDD(Earliest Due Date,按截止日期升序做)"1‖L_max can be solved optimally by the Earliest Due Date First rule (EDD)"
最小化完成时间总和 ΣC_j(“尽快清空待办”)SPT(Shortest Processing Time,先做最快的)"solved optimally by the Shortest Processing Time First rule (SPT)"
最小化加权完成时间 Σw_jC_jWSPT(按 权重/时长 比 w_j/p_j 降序)"scheduled by ascending order of the ratio p_j/w_j"
最小化迟到件数 ΣU_j(“少死几个项目”)Moore-Hodgson 算法"solved optimally by the Hodgson-Moore algorithm"

可执行启发:

  1. 静态任务用 EDD:Teng:"if you're concerned with minimising maximum lateness, the best strategy is to start with the task due soonest."
  2. 任务不断插队时用抢占式 EDD:Teng:"the optimal strategy for minimising maximum lateness is still the preemptive version of the Earliest Due Date — switching to the job that just came up if it's due sooner than the one you're currently doing and otherwise ignoring it." 注意切换有成本。
  3. 被小任务淹没时用 SPT:先扫掉耗时短的,最大化“完成件数”的体感;但 Chen 点破其阴暗面:"Procrastination is really a great solution to meet the 'wrong' metric"——拖延正是 SPT 在错误度量上的最优表现。
  4. 重要且快的先做(WSPT):权重÷时长比排序(Insight Books:"high weight/short duration first")。
  5. 有依赖关系从后往前排:Teng:"look only at the tasks that no other tasks depend on, and put the one with the latest due date at the end of the schedule."(即 Lawler 算法的思路;注意带一般优先约束的加权版是强 NP-hard,别指望完美日程)
  6. 警惕优先级反转:低优任务占着高优任务需要的资源。解法是优先级继承:Teng:"Suppose a low-priority task is blocking a high-priority task. In that case, the low-priority task inherits the priority of the blocked task."(书内的经典案例是 1997 年火星探路者号的重启事故——凭既有知识补充,本次在线来源未复核此细节。)
  7. 识别 thrashing 并立即减载:Teng 的杂耍比喻——杂耍者接不住第 n+1 个球时,“他不是掉一个球,而是掉掉一切”。Chen:"too much interruption leads to thrashing where *nothing* gets done." 书内建议(凭既有知识):系统开始抖动的第一反应是主动少做,学会说不,保护注意力。Chen 还有一句调度观:"see your schedule as a guess, not a plan."
  8. 中断合并(interrupt coalescing):Teng:"If you have five credit card bills, for instance, don't pay them as they arrive; take care of them all in one go when the fifth bill comes." Chen 给的生活版:"Mitigate this by coalescing your interruptions (ex: office hours!)"
  9. 控制队列长度(bufferbloat 教训):Insight Books 对 Ch.10 的转述:"oversized queues—overcommitment—inflate waiting time. Minimize latency by keeping buffers small, signaling problems early."(超载的缓冲区让一切变慢;过载时先缩队列,不是加带宽。)

2.3 信息过载:缓存、遗忘与“不整理的自由”

主张:信息过载的正确解法不是“记住更多”,而是像缓存一样分层、按 LRU 驱逐、并放弃不必要的排序。

  1. 建立缓存层级。Teng:"Your office or wardrobe works like caches in the computer… your wardrobe is one cache level, your basement another, and a self-storage locker a third." Chen 的版本:"Our nightstand is a cache for our dresser is a cache for our closet is a cache for…"
  2. 按使用频率就近摆放,而不是按“整齐”。Chen:"put things where we'd use them, not necessarily where is 'neat'"——甚至自嘲"That pile of clothes on my desk chair is just me being efficient and caching them :)"
  3. LRU 是无需预知未来的最佳实用驱逐策略。Teng:"The best approach is Least Recently Used (LRU). Simply evict the items after a certain time if they are no longer used." 理论锚点(Wikipedia: Cache replacement policy):理论最优是 Bélády 算法(驱逐“未来最久不会再用”的项),但 "Since it is generally impossible to predict how far in the future information will be needed, this is unfeasible in practice";LRU 需要记录使用时间、开销大,实际系统(如 2017 版 Linux 页缓存)用 LRU 的近似(Clock/Clock-Pro 混合)。
  4. 排序要节制。Teng 引书中的章末结论:"Sorting something you will never search for is a complete waste; searching for something you never sorted is inefficient." 且排序有规模不经济(O(n log n) 陡增),"Computer scientists are more interested in the worst-case analysis… Worst-case analysis lets us make hard guarantees"。
  5. 遗忘是驱逐,不是故障。Chen 转述书对老年记忆的重新解读:"It's not necessarily that memory degrades over time, but the amount of information increases without an increase in computational resources… of course performance will decrease!" Teng:"The problem with the human brain might be not one of storage but of organisation."——检索变慢 ≠ 存储坏了。
  6. 用探索/利用配比消化选项爆炸。关键参数是时间视野:Teng:"It ultimately depends on something we still need to discuss: how long you plan to be in the casino."(即将离开一座城的人该去熟悉的馆子。)策略工具:Win-Stay/Lose-Shift(Robins 1952)、UCB("optimism in the face of uncertainty",选置信区间上界最高的选项)、遗憾最小化。书的诊断:"People tend to over-explore—to favour the new disproportionately over the best."(Teng)
  7. 保护先验(信息过载对判断力的腐蚀)。Teng 引书:"You need to protect your priors to make good predictions." 证据:凶杀率 1990 年代下降 20% 的同时,美国电视新闻中的枪支暴力内容增加了 600%。预测工具箱:Laplace 律 (w+1)/(n+2)、哥白尼原理(无信息先验:Google 还能撑到约 2032)、按分布选规则——幂律→乘法规则,正态→平均值规则,Erlang→加法规则(Teng;Chen)。
  8. 对抗“思考过载”(overfitting):Teng:"The greater the uncertainty, the more significant the gap between what you can measure and what matters, and the more you should watch out for overfitting—the more you prefer simplicity and the earlier you should stop."(交叉验证 + 惩罚复杂度 + 奥卡姆剃刀。)
  9. 计算善意(信息过载的社交解法):开放式提问是把计算负担转嫁给对方。Chen:"give them some proposals that they can *verify* whether or not they're free instead of having to find times on their own."(Insight Books 的转述:"Offering two specific meeting times is algorithmically superior to saying 'whenever works.'")Teng 引书:"You are transferring the computational burden to them."

Chen 的重要反向提醒(局限预告):把图书馆“里外翻转”(热门书全放门口)在 LRU 度量上最优,但 "it increases everyone's exploitation and decreases the exploration"——推荐系统把最像你最近用过的东西排到前面,同样是 LRU 式的信息茧房。


三、方法

作者的论证方法是问题同构 + 最优性保证,而非生产格言汇编:

  1. 映射:把一类生活决策翻译成形式化的计算问题类(秘书问题、多臂老虎机、单机调度、缓存替换、贝叶斯推断……);
  2. 取用该问题类中被证明最优(或带最坏情况保证)的算法——EDD/SPT/Moore-Hodgson 在单机调度中的最优性、1/e 规则的推导、Bélády/LRU 在缓存理论中的地位,均可上溯到学术文献(本次通过 Wikipedia 的 Single-machine scheduling、Cache replacement policy、Secretary problem 词条验证了三条主线的定理表述);
  3. 用 CS 的评价语言重新定义“好决策”:最坏情况分析、竞争比、遗憾最小化——"Computer scientists are more interested in the worst-case analysis than the single best or average performance"(Teng 转述 Ch.3);
  4. 变体敏感:同一个问题,允许反悔、可能被拒、有先验信息,最优阈值都会变(37% ↔ 61% ↔ √n ↔ 阈值规则),书中逐一给出;
  5. 跨学科写作:Christian 提供案例与叙事,Griffiths 提供认知科学背书(其本人与 Tenenbaum 的"Optimal Predictions in Everyday Cognition"研究是 Bayes 章的学术底座,Insight Books 提到 "Research by Griffiths and Tenenbaum finds that people's intuitions are often implicitly Bayesian when experience furnishes priors")。

四、数据与证据

  1. 数学推导:P(x) = −x·ln(x),x=1/e 处最优;成功率表(n=3 → 0.500;n=10 → 0.399;n→∞ → 0.368)(Wikipedia: Secretary problem,含完整推导与 n=1..10 表)。
  2. 行为实验:实验心理学/行为运营研究的一致发现——"people tend to stop searching too soon"(同上,Experimental studies 节);书转引 Rapoport 系实验:4/5 以上的试验中人们过早承诺(转引 Teng);fMRI 研究定位了“决定停止搜集信息”的神经基础(Costa & Averbeck 2013,转引同上)。
  3. 调度定理:EDD、SPT、WSPT、Moore-Hodgson 的最优性均为运筹学标准结论;带优先约束的加权完成时间版本为强 NP-hard(Wikipedia: Single-machine scheduling)。
  4. 缓存理论:Bélády 算法是理论最优但需"clairvoyant"(预知未来);流式数据会让 LRU 缓存污染(cache pollution);2017 Linux 页缓存采用 LRU+Clock-Pro 混合(Wikipedia: Cache replacement policy)。
  5. 媒体偏差数字:美国凶杀率 1990s 下降 20%,电视新闻枪支暴力内容 +600%(书内数据,转引 Teng)。
  6. 历史考证:秘书问题可溯至 Flood 1949("fiancée problem")、Gardner 1960 年 2 月《Scientific American》的 "game of googol";开普勒 1611–1613 年间用类似序列策略在 11 位候选人中择偶(Ferguson 1989《Who Solved the Secretary Problem?》考证,转引 Wikipedia)。
  7. 社会接受度:Kirkus:"An entertaining, intelligently presented book for the numerate and computer literate."(转引 Wikipedia 书目页);《卫报》:"computing algorithms could be a surprisingly useful way to embrace the messy compromises of real, non-Vulcan life."(转引官网)

五、结论与效果

  1. 三大启发可以压缩成三句话:
    • 最优停止:先用 37% 的时间/名额免费校准,之后见到更好的就别再等——且要对抗“过早承诺”的本能(大多数人在 80% 的实验里跳早了)。
    • 任务调度:先声明你要优化什么(最大迟到→EDD;完成件数→SPT;加权产出→权重/时长比;少死项目→Moore-Hodgson),然后机械执行;负载超过吞吐量时,减载比加速重要。
    • 信息过载:像缓存一样生活——分层放置、LRU 驱逐、忘掉是功能、只整理会再搜索的东西;并且用“计算善意”替别人的注意力减负。
  2. 过程与结果分离(Teng 引书):"If you followed the best possible process, you've done all you can, and you shouldn't blame yourself if things didn't go your way." 1/e ≈ 36.8% 意味着即使最优策略也大概率错过最佳——它的价值在于给出可辩护的下界。
  3. "sometimes 'good enough' really is good enough."(Teng 引书收尾);《卫报》评价其说服力恰在于此:"Not because I endorse the idea of living like some hyper-rational Vulcan, but because computing algorithms could be a surprisingly useful way to embrace the messy compromises of real, non-Vulcan life."

六、局限

  1. 模型假设强:经典秘书问题要求 n 已知、只能比相对名次、拒绝不可撤回。Wikipedia 明确指出:n 未知时"the optimal success probability is now no longer around 1/e but typically lower… Depending on the choice of the distribution of N, the optimal win probability can approach zero"。37% 是理想模型的数字,不是普适常数。
  2. 度量不可测则算法落空:EDD 需要可信的截止时间,SPT 需要可信的耗时估计——生活的困难常在估时/估重本身。
  3. “单机”假设:人不是单队列处理器,多目标、情绪、协作皆未建模。Chen 的批评有代表性:LRU 最优的社会(里外翻转的图书馆、Discover Weekly)以牺牲 exploration/偶遇为代价。
  4. 部分论证是类比而非实证:如“人脑=缓存层级”“老年=检索变慢”是有启发性的隐喻,不是严格神经科学结论。
  5. 36.8% 的心理落差:书里也承认(Teng 转述)计算机科学"can't offer you a life with no regret",只能"minimal regret"——追求“选中最佳”的框架本身就该被阈值/期望值变体替换。
  6. 本次精读的局限(如实):基于 6 个在线二手来源 + 百科,未逐页核对原书页码;paulminors 摘要 404;Zotero 未运行未能交叉检索个人书库;Mars Pathfinder 案例等个别书内细节凭既有知识补充并已标注。

七、对我的启发

结合我的工作场景(Agent 开发、笔记系统、自动化工作流、信息流管理):

  1. Agent/工作流的任务编排直接套用 Ch.5:给 agent 的待办队列显式声明度量再选策略——通知/轻修复类用 SPT 批量扫,deadline 驱动的作业用 EDD,中断合并(interrupt coalescing)正是“消息攒批处理”的形式化名称;thrashing 的征兆(切上下文开销 > 有效产出)应当写进 agent 的自监控指标。
  2. 记忆系统 = 缓存层级:工作记忆/会话摘要/长期笔记库的三级结构对应 CPU 缓存→内存→磁盘;驱逐策略用 LRU(+ 频率修正,ARC 思路),并且理直气壮地删——“遗忘是驱逐,不是故障”。我的笔记库里“不再会搜索的条目不值得精排”可以省下大量整理时间。
  3. 评估与调参用 Overfitting 章:不确定性越大、代理指标与真实目标差距越大,越要早停、越要简单启发式——这直接约束我在 RAG/agent 调优中“别用单一 benchmark 过拟合”。
  4. 序列决策留出 37% 观察期:选型、招人、租房、接活——先划出明确的“只看不承诺”窗口(哪怕缩短到时间维度的 1/e),再跳;满信息场景(有可查数据)改用阈值规则。写进决策模板而不是靠临场感觉。
  5. 先验防护作为信息卫生:新闻/时间线的偏差会系统性污染贝叶斯先验(-20% vs +600% 的案例),值得在信息摄入侧设计“代表性与采样”机制。
  6. 计算善意作为默认沟通协议:给具体提案(两个时间、两个方案)而非开放问题;这既是礼貌也是把对方的搜索复杂度从 O(n) 降到 O(1)。
  7. 方法论迁移:这套“问题同构 + 最优性保证”的写法本身值得模仿——把模糊的生活问题先形式化,再借用有证明的结论,比发明私人格言可靠得多。

附:可执行启发速查卡

最优停止
├─ 默认:37% 只看 → 首个“史上最佳”立刻出手(成功率上限 ~36.8%)
├─ 候选数未知 → 按时间的 1/e 划观察期
├─ 满信息/要期望值 → 阈值规则;要“尽量好” → 观察期缩至 √n
├─ 可反悔 → 观察期拉长(~61%);会被拒 → 更早更频繁出手
└─ 反本能:多数人跳太早(>4/5 试验)——守住观察期

任务调度(先选度量!)
├─ 最小化最大迟到 → EDD(截止升序);任务会插队 → 抢占式 EDD
├─ 尽快清空 → SPT(先做最快的);加权 → 权重/时长比
├─ 少死几个项目 → Moore-Hodgson
├─ 有依赖 → 从后往前排(Lawler)
├─ 低优卡高优 → 优先级继承
├─ 开始抖动(thrashing) → 第一反应是减载/说不,不是加速
└─ 中断合并:邮件/账单/消息攒批,固定时段处理

信息过载
├─ 分层缓存:常用物放最近的“缓存级”
├─ 按 LRU 驱逐:久未用 → 降级/丢弃(忘记=驱逐=功能)
├─ 只整理会再搜索的东西;排序有规模不经济
├─ 选项爆炸 → 按时间视野配探索/利用;UCB 乐观尝试
├─ 保护先验:媒体过表征罕见灾难,别拿时间线当世界样本
├─ 不确定性越大 → 越早停止思考(防过拟合)
└─ 计算善意:给具体选项,别把搜索负担转给别人

引述与来源汇总

逐字引述(英文,按文中出现顺序)

来源链接(均为本次会话实际抓取)

  1. https://walterteng.com/algorithms-to-live-by
  2. https://allisonchen.us/algorithms_to_live_by
  3. https://en.wikipedia.org/wiki/Algorithms_to_Live_By
  4. https://algorithmstoliveby.com/
  5. https://en.wikipedia.org/wiki/Secretary_problem
  6. https://en.wikipedia.org/wiki/Single-machine_scheduling
  7. https://en.wikipedia.org/wiki/Cache_replacement_policy
  8. https://insightbooks.app/books/algorithms-to-live-by

*笔记结束。未改动本目录其他条目笔记、matrix.csv、backlog 或 nightly-log.md。*

← 资料库今日播报 →