附录B 习题答案附录B 习题答案逐项覆盖权威目录,以公式、轨迹、交互实验和失败对照重建深度强化学习证据链。为什么先冻结环境、轨迹与参数版本 、、、、、共同构成本页坐标。把习题答案改造成可检查的解题协议:先列已知与目标,再给推导、数值或程序证据,最后用反例检验边界。 阅读时把环境状态、采样数据、学习目标、优化参数和评价策略分成五份账。每一条转移至少保存状态、动作、奖励、下一状态、终止与截断标记、行为概率和采集时的参数版本;每一次更新保存目标值、损失、梯度范数、更新前后参数摘要和随机种子。这样才能判断改进来自正确算法,而不是信息泄漏、状态污染或评价仍在学习。 数学骨架 answer=claim+derivation+evidence\text{answer}=\text{claim}+\text{derivation}+\text{evidence}answer=claim+derivation+evidence residual=computed−expected\text{residual}=\text{computed}-\text{expected}residual=computed−expected relerr=∣x−x^∣max(1,∣x∣,∣x^∣)\operatorname{relerr}=\frac{|x-\hat x|}{\max(1,|x|,|\hat x|)}relerr=max(1,∣x∣,∣x^∣)∣x−x^∣ pass ⟺ residual within tolerance and boundary tests pass\text{pass}\iff\text{residual within tolerance and boundary tests pass}pass⟺residual within tolerance and boundary tests pass 公式必须落实为shape与版本合同。奖励是标量,动作可以是离散索引或连续向量,终止转移的未来项固定为零;行为策略负责产生数据,目标策略负责定义学习目标,在线参数与冻结参数不能靠变量名猜测。先用一个两状态、两动作或两智能体样例手算,再运行批量训练。 最小实现骨架 def record_transition(env, policy, observation): action, logp, policy_version = policy.sample(observation) next_observation, reward, terminated, truncated, info = env.step(action) return { "observation": observation, "action": action, "reward": float(reward), "next_observation": next_observation, "terminated": bool(terminated), "truncated": bool(truncated), "behavior_logp": float(logp), "policy_version": policy_version, } def one_step_target(transition, bootstrap_value, gamma): future = 0.0 if transition["terminated"] else bootstrap_value return transition["reward"] + gamma * future def audit_update(before, target, loss, gradient, after): assert target.isfinite().all() assert loss.isfinite().all() assert gradient.isfinite().all() return {"before": before.digest(), "target": target.detach(), "grad_norm": gradient.norm(), "after": after.digest()} 这三段代码不替代具体算法,而是固定共同边界:环境只产生事实,目标函数只读取冻结转移,优化器只在审计通过后更新。章节中的DQN、SARSA、策略梯度、A3C、MADDPG或MCTS都必须映射回这套生命周期。 常见失败与回退 本章回顾 把习题答案改造成可检查的解题协议:先列已知与目标,再给推导、数值或程序证据,最后用反例检验边界。 最终掌握标准不是复述算法名,而是能说明每个量来自哪里、由哪版策略产生、在哪个边界归零、如何手算,以及故障样本应在哪一步被发现。通过标准是:每题答案能够脱离原运行独立重算,公式符号、策略版本、随机种子和终止条件齐全,不以截图或最终分数代替过程。 前后导航 附录A 贝尔曼方程 《深度强化学习》全书总复习 复习本章(6 题)← 上一章附录A 贝尔曼方程讨论评论区加载中…