<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[My world]]></title><description><![CDATA[Hi~]]></description><link>https://www.coder-nova.com</link><image><url>https://www.coder-nova.com/innei.svg</url><title>My world</title><link>https://www.coder-nova.com</link></image><generator>Shiro (https://github.com/Innei/Shiro)</generator><lastBuildDate>Sun, 10 May 2026 13:09:18 GMT</lastBuildDate><atom:link href="https://www.coder-nova.com/feed" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 May 2026 13:09:17 GMT</pubDate><language><![CDATA[zh-CN]]></language><item><title><![CDATA[[投资学习笔记] 阻力位与箱体]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/invest/resistance_level">https://www.coder-nova.com/posts/invest/resistance_level</a></blockquote><div><p>起因是SBG在回踩的时候卖飞了，经过反思后觉得有必要来学习一下如何判断阻力位以及箱体。</p><hr/><h3 id="--resistance-level">一、 阻力位 (Resistance Level)</h3><p>阻力位可以说是股价上涨的“天花板”。在这个价位附近，卖方的力量开始超过买方的力量，导致股价停止上涨，甚至可能掉头下跌。</p><h4 id="-">(一) 如何确定阻力位？</h4><ol start="1"><li><strong>前期高点 (Previous Highs)</strong>：在K线图上，过去明显的波段高点或历史最高点，是天然的阻力位。</li><li><strong>移动平均线 (Moving Averages, MA)</strong>：在下降趋势中，重要的均线（如MA20, MA60, MA120）会成为股价反弹的动态阻力。</li><li><strong>下降趋势线 (Downtrend Line)</strong>：连接两个或多个依次降低的高点，形成的斜线会对后续反弹形成压制。</li><li><strong>斐波那契回撤 (Fibonacci Retracement)</strong>：在一轮下跌后，反弹至38.2%, 50%, 61.8%等关键位置时，通常会遇到阻力。</li><li><strong>整数关口/心理价位 (Psychological Levels)</strong>：如 ¥10, ¥50, ¥100 等整数价位。</li></ol><h4 id="-">(二) 原因分析</h4><ul><li><p><strong>前期高点</strong>：这是最经典的心理博弈区，主要有三股卖出力量汇集于此。</p><ol start="1"><li><strong>解套盘</strong>：在前期高点买入的投资者，股价下跌后一直被套牢。当股价终于回升到他们的成本价附近时，会急于卖出回本。这构成了第一批坚决的卖压。</li><li><strong>获利盘</strong>：在底部或上涨中途买入的投资者，看到股价接近了前一个高峰，会认为这是一个阶段性的顶部。出于锁定利润的心理，他们会选择在此卖出。</li><li><strong>做空力量</strong>：看空市场的投资者会认为前期高点是一个经过市场验证的天花板，在此位置建立空头头寸的风险收益比较高，他们的卖出行为进一步加强了阻力。</li></ol></li><li><p><strong>移动平均线 (MA)</strong>：</p><ul><li><strong>平均成本的“心理锚”</strong>：移动平均线代表了过去一段时间内所有交易者的平均持仓成本。在下降趋势中，当股价反弹至重要的长期均线（如60日线、120日线）时，意味着价格接近了这段时间内的平均成本。大量在此期间买入的被套投资者终于等到了解套机会，便会集中卖出，形成强大阻力。</li></ul></li><li><p><strong>整数关口/心理价位</strong>：</p><ul><li><strong>人类对“整数”的偏好</strong>：人们在设定目标时，天然倾向于使用简单好记的整数，如10元、50元、100元。无论是机构还是散户，他们的挂单、止盈目标价位也常常集中在这些整数关口，导致订单的密集，从而形成事实上的阻力。当然，中国交易者难免会出现6或8的偏好。</li></ul></li></ul><h4 id="-">(三) 阻力位突破判断技巧</h4><p><strong>1. 成交量与阻力强弱</strong>
成交量是判断力量强弱的核心指标，验证阻力位和突破有效性的试金石。</p><ul><li><strong>放量突破的可靠性</strong>：突破阻力位时，如果成交量显著放大，说明有大量资金愿意在更高价位买入，买方力量充足，突破更容易成立，是强烈的看涨信号。
  <ul><li><strong>术语解释：放量 (Volume Spike)</strong> <ul><li>指成交量远超近期平均水平。通常以突破日的成交量达到前5个交易日平均成交量的1.5倍或以上，作为参考标准。</li></ul></li></ul></li><li><strong>缩量遇阻回落</strong>：当股价接近阻力位但成交量萎缩，表明市场追涨意愿不足，缺乏向上攻击的能量，此时很容易因卖盘的出现而冲高回落。</li></ul><p><strong>2. 多周期共振</strong>
不同时间周期的图表相互验证，可以大幅提高阻力位的可靠性。</p><ul><li><strong>日线 + 周线 + 月线</strong>：如果在日线图上看到的阻力位，恰好也是周线图或月线图上的一个重要历史高点，那么这个阻力位的级别就非常高，突破难度极大，一旦突破，意义也更重大。
  <ul><li><strong>术语解释：多周期共振 (Multi-Timeframe Resonance)</strong> <ul><li>指在不同的时间周期图表上（如日线、周线、月线），出现了指向同一结论的技术信号（如多个周期同时出现阻力）。这种共振信号的可靠性远高于单一周期的信号。</li></ul></li></ul></li><li><strong>均线与水平阻力重叠</strong>：例如，60日均线（MA60）恰好运行到前期高点的水平位置附近，形成“双重阻力”，这里的压力会非常强。</li></ul><p><strong>3. K线形态确认</strong>
单日的K线形态可以提供关于阻力位附近多空博弈的宝贵信息。</p><ul><li><strong>长上影线</strong>：股价在盘中一度突破阻力位，但收盘时又被打回阻力位下方，形成一根带有长长上影线的K线。这说明上方卖压沉重，多头攻击失败，阻力位被有效验证。
  <ul><li><strong>术语解释：K线 (Candlestick)</strong> <ul><li>又称蜡烛图，通过图形记录每个交易日的开盘价、收盘价、最高价和最低价。上影线代表了当天最高价与收盘价（或开盘价）之间的差距。</li></ul></li></ul></li><li><strong>连续小阳线冲击阻力</strong>：股价以温和的小阳线形式，一步步逼近阻力位。这说明买方在持续试探，但如果连续多日都无法有效放量突破，说明攻击力度有限，耐心耗尽后可能引发空头的快速反扑。</li></ul><p><strong>4. 动态阻力判断</strong>
除了固定的水平线和趋势线，还有一些指标可以提供动态变化的阻力参考。</p><ul><li><strong>布林带上轨</strong>：在震荡行情中，布林带（Bollinger Bands）的通道上轨线常常对股价形成短期动态阻力。
  <ul><li><strong>术语解释：布林带 (Bollinger Bands, BOLL)</strong> <ul><li>一种由移动平均线和统计学中的标准差概念组成的路径指标。它由上、中、下三条轨道线组成，股价通常在上下轨之间波动。</li></ul></li></ul></li><li><strong>趋势线转折</strong>：支撑与阻力可以相互转化。例如，一条长期压制股价的下降趋势线一旦被成功突破，当股价后续回调至这条线附近时，原来的阻力线就会变成支撑线。</li></ul><hr/><h3 id="--trading-range--box">二、 箱体 (Trading Range / Box)</h3><p>箱体理论是指股价在一段时间内，在由阻力位（箱顶）和支撑位（箱底）构成的价格区间内反复波动。</p><h4 id="-">(一) 如何识别箱体？</h4><ol start="1"><li><strong>识别价格区间</strong>：找到一段股价横盘整理的时期。</li><li><strong>确定箱顶（阻力）</strong>：连接该区域内至少两个大致相同的高点，画出水平上轨。</li><li><strong>确定箱底（支撑）</strong>：连接该区域内至少两个大致相同的低点，画出水平下轨。</li></ol><h4 id="-">(二) 箱体优化技巧</h4><p><strong>1. 箱体形态识别优化</strong></p><ul><li><strong>宽幅 vs. 窄幅箱体</strong>：
  <ul><li><strong>宽幅箱体</strong>：箱顶与箱底之间价差较大（如超过15%-20%）。波动空间大，适合在箱体内进行高抛低吸的波段操作。</li><li><strong>窄幅箱体</strong>：价差很小，K线紧密排列。这通常意味着多空力量高度均衡，市场在等待一个明确的信号。一旦突破，能量释放会更猛烈，往往伴随加速的大幅行情。</li></ul></li><li><strong>假突破识别</strong>：这是箱体交易中最需要防范的陷阱。
  <ul><li><strong>向上假突破 (Bull Trap)</strong>：股价在某天放量突破箱顶，但无法持续，在1-3个交易日内又快速跌回箱体内部，甚至伴随着更大的成交量下跌。这是诱多陷阱。</li><li><strong>向下假跌破 (Bear Trap)</strong>：股价跌破箱底，看似趋势转坏，但很快被强力拉回箱体内部，并伴随成交量放大。这是诱空陷阱，往往是洗盘吸筹的行为。</li></ul></li></ul><p><strong>2. 箱体内的交易量变化</strong></p><ul><li><strong>量价齐升</strong>：当价格从箱底反弹，向箱顶运行时，如果成交量也呈现温和放大的态势，说明有资金在积极推动，增加了未来成功突破箱顶的可能性。</li><li><strong>量能递减</strong>：当价格在箱体内反复震荡，但整体成交量却呈现越来越小的趋势。这表明市场交投清淡，多空双方的观望情绪浓厚，浮动筹码被逐渐锁定。这可能是暴风雨前的宁静，意味着突破的时机越来越近。</li></ul><p><strong>3. 多周期箱体叠加</strong>
从小周期服从大周期的原则出发，观察不同周期图上的箱体。</p><ul><li>一个日线级别的小箱体，可能只是周线级别一个大箱体内部的一次小幅震荡。大周期箱体的突破（如周线级别的突破），往往会带来更长久、更强劲的趋势性行情。</li></ul><p><strong>4. 突破后的加速规律</strong></p><ul><li><strong>回踩确认 (Pullback)</strong>：一个健康、可靠的突破，往往不是一去不回头。股价在向上突破箱顶后，上涨一段距离，然后会有一个缩量的回调动作，回踩到原箱顶（此时已从阻力变为支撑）附近，得到支撑后再继续上攻。这个“回踩确认”的过程可能是绝佳的二次买入或加仓点。</li></ul><hr/><h3 id="-">三、 综合判断</h3><p><strong>1. 配合震荡指标</strong>
使用RSI、MACD等震荡指标来辅助判断突破的风险。</p><ul><li>当股价即将或刚刚突破阻力位时，如果RSI指标已经显示高于70的超买状态，或者MACD指标与股价走势形成顶背离，那么即使突破了，也要警惕短期内因动能衰竭而引发回调的风险。
  <ul><li><strong>术语解释：RSI (相对强弱指数)</strong> <ul><li>衡量股价近期涨跌动能的指标，通常高于70被视为超买区，低于30为超卖区。</li></ul></li><li><strong>术语解释：MACD 顶背离 (Bearish Divergence)</strong> <ul><li>指股价创出新高，但MACD指标的对应高点却未能创出新高（甚至在降低）。这是典型的动能衰竭信号，预示上涨趋势可能即将反转。</li></ul></li></ul></li></ul><p><strong>2. 事件驱动</strong>
技术分析并非万能，需要结合基本面信息。</p><ul><li>当股价运行到关键阻力位或箱体突破前夕，如果恰逢公司发布财报、行业出现重大利好/利空政策等重大事件，这些事件驱动的强大力量可能会让原有的技术形态瞬间失效。</li></ul><p><strong>3. 心理预期与市场情绪</strong></p><ul><li><strong>热门题材股</strong>的阻力位突破，往往伴随着市场的高度关注和情绪化资金的爆发性推动，有时会以连续涨停等极端方式完成，不一定有“回踩”过程。</li><li><strong>冷门股或绩优白马股</strong>的突破，则更多依赖于主力资金的稳健布局，走势通常更符合技术规范，例如会清晰地看到放量突破和缩量回踩。</li></ul><hr/><h3 id="">四、如何识别假突破</h3><h4 id="-">(一) 突破前的信号</h4><p>在股价尚未突破阻力位，但正在不断接近它时，一些先行指标可能已经发出了警告。</p><p><strong>1. 量价背离 (Volume-Price Divergence) - 最重要的先行指标</strong></p><ul><li><strong>现象</strong>：股价在不断创出新高（或接近前期高点），但对应的成交量却一波比一波低，呈现萎缩状态。</li><li><strong>解读</strong>：这说明推动价格上涨的动能（资金）正在衰竭。价格的上涨更像是一种惯性，缺乏新增资金的认可。这种“无量上涨”是空虚的，一旦在阻力位遇到抛压，很容易崩溃。</li></ul><p><strong>2. 指标顶背离 (Indicator Bearish Divergence)</strong></p><ul><li><strong>现象</strong>：股价创出新高，但常用的动量指标（如MACD、RSI）的对应高点却未能创出新高，反而走低。</li><li><strong>解读</strong>：这表明虽然价格表面上很强势，但其内在的上涨动能已经减弱，上涨趋势随时可能反转。价格和指标走势不一致，是趋势即将衰竭的信号。</li></ul><p><strong>3. K线形态乏力</strong></p><ul><li><strong>现象</strong>：在冲击阻力位的过程中，K线实体越来越短，上影线却越来越长，或者频繁出现十字星。</li><li><strong>解读</strong>：长上影线和十字星都代表了在该价位多空分歧巨大，买方虽然努力上攻，但被卖方成功压制。这说明阻力位的抛压非常真实且有效，买方的攻击已经显现出疲态。</li></ul><h4 id="-">(二) 突破的验证方法</h4><p><strong>1. 突破必须放量</strong></p><ul><li><strong>真突破</strong>：一个健康、可信的突破，<strong>必须伴随成交量的显著放大</strong>（通常是20日均量的1.5倍以上）。</li><li><strong>假突破</strong>：如果突破阻力位当天的成交量与前几日相比没有明显放大，甚至是缩量的，那么这是最典型的假突破特征。</li><li><strong>原因分析</strong>：突破阻力位意味着要消化所有在该位置等待解套和获利的卖盘，这需要巨大的资金来承接。没有成交量的放出，说明市场主力资金根本没有参与，或者参与意愿不强。</li></ul><p><strong>2. K线实体强度</strong></p><ul><li><strong>真突破</strong>：突破当天通常会收出一根<strong>大阳线</strong>，且收盘价要明显高于阻力线（比如高于3%以上），显示出买方压倒性的决心。</li><li><strong>假突破</strong>：突破当天收出的是一根小阳线，或者带有长上影线的阳线（即使收盘价在阻力位之上）。这表明突破过程非常勉强，在盘中遭到了强大阻击，买方优势微弱。</li></ul><h4 id="-">(三) 突破后的确认技巧</h4><p><strong>1. “三日原则”与快速回落</strong></p><ul><li><strong>真突破</strong>：股价在突破阻力位后，通常能<strong>连续2-3个交易日稳定地收盘在原阻力位之上</strong>。</li><li><strong>假突破</strong>：最常见的特征是在突破后的<strong>下一个交易日</strong>，股价就立即大幅低开或盘中跳水，收盘时又跌回到了阻力位下方。</li></ul><p><strong>2. 回踩形态的性质</strong></p><ul><li><strong>真突破后的回踩</strong>：健康的回踩是<strong>缩量的</strong>，股价跌到原阻力位附近时会明显获得支撑，然后止跌企稳，再度上涨。此时，原阻力位成功转换为支撑位。</li><li><strong>假突破的回落</strong>：回落是<strong>放量的</strong>，股价会毫不费力地直接击穿原阻力位，根本没有任何支撑作用。这表明市场完全不认可突破的有效性，恐慌盘正在涌出。</li></ul></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/invest/resistance_level#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/invest/resistance_level</link><guid isPermaLink="true">https://www.coder-nova.com/posts/invest/resistance_level</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Fri, 15 Aug 2025 06:23:56 GMT</pubDate></item><item><title><![CDATA[[中文笔记] Convex Optimization for Neural Networks]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/convex_optimization_nn">https://www.coder-nova.com/posts/ai/convex_optimization_nn</a></blockquote><div><p><a href="https://web.stanford.edu/class/ee364b/lectures/convexNN.pdf">课件地址（Stanford EE364B：Convex Optimization for Neural Networks）</a></p><p><a href="https://web.stanford.edu/~boyd/cvxbook/bv_cvxslides.pdf">预备知识 (凸函数相关)</a></p><h2 id="-relu-">核心问题：如何将两层 ReLU 网络的非凸问题转为凸问题求解？</h2><h3 id=""><strong>完整的推导路线图</strong></h3><ol start="1"><li><strong>非凸的 L2 正则化网络</strong> ↓ <em>(变量缩放)</em></li><li><strong>等价的 L1 路径范数问题</strong> ↓ <em>(权重规范化)</em></li><li><strong>无限字典的 LASSO 问题</strong> ↓ <em>(凸对偶)</em></li><li><strong>半无限规划 (SIP)</strong> ↓ <em>(超平面排列)</em></li><li><strong>有限维的凸对偶问题 (QCQP)</strong> ↓ <em>(再次求对偶)</em></li><li><strong>最终的、可解的组 LASSO 问题</strong></li></ol><blockquote><p>通过这个转换来理解“神经网络是凸正则化器”。它通过一个巧妙的变量缩放技巧，将一个看似复杂的 L2 正则化项，变成了一个形式更简单、更利于后续对偶分析的 L1 正则化项。</p></blockquote>
<hr/><h3 id="">问题设定</h3><p><strong>场景设定</strong></p><ul><li><strong>模型</strong>: 两层全连接 ReLU 网络。</li><li><strong>损失函数</strong>: 平方损失。</li><li><strong>正则化</strong>: 标准的 L2 权重衰减 (Weight Decay)。</li></ul><p>我们的初始优化问题是：</p><p>$$
\min<em>{W_1, W_2} \frac{1}{2} \left| \sum</em>{j=1}^{m} \sigma(Xw<em>{1j})w</em>{2j} - y \right|<em>2^2 + \lambda \left( \sum</em>{j=1}^{m} |w<em>{1j}|_2^2 + \sum</em>{j=1}^{m} |w_{2j}|^2 \right)
$$</p><p>其中，$W<em>1$ 是第一层权重矩阵（$w</em>{1j}$ 是其第 j 列），$w<em>2$ 是第二层权重向量（$w</em>{2j}$ 是其第 j 个标量元素）。这是一个关于 $W_1$ 和 $W_2$ 的非凸问题。</p><hr/><h3 id="-the-scaling-trick">第一步：变量缩放 (The Scaling Trick)</h3><p>对于单个隐层神经元 j，我们可以对其权重对 $(w<em>{1j}, w</em>{2j})$ 进行缩放，而不改变网络的最终输出。</p><h4 id="11-">1.1. 定义缩放变换</h4><p>为每个隐神经元 $j$ 引入一个缩放因子 $\alpha_j &gt; 0$。定义新的权重为：</p><p>$$
\tilde{w}<em>{1j} = \frac{w</em>{1j}}{\alpha<em>j}, \quad \tilde{w}</em>{2j} = w_{2j}\alpha_j
$$</p><h4 id="12-">1.2. 为什么网络输出不变？</h4><p>这一步依赖于 ReLU 函数 $\sigma(t) = \max(0, t)$ 的正齐次性 (Positive Homogeneity)，即 $\sigma(c \cdot t) = c \cdot \sigma(t)$ 对任何 $c \ge 0$ 成立。</p><p>因此，对任意一个神经元 $j$，其对最终输出的贡献为：</p><p>$$
\sigma(X\tilde{w}<em>{1j})\tilde{w}</em>{2j} = \sigma\left(X\frac{w<em>{1j}}{\alpha_j}\right)(w</em>{2j}\alpha<em>j) = \frac{1}{\alpha_j}\sigma(Xw</em>{1j})(\alpha<em>j w</em>{2j}) = \sigma(Xw<em>{1j})w</em>{2j}
$$</p><p>由于 $\alpha<em>j &gt; 0$，$1/\alpha_j$ 可以被提出来。可以看到，经过缩放后的新权重 $(\tilde{w}</em>{1j}, \tilde{w}<em>{2j})$ 产生的输出与原权重完全相同。因此，总模型的输出 $\sum \sigma(\cdot)w</em>{2j}$ 和损失函数 $|\dots - y|^2$ 的值也保持不变。</p><h4 id="13-">1.3. 正则化项如何变化？</h4><p>虽然损失项不变，但正则化项会随着 $\alpha<em>j$ 的变化而改变。对于神经元 $j$，其正则化惩罚从 $|w</em>{1j}|<em>2^2 + |w</em>{2j}|^2$ 变为：</p><p>$$
\text{Penalty}<em>j(\alpha_j) = \left| \frac{w</em>{1j}}{\alpha<em>j} \right|_2^2 + |w</em>{2j}\alpha<em>j|^2 = \frac{1}{\alpha_j^2}|w</em>{1j}|<em>2^2 + \alpha_j^2|w</em>{2j}|^2
$$</p><h4 id="14-">1.4. 寻找最优缩放</h4><p>对于一组固定的 $(w<em>{1j}, w</em>{2j})$，我们可以通过选择最优的 $\alpha_j$ 来最小化这个惩罚项。我们将 $\text{Penalty}_j(\alpha_j)$ 看作是关于 $\alpha_j$ 的函数，求其最小值：</p><p>令其导数为零：</p><p>$$
\frac{d}{d\alpha<em>j}\text{Penalty}_j(\alpha_j) = -\frac{2}{\alpha_j^3}|w</em>{1j}|<em>2^2 + 2\alpha_j|w</em>{2j}|^2 = 0
$$</p><p>解得最优的 $\alpha_j^*$ 满足：</p><p>$$
(\alpha<em>j^*)^4 = \frac{|w</em>{1j}|<em>2^2}{|w</em>{2j}|^2} \quad \implies \quad (\alpha<em>j^*)^2 = \frac{|w</em>{1j}|<em>2}{|w</em>{2j}|}
$$</p><p>将最优的 $(\alpha_j^*)^2$ 代回惩罚项，得到最小惩罚值为：</p><p>$$
\min<em>{\alpha_j &gt; 0} \text{Penalty}_j(\alpha_j) = \frac{|w</em>{2j}|}{|w<em>{1j}|_2}|w</em>{1j}|<em>2^2 + \frac{|w</em>{1j}|<em>2}{|w</em>{2j}|}|w<em>{2j}|^2 = |w</em>{1j}|<em>2|w</em>{2j}| + |w<em>{1j}|_2|w</em>{2j}| = 2|w<em>{1j}|_2|w</em>{2j}|
$$</p><h4 id="15--l2--l1-">1.5. 结论：从 L2 到 L1 路径范数</h4><p>这个结果表明，对于任意给定的权重 $(W<em>1, W_2)$，总能找到一组缩放因子 ${\alpha_j}$，使得网络输出不变，但正则化项取得其可能的最小值 $\sum 2\lambda|w</em>{1j}|<em>2|w</em>{2j}|$。</p><p>因此，原始的、带有 L2 权重衰减的优化问题，等价于下面这个新的优化问题：</p><p>$$
\min<em>{W_1, W_2} \frac{1}{2} \left| \sum</em>{j=1}^{m} \sigma(Xw<em>{1j})w</em>{2j} - y \right|<em>2^2 + 2\lambda \sum</em>{j=1}^{m} |w<em>{1j}|_2|w</em>{2j}|
$$</p><p>这个新的正则化项 $\sum |w<em>{1j}|_2|w</em>{2j}|$ 被称为<strong>路径范数 (Path-Norm)</strong>。它形似 L1 范数，因为它惩罚的是绝对值的和，这为后续的稀疏性分析和对偶变换奠定了基础。我们成功地将 L2 正则化“搬运”并转化为了一个结构更清晰的 L1 型正则化。</p><hr/><h3 id="-lasso-">第二步：权重规范化与 LASSO 形式</h3><p>为了使问题形式更加标准，我们进一步对权重进行分解。</p><h4 id="21-">2.1. 再次重参数化</h4><p>对于每个 $j$，定义：</p><ul><li><strong>方向</strong>: $u<em>j = w</em>{1j} / |w_{1j}|_2$，这是一个单位向量，$|u_j|_2 = 1$。</li><li><strong>系数</strong>: $c<em>j = w</em>{2j} |w_{1j}|_2$。</li></ul><h4 id="22-">2.2. 代入模型</h4><p>网络的输出可以重写为：</p><p>$$
\sigma(Xw<em>{1j})w</em>{2j} = \sigma(X(|w<em>{1j}|_2 u_j))w</em>{2j} = |w<em>{1j}|_2\sigma(Xu_j)w</em>{2j} = \sigma(Xu<em>j)(w</em>{2j}|w_{1j}|_2) = \sigma(Xu_j)c_j
$$</p><p>而路径范数正则项则变成了对新系数 $c_j$ 的 L1 惩罚：</p><p>$$
2\lambda \sum<em>{j} |w</em>{1j}|<em>2 |w</em>{2j}| = 2\lambda \sum<em>{j} |w</em>{2j} |w<em>{1j}|_2| = 2\lambda \sum</em>{j} |c_j|
$$</p><h4 id="23--lasso-">2.3. 等价的 LASSO 问题</h4><p>吸收常数 2 到 $\lambda$ 中，我们得到了一个在形式上非常接近 LASSO (L1 正则化回归) 的问题：</p><p>$$
\min<em>{|u_j|_2=1, c_j \in \mathbb{R}} \frac{1}{2} \left| \sum</em>{j=1}^{m} \sigma(Xu<em>j)c_j - y \right|_2^2 + \lambda \sum</em>{j=1}^{m} |c_j|
$$</p><p>这个问题要求我们在所有可能的“特征”（由单位向量 $u_j$ 生成的 $\sigma(Xu_j)$）中，寻找一个稀疏的线性组合来拟合 $y$。这正是后续进行凸对偶分析的出发点。</p><h3 id="-sip">第三步：推导凸对偶，得到半无限规划 (SIP)</h3><p>我们已经将原问题等价地表示为一个在“特征” $\sigma(Xu_j)$ 上的稀疏回归问题。这里的“特征”是由第一层单位范数权重 $u_j$ 生成的。因为 $u_j$ 可以在单位球面上任意取值，所以我们实际上是在一个无限的特征字典里进行选择。</p><p>这一步的目标是推导出这个问题的<strong>凸对偶 (Convex Dual)</strong>形式。</p><h4 id="31-">3.1. 定义问题和字典</h4><p>我们的问题是：</p><p>$$
\min_{|u_j|_2=1, c_j} \frac{1}{2} \left| \sum_j \sigma(Xu_j)c_j - y \right|_2^2 + \lambda \sum_j |c_j|
$$</p><p>为了进行分析，我们首先将这个问题看作一个两阶段的过程：</p><ol start="1"><li>先从无限的特征集合 $\Phi = {\sigma(Xu) \mid |u|_2=1}$ 中，选择一个有限的子集（即字典）$\mathcal{A} = [\sigma(Xu_1), \sigma(Xu_2), \dots] = [\phi_1, \phi_2, \dots]$。</li><li><p>然后在这个固定的字典 $\mathcal{A}$ 上求解标准的 LASSO 问题：</p><p>$$
\min_{c} \frac{1}{2}|\mathcal{A}c - y|_2^2 + \lambda|c|_1
$$</p></li></ol><h4 id="32--lasso-">3.2. 固定字典下的标准 LASSO 对偶</h4><p>现在，我们对这个固定字典 $\mathcal{A}$ 的 LASSO 问题求其对偶。</p><ul><li><p><strong>引入对偶变量</strong>: 我们引入对偶变量 $v \in \mathbb{R}^n$（n 是样本数）。利用 Fenchel 共轭，二次损失项可以写作：</p><p>  $$
  \frac{1}{2}|\mathcal{A}c - y|<em>2^2 = \max</em>{v \in \mathbb{R}^n} \left( v^\top(\mathcal{A}c) - \frac{1}{2}|v-y|_2^2 + \frac{1}{2}|y|_2^2 \right)
  $$</p><p>  <em>(注：$\frac{1}{2}|y|_2^2$ 是常数，为简化通常先省略，最后加回。课件中的 $-\frac{1}{2}|v-y|_2^2$ 是一个等价的、更简洁的表达)。</em></p></li><li><p><strong>交换 min 和 max</strong>: 将上式代入原问题，得到一个 min-max 问题。由于原问题是凸的，强对偶性成立，我们可以交换 min 和 max 的顺序：</p><p>  $$
  \max<em>{v} \min</em>{c} \left( v^\top(\mathcal{A}c) + \lambda|c|_1 - \frac{1}{2}|v-y|_2^2 + \frac{1}{2}|y|_2^2 \right)
  $$</p></li><li><p><strong>求解内部 min</strong>: 我们关注内部对 $c$ 的最小化部分：</p><p>  $$
  \min_{c} \left( (\mathcal{A}^\top v)^\top c + \lambda|c|_1 \right)
  $$</p><p>  这是 L1 范数的共轭函数。其解为：</p><p>  $$
  \begin{cases}
  0, &amp; \text{if } |\mathcal{A}^\top v|_\infty \le \lambda \
  -\infty, &amp; \text{otherwise}
  \end{cases}
  $$</p><p>  其中 $|\mathcal{A}^\top v|_\infty \le \lambda$ 等价于对字典的每一列 $\phi_j$ 都有 $|v^\top\phi_j| \le \lambda$。当这个条件不满足时，我们可以让 $c$ 的某些元素朝 $-(\mathcal{A}^\top v)$ 的方向无限增大，使得值为 $-\infty$。</p></li><li><p><strong>得到对偶问题</strong>: 将这个结果代回 max 问题，$-\infty$ 的情况可以忽略，我们只关心值为 0 的情况，即约束 $|\mathcal{A}^\top v|_\infty \le \lambda$ 必须满足。因此，固定字典 $\mathcal{A}$ 下的对偶问题是：</p><p>  $$
  \begin{aligned}
  \max<em>{v} \quad &amp; -\frac{1}{2}|v-y|_2^2 + \frac{1}{2}|y|_2^2 \
  \text{s.t.} \quad &amp; |\mathcal{A}^\top v|</em>\infty \le \lambda
  \end{aligned}
  $$</p><p>  <em>(目标函数等价于最小化 $|v-y|_2^2$)</em></p></li></ul><h4 id="33-">3.3. 从固定字典回到无限字典</h4><p>现在，我们回到原始设定，即字典 $\mathcal{A}$ 并非固定的，而是包含了所有由单位向量 $u$ 生成的特征 $\sigma(Xu)$。</p><p>对偶问题的约束 $|\mathcal{A}^\top v|_\infty \le \lambda$，即 $|v^\top\phi| \le \lambda$，必须对字典中的每一列 $\phi$ 都成立。为了让这个对偶问题成为原问题的一个有效下界（并且由于强对偶性，是一个紧密的下界），这个约束必须对整个无限特征集 $\Phi$ 都成立。</p><p>因此，我们将约束替换为：</p><p>$$
|v^\top\sigma(Xu)| \le \lambda, \quad \text{对所有满足 } |u|_2=1 \text{ 的 } u \text{ 成立。}
$$</p><h4 id="34--semi-infinite-program-sip">3.4. 最终的半无限规划 (Semi-Infinite Program, SIP)</h4><p>将这个无限约束代入，我们得到了最终的对偶问题，它是一个<strong>半无限规划</strong>：</p><p>$$
\begin{aligned}
\max_{v \in \mathbb{R}^n} \quad &amp; -\frac{1}{2}|v-y|_2^2 \
\text{s.t.} \quad &amp; |v^\top\sigma(Xu)| \le \lambda, \quad \forall u \in \mathbb{R}^d, |u|_2=1
\end{aligned}
$$</p><p>这个规划被称为半无限，因为它的优化变量 $v$ 是有限维的（$v \in \mathbb{R}^n$），但它却拥有无限约束（每个单位向量 $u$ 都对应一条约束）。</p><h3 id="--sip-">第四步：将无限约束转化为有限约束 (从 SIP 到可解问题)</h3><p>我们在第三步得到的半无限规划 (SIP) 是一个理论上优美的结果，但它包含无限约束，无法直接用算法求解。这一步的目的是展示如何将这无限条约束转化为有限。</p><h4 id="41--sip-">4.1. 回顾 SIP 和其挑战</h4><p>到这里，我们的问题是：</p><p>$$
\begin{aligned}
\max_{v \in \mathbb{R}^n} \quad &amp; -\frac{1}{2}|v-y|_2^2 \
\text{s.t.} \quad &amp; |v^\top\sigma(Xu)| \le \lambda, \quad \forall u \in \mathbb{R}^d, |u|_2=1
\end{aligned}
$$</p><p>挑战在于约束条件 $|v^\top\sigma(Xu)| \le \lambda$ 必须对单位球面 $|u|_2=1$ 上无穷无尽的向量 <code>u</code> 都成立。</p><h4 id="42--hyperplane-arrangement">4.2. 超平面排列 (Hyperplane Arrangement)</h4><p>这里的核心思想是：函数 $\sigma(Xu)$ 虽然依赖于连续变化的 <code>u</code>，但其“形状”只有有限多种。</p><ul><li><strong>ReLU 的分段线性特性</strong>: $\sigma(z) = \max(0, z)$ 是一个分段线性函数。因此，$\sigma(Xu)$ 也是一个关于 <code>u</code> 的分段线性函数。</li><li><strong>符号模式 (Sign Pattern)</strong>: 函数 $\sigma(Xu)$ 的具体形式取决于向量 $Xu$ 中每个元素 $x_i^\top u$ 的正负号。</li><li><strong>超平面</strong>: 在 d 维的权重空间中，每个方程 $x_i^\top u = 0$ (对于样本 i=1,...,n) 都定义了一个穿过原点的超平面。</li><li><strong>区域划分</strong>: 这 n 个超平面将整个 $\mathbb{R}^d$ 空间划分成了有限个多面体区域 (Polyhedral Regions)。</li><li><strong>关键结论</strong>: 在任何一个特定的区域 k 内部，所有向量 <code>u</code> 产生的 $Xu$ 都具有完全相同的符号模式。</li></ul><h4 id="43-">4.3. 用对角矩阵表示符号模式</h4><p>对于每个区域 k，我们可以用一个 n×n 的对角矩阵 $D<em>k$ 来表示其对应的符号模式。$D_k$ 的对角线元素 $(D_k)</em>{ii}$ 为：</p><p>$$
(D<em>k)</em>{ii} =
\begin{cases}
1, &amp; \text{如果在该区域内 } x_i^\top u &gt; 0 \
0, &amp; \text{如果在该区域内 } x_i^\top u \le 0
\end{cases}
$$</p><p>利用这个矩阵，只要 <code>u</code> 位于区域 <code>k</code>，我们就可以将非线性的 $\sigma(Xu)$ 精确地写成线性形式：</p><p>$$
\sigma(Xu) = D_k X u
$$</p><h4 id="44-">4.4. 分解无限约束</h4><p>现在，我们可以将原始的无限约束分解到每个区域上。</p><p>$$
\sup_{|u|_2=1} |v^\top \sigma(Xu)| \le \lambda
$$</p><p>等价于</p><p>$$
\max<em>{k=1, \dots, p} \left( \sup</em>{u \in \text{Region}_k, |u|_2=1} |v^\top \sigma(Xu)| \right) \le \lambda
$$</p><p>其中 <code>p</code> 是区域的总数（有限个）。将 $\sigma(Xu) = D_kXu$ 代入，上式变为：</p><p>$$
\max<em>{k=1, \dots, p} \left( \sup</em>{u \in \text{Region}_k, |u|_2=1} |v^\top D_k X u| \right) \le \lambda
$$</p><p>由于 $|v^\top D_k X u|$ 是 <code>u</code> 的线性函数（的绝对值），其在单位球上的最大值一定在整个球面上取到，而不仅仅是在某个区域的交集上。所以我们可以简化并得到一组有限的约束：</p><p>$$
\sup_{|u|_2=1} |v^\top D_k X u| \le \lambda, \quad \text{对每个模式 } k=1, \dots, p
$$</p><p>根据对偶范数的定义，$\sup_{|u|_2=1} |z^\top u| = |z|_2$。因此，每条约束都变成了：</p><p>$$
|(v^\top D_k X)^\top|_2 \le \lambda \quad \iff \quad |X^\top D_k v|_2 \le \lambda
$$</p><h4 id="45-">4.5. 等价的有限维对偶问题</h4><p>我们将 SIP 中的无限约束替换为这 <code>p</code> 条有限的凸约束，得到一个标准的、可求解的凸优化问题（这是一个二次约束二次规划 QCQP）：</p><p>$$
\begin{aligned}
\max_{v \in \mathbb{R}^n} &amp; \quad -\frac{1}{2}|v-y|_2^2 \
\text{s.t.} &amp; \quad |X^\top D_k v|_2 \le \lambda, \quad \text{for } k=1, \dots, p
\end{aligned}
$$</p><h4 id="46--primal--group-lasso">4.6. 恢复最终的、可解释的 Primal 问题 (Group LASSO)</h4><p>虽然上述对偶问题已经可解，但为了得到更具解释性的形式，我们对它再次求对偶，从而得到原问题的<strong>最终 primal 形式</strong>。得到一个<strong>组稀疏 (Group LASSO)</strong> 回归问题：</p><p>$$
\min<em>{Z_1, \dots, Z_p \in \mathbb{R}^d} \frac{1}{2} \left| \sum</em>{k=1}^p D<em>k X Z_k - y \right|_2^2 + \lambda \sum</em>{k=1}^p |Z_k|_2
$$</p><ul><li><strong>变量</strong>: <code>Z_k</code> 是一个 <code>d</code> 维向量，与第 <code>k</code> 个激活模式相关联。</li><li><strong>模型</strong>: 模型将最终的输出 <code>y</code> 表达为来自不同激活模式的贡献 <code>D_kXZ_k</code> 的线性组合。</li><li><strong>正则化</strong>: $\lambda \sum |Z_k|_2$ 是组 L1/L2 范数。它会鼓励<strong>整个向量 <code>Z_k</code> 同时为零</strong>。</li><li><strong>解释</strong>: 这个模型通过选择少数几个（稀疏的）重要的激活模式（那些 $Z_k \neq 0$ 的模式）来拟合数据。</li></ul><hr/><h3 id="">总结</h3><p>至此，我们证明了，一个经典的两层 ReLU 网络的训练问题，尽管其原始形式是非凸的，但它与一个标准的、可以高效求解的凸优化问题（组 LASSO）完全等价。这就证明了核心论点：<strong>神经网络可以被看作是凸正则化器</strong>。从最终的组 LASSO 解中，可以恢复出原非凸网络的最优权重 $W_1^<em>$ 和 $W_2^</em>$。</p><hr/><h3 id="ps--w1j2--1-">p.s. 在课件中将变换为 $|W_{1j}|_2 = 1$ 的理由</h3><p>这其实就是把第一层吸收到第二层系数里，而不影响网络输出，也不改变正则项的结构。</p><h4 id="1-">1. 缩放不改变输出</h4><p>ReLU 满足正齐次性：</p><p>$$
\sigma(c,t) = c,\sigma(t), \quad c \ge 0
$$</p><p>所以如果我们把 $W<em>{1j}$ 放大 $k&gt;0$ 倍，并同时把 $W</em>{2j}$ 缩小 $k$ 倍：</p><p>$$
\sigma(X (k W<em>{1j})) \cdot \frac{W</em>{2j}}{k} = k,\sigma(X W<em>{1j}) \cdot \frac{W</em>{2j}}{k} = \sigma(X W<em>{1j}) W</em>{2j}
$$</p><p>网络输出完全不变。</p><h4 id="2-">2. 在最优缩放下，正则项是</h4><p>经过 $\alpha_j$ 优化，我们已经得出最优正则是：</p><p>$$
\lambda \sum<em>{j} 2|W</em>{1j}|<em>2 , |W</em>{2j}|
$$</p><p>（常数 2 可以并进 $\lambda$ 里）</p><h4 id="3-">3. 吸收长度到第二层</h4><p>上面的正则是第一层长度 × 第二层绝对值的乘积。
既然输出只依赖两者的乘积，我们完全可以把第一层长度定为 1，然后把它的值乘到第二层系数上去：</p><p>令：</p><p>$$
u<em>j = \frac{W</em>{1j}}{|W_{1j}|_2} \quad (|u_j|_2 = 1),
$$</p><p>$$
c<em>j = \text{sign}(W</em>{2j}) \cdot |W<em>{1j}|_2 |W</em>{2j}| \quad (= W<em>{2j} |W</em>{1j}|_2)
$$</p><p>这样：</p><ul><li><p><strong>输出</strong>：</p><p>  $$
  \sigma(X W<em>{1j}) W</em>{2j} = \sigma\big(X(|W<em>{1j}|_2 u_j)\big),\frac{c_j}{|W</em>{1j}|_2} = \sigma(X u_j), c_j
  $$</p></li><li><p><strong>正则项</strong>：</p><p>  $$
  |W<em>{1j}|_2 , |W</em>{2j}| = |c_j|
  $$</p></li></ul><p>因为 $|u_j|_2=1$ 已固定，所以只剩下对 $c_j$ 的 L1 正则。</p></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/convex_optimization_nn#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/convex_optimization_nn</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/convex_optimization_nn</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Tue, 12 Aug 2025 15:04:59 GMT</pubDate></item><item><title><![CDATA[[投资学习笔记] 推文分析学习：解读美国国债收益率曲线信号]]></title><description><![CDATA[<link rel="preload" as="image" href="https://pbs.twimg.com/media/Gxwfk-mbAAAUHjE?format=jpg&amp;name=large"/><div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/invest/daily_treasury_par_yield_curve_rates">https://www.coder-nova.com/posts/invest/daily_treasury_par_yield_curve_rates</a></blockquote><div><blockquote><p><strong>核心结论</strong>：当前收益率曲线的多个结构表明，市场正在强烈预期未来的降息，经济“硬着陆”风险显著上升。投资者已开始抢跑交易政策拐点。</p></blockquote>
<hr/><h3 id="">参考图表与数据来源</h3><ul><li><p><strong>官方数据来源</strong>: 可以在美国财政部官网上查看每日更新的收益率曲线数据。</p><ul><li><strong>链接</strong>: <a href="https://home.treasury.gov/policy-issues/financing-the-government/interest-rate-statistics">U.S. DEPARTMENT OF THE TREASURY - Daily Treasury Par Yield Curve Rates</a></li></ul></li><li><p><strong>示例</strong>:
  <img src="https://pbs.twimg.com/media/Gxwfk-mbAAAUHjE?format=jpg&amp;name=large" alt="美国国债收益率曲线示例 2025-08-07"/></p><p>  来源: <a href="https://x.com/corsica267/status/1953471063666594235">https://x.com/corsica267/status/1953471063666594235</a></p></li></ul><hr/><h3 id="-">一、 收益率曲线逐条解析</h3><p><strong>1. 1M–6M：流动性未吃紧</strong></p><ul><li><strong>现象</strong>：1个月至6个月的短端收益率曲线平坦，无异常陡峭。</li><li><strong>解读</strong>：短期融资市场资金充裕，没有出现流动性危机（“钱荒”）的迹象。</li></ul><p><strong>2. 1Y–3Y：倒挂 → 强降息预期</strong></p><ul><li><strong>现象</strong>：1年期国债收益率高于3年期。</li><li><strong>解读</strong>：市场认为短期利率偏高，但未来必然会下行。这是押注美联储将 <strong>大幅降息</strong> 的明确信号。</li></ul><p><strong>3. 2Y vs. 联邦基金利率：衰退前兆</strong></p><ul><li><strong>现象</strong>：2年期国债收益率比联邦基金利率（FFR）下限低超过100个基点（bp）。</li><li><strong>解读</strong>：这是一个强烈的历史信号，通常发生在 <strong>经济衰退前3–9个月</strong>，反映市场对未来降息的极高确定性。</li></ul><p><strong>4. 3Y–10Y：熊陡 → 长期通胀预期</strong></p><ul><li><strong>现象</strong>：曲线呈现 <strong>熊陡（Bear Steepener）</strong>，即短端利率下降，但长端利率下降更慢甚至上升。</li><li><strong>解读</strong>：市场预期短期经济会下行（迫使联储降息），但 <strong>长期通胀压力依然存在</strong>，可能源于财政赤字或供应链等结构性问题。</li></ul><p><strong>5. 30Y–20Y：小幅正斜率 → 久期与供给风险</strong></p><ul><li><strong>现象</strong>：30年期利率仅略高于20年期。</li><li><strong>解读</strong>：超长期债券面临 <strong>久期风险</strong>（对利率波动敏感）和 <strong>供给压力</strong>（财政部发债）。同时也侧面反映了衰退预期，否则利差会更阔。</li></ul><p><strong>6. 10Y–2Y：倒挂大幅回正 → 经济见顶信号</strong></p><ul><li><strong>现象</strong>：经典的<code>10Y-2Y</code>利差从深度倒挂状态迅速回归正值。</li><li><strong>解读</strong>：历史（如2000年、2007年）表明，这种 <strong>快速正常化</strong> 往往是经济周期触顶、衰退即将来临的标志。</li></ul><p><strong>7. 3M–10Y：轻微倒挂 → 放水前的衰退交易</strong></p><ul><li><strong>现象</strong>：3个月收益率略高于10年期收益率。</li><li><strong>解读</strong>：这是另一个经典的衰退先行指标。市场开始提前布局 <strong>“放水”（降息）前的衰退交易</strong>，如买入长期债券。</li></ul><p><strong>8. 总体：硬着陆风险上升</strong></p><ul><li><strong>综合判断</strong>：多个利差结构发出经济降温信号，但长端的通胀预期并未完全消失。如果政策应对不够平滑，经济很可能走向 <strong>硬着陆</strong>（即衰退伴随失业率急剧上升）。</li></ul><hr/><h3 id="-">二、 对市场的含义</h3><p><strong>1. 市场抢政策拐点，美元见顶</strong></p><ul><li>投资者正在押注美联储政策将从紧缩转向宽松（降息）。</li><li>美元指数（DXY）可能因此见顶回落，资金或将流向黄金、大宗商品、非美资产等。</li></ul><p><strong>2. 若进入衰退，2Y–10Y利差将再度陡峭</strong></p><ul><li>经济衰退一旦确认，央行会快速降息，导致短端利率（2Y）下降速度远快于长端（10Y）。</li><li>这将导致 <code>2Y-10Y</code> 收益率曲线进一步 <strong>陡峭化</strong>。</li></ul><p><strong>3. 短期交易策略：逢“弱”做多</strong></p><ul><li>在9月/10月的重要时间窗口前，市场情绪敏感。</li><li>每当有疲软的经济数据公布，市场对降息的预期就会加强，从而推动资金流入 <strong>长期国债（如 TLT）和黄金（如 GLD）</strong>。</li></ul><hr/><h3 id="-">三、 核心逻辑</h3><ul><li><strong>收益率曲线形态</strong> → 暗示经济周期处于 <strong>顶点向下</strong> 的阶段。
  <ul><li><strong>短端倒挂 + 2Y远低于FFR</strong> → 确认 <strong>高确定性的降息预期</strong>。</li><li><strong>长端熊陡</strong> → 确认 <strong>长期通胀预期未死</strong>。</li></ul></li><li><strong>交易含义</strong>：
  <ul><li><strong>中短期</strong>：做多长债 + 黄金，捕捉降息预期。</li><li><strong>中长期</strong>：采取防御姿态，防范衰退风险，减配股票等高风险资产。</li></ul></li></ul></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/invest/daily_treasury_par_yield_curve_rates#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/invest/daily_treasury_par_yield_curve_rates</link><guid isPermaLink="true">https://www.coder-nova.com/posts/invest/daily_treasury_par_yield_curve_rates</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Fri, 08 Aug 2025 03:47:07 GMT</pubDate></item><item><title><![CDATA[[投资学习笔记] 推文分析学习：从银行消费数据看美国经济]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/invest/bank-consumer-spending-us-economy">https://www.coder-nova.com/posts/invest/bank-consumer-spending-us-economy</a></blockquote><div><blockquote><p><strong>核心观点</strong>：美国银行CEO通过观察其内部的消费增速数据，可以对美国整体的通胀和经济增长趋势做出判断。由于消费占美国GDP的大头，银行的消费数据可以视为经济的“温度计”。</p></blockquote>
<h3 id="-">一、 核心逻辑链条</h3><p>美国银行CEO曾表示：“我们看到的消费增速已经回到疫情前，所以通胀增速会放缓。”</p><p>这个判断基于以下推理：</p><ol start="1"><li><strong>消费是经济引擎</strong>：美国约60%的GDP来自于个人消费支出（PCE）。</li><li><strong>银行掌握一手数据</strong>：银行通过信用卡、储蓄账户等业务，能实时掌握最真实的消费数据。因此，银行观察到的消费增速，在很大程度上约等于名义GDP中消费部分的增速。</li><li><strong>增速的构成</strong>：消费增速（名义） = 真实消费增长（实际GDP增长的核心） + 价格上涨（通胀）。</li><li><strong>推导经济状态</strong>：如果整体消费增速固定在某一水平（例如4.5%~5%），那么：
<ul><li>当通胀率超过这个水平时（例如 <code>CPI &gt; 5%</code>），就意味着真实的消费增长必须是负数。</li><li>真实的消费负增长，则预示着 <strong>实际GDP负增长</strong>，即经济衰退。</li></ul></li></ol><h3 id="-">二、 关键变量</h3><table><thead><tr><th style="text-align:left">项目</th><th style="text-align:left">含义</th><th style="text-align:left">举例</th></tr></thead><tbody><tr><td style="text-align:left"><strong>名义GDP增长</strong></td><td style="text-align:left">未剔除通胀影响的经济增长率。</td><td style="text-align:left">GDP增长了5%</td></tr><tr><td style="text-align:left"><strong>实际GDP增长</strong></td><td style="text-align:left">剔除通胀影响后的、真实的经济增长率。</td><td style="text-align:left">真实经济增长了2%</td></tr><tr><td style="text-align:left"><strong>通胀</strong></td><td style="text-align:left">此处可理解为 <strong>名义增长</strong> 与 <strong>实际增长</strong> 之间的差值。</td><td style="text-align:left">通胀率为3%</td></tr><tr><td style="text-align:left"><strong>银行观察的消费增速</strong></td><td style="text-align:left">包含了 <strong>真实消费增速</strong> 和 <strong>通胀</strong> 的名义数据。</td><td style="text-align:left">银行看到消费额增长5%<br/>（可能=2%真实增长+3%通胀）</td></tr></tbody></table><h3 id="-">三、 逻辑的公式化表示</h3><p>我们可以将这个逻辑简化为一个近似的公式：</p><p>$$\text{实际GDP增速} \approx \text{消费增速（名义）} - \text{通胀率}$$</p><p>基于美国银行CEO观察到的 <strong>4.5% ~ 5%</strong> 的消费增速，我们可以推演出不同的经济情景：</p><ul><li><p><strong>情景A：温和增长</strong></p><ul><li>如果通胀率为 <strong>2.5%</strong></li><li>实际GDP增速 ≈ (4.5% ~ 5%) - 2.5% = <strong>2% ~ 2.5%</strong></li><li>结论：经济处于健康、温和的增长区间。</li></ul></li><li><p><strong>情景B：经济衰退</strong></p><ul><li>如果通胀率为 <strong>5.5%</strong></li><li>实际GDP增速 ≈ (4.5% ~ 5%) - 5.5% = <strong>-1% ~ -0.5%</strong></li><li>结论：经济已进入负增长，即技术性衰退。</li></ul></li></ul><h3 id="-">四、 为什么说银行财报是“经济温度计”？</h3><p>银行的业务使其能敏锐地捕捉到经济活动的细微变化。这些变化最终会反映在财报上。</p><p><strong>银行能看到的领先/同步指标包括：</strong></p><ul><li><strong>信用卡消费</strong>：消费额度是上升还是下降？</li><li><strong>储蓄账户</strong>：居民储蓄是在增加还是在被消耗？</li><li><strong>贷款业务</strong>：消费贷款、企业贷款的申请是放缓还是加速？</li><li><strong>资产质量</strong>：贷款违约率、坏账率是否正在增加？</li></ul><p><strong>因此，我们可以得出结论：</strong></p><ul><li><strong>预警信号</strong> 🚨：当银行财报显示 <strong>消费放缓、储蓄下降、坏账率上升</strong> 时，通常是经济活动已经或即将步入衰退的信号。</li><li><strong>健康信号</strong> ✅：如果银行财报稳健，说明 <strong>居民消费和企业投资依然活跃</strong>，经济离衰退还有距离。</li></ul></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/invest/bank-consumer-spending-us-economy#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/invest/bank-consumer-spending-us-economy</link><guid isPermaLink="true">https://www.coder-nova.com/posts/invest/bank-consumer-spending-us-economy</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Fri, 08 Aug 2025 02:54:00 GMT</pubDate></item><item><title><![CDATA[中文笔记：Software Is Changing (Again) by Andrej Karpathy]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/software_3.0">https://www.coder-nova.com/posts/ai/software_3.0</a></blockquote><div><blockquote><p><strong>序言</strong>：午后听了Andrej Karpathy最新的演讲，大为震撼，于是有了此篇笔记。这里对每个小节做一些整理和思考。这里先说下结论：Markdown才是这时代最好的编程语言！（笑）</p></blockquote>
<p>视频地址：
<div><iframe width="600" height="400" src="https://www.youtube.com/embed/LCEmiRjPEtQ"></iframe></div></p><hr/><h2 id="llms">LLMs是新型计算机</h2><p>在Andrej Karpathy的定义中，软件的变迁分为了三个时代。</p><h3 id="1-software-10-">1. Software 1.0: 传统代码</h3><p>在1.0时代中，软件指的是你为计算机编写的代码。程序由程序员编写，并在计算机上执行。</p><h3 id="2-software-10-">2. Software 1.0: 神经网络</h3><p>由于神经网络的崛起，神经网络中的参数被视为2.0时代中的编程代码。程序员不在需要直接编写这些代码，而是通过调整数据集并运行优化器来创建神经网络的参数。
软件开发从显式编码转向数据驱动和模型训练，并且如Hugging Face平台成为2.0时代的GitHub平台，用于共享和可视化模型参数</p><h3 id="3-software-30-llms">3. Software 3.0: LLMs的时代</h3><p>3.0时代指的便是LLM，因为他们可以直接生成程序。而英语等自然语言就变为了3.0时代的编程代码。比如，可以用少量提示来编程 LLM 进行情感分类，而不是编写Python代码或训练神经网络模型。</p><p>在这一节中Andrej Karpathy以自动驾驶的发展为例，在神经网络崛起（2.0时代）之后，工程师们使用了一些网络模型来替换了传统算法代码（如图像识别任务）。而现在才是3.0时代的开始，今后也将会有大量的软件被重写。</p><p><strong>思考：</strong>
其实这里笔者认为3.0时代发展的最后是需要跳出传统的编程范式的（如使用C++，Python等代码来执行任务），LLM完全有能力直接操作逻辑电路中的0，1来生成程序。大规模数据集以及需要处理的信息量巨大（每个时钟周期数百万到数十亿个位的变化）都将是挑战。</p><hr/><h2 id="llmsutilitiesoperating-systems">LLMs是公用事业（Utilities），操作系统（Operating Systems）？</h2><p>不得不说天才们的脑洞是真的大。这一节中LLM 先被比作公用事业（如电力），这主要基于其提供服务的方式和用户需求。LLM的开发过程类似于建设电网的基础设施，都是由大公司投入大量资本来得到的。然后他们通过<strong>API以按量付费（按token计费)</strong>的方式向用户提供智能服务，这相当于提供电力服务的运营支出。与公用事业服务的典型需求相似，用户对LLM API有很高的要求，包括低延迟、正常运行时间和一致的质量。</p><p>此外，由于存在像OpenRouter这样的工具，允许用户在不同的LLM之间轻松切换，因为LLM不争夺物理空间，因此可以有多个“电力供应商”。LLM的构建由于需要巨大的资本支出，并且技术栈发展迅速，研发秘密高度集中在少数LLM实验室内部，这使得它们也具备了晶圆厂的一些特征。</p><p>此外，LLM不仅仅是像电力或水那样的简单商品，它们正在成为日益复杂的软件生态系统。这里介绍了一种更深层的类比是将其视为新型的操作系统。与操作系统类似，LLM也存在少数闭源提供商（如Windows或Mac OS），以及开源替代方案（如Linux）。LLM本身也可以被视为CPU的等价物，其包含上下文窗口（context window）工作记忆（working memory）或内存。又如VS Code应用程序可以在Windows、Linux或Mac上运行，LLM应用（例如Cursor）可以在不同的LLM上运行。</p><p>LLM当前相当于60年代的计算机时代（云端，数据通过流式传输和批处理进行），首先LLM计算目前仍然非常昂贵，这迫使LLM集中部署在云端。而且用户通过<strong>分时共享（time sharing）</strong>的方式进行访问，而非完全独占其计算资源。个人计算革命尚未在LLM领域发生，因为目前经济上不划算。</p><hr/><h2 id="llm-psychology">LLM psychology</h2><p>LLM被认为是“人类精神”或“人类的随机模拟”。这是因为它们通过在互联网上所有可用的文本进行训练，这些文本源自人类，因此它们展现出一种类似人类的涌现心理 (emergent psychology that is humanlike)。LLM拥有百科全书般的知识和记忆，能够记住比任何个体人类都多得多的信息，可以非常容易地记住SHA哈希等各种信息。</p><p><strong>认知缺陷/局限性:</strong></p><p>-幻觉 (Hallucinations): LLM会频繁地“产生幻觉”并“编造内容”。</p><p>-自我认知不足 (Insufficient self-knowledge): 它们没有一个非常好的或足够强的“内部自我认知模型”。</p><p>-锯齿状智能 (Jagged intelligence): 它们的智能是“锯齿状的”，这意味着它们在某些解决问题的领域可能表现出超人水平，但随后又会犯下“基本上没有人类会犯的错误”，例如坚持“9.11大于9.9”或者“strawberry”中有两个“r”。这些是“你可能会绊倒的粗糙边缘” (rough edges that you can trip on)。</p><p>-顺行性遗忘症 (Anterograde amnesia): LLM似乎也遭受某种类似于顺行性遗忘症的困扰。与人类同事不同，人类会随着时间学习和巩固知识，而LLM“本身不会这样做”。它们的上下文窗口 (context windows) 就像是工作记忆 (working memory)，必须直接对其进行编程，因为它们不会默认变得更聪明。这被比作电影《记忆碎片》(Momento) 和《初恋50次》(51st Dates) 中的主角，他们的“权重是固定的，上下文窗口每天早上都会被清空”。</p><p>-易受骗性与安全风险 (Gullibility and security risks): LLM非常容易上当，并且容易受到提示注入 (prompt injection) 风险的影响。它们还可能泄露你的数据。</p><h2 id="llm">通过LLM来构建部分自动化的产品</h2><hr/><p>这部分的内容可能略显繁杂，但是中心思想是找到当前LLM缺陷/局限性的解决方法。这里最后的比喻是钢铁侠战衣，在面对有缺陷的LLM时，我们应该构建更多的是增强人类能力的工具（augmentation），而不是完全自主的机器人（autonomous robots）。</p><h3 id="1-gui">1. 需要GUI而不是直接通过文本交流</h3><p>直接通过文本与LLM交互，感觉就像通过终端与操作系统对话一样，LLM生成的大量的文本很难阅读、解释和理解，需要通过视觉表示来加速人类验证和审计系统的工作。目前，尚未以通用方式真正发明出适用于LLM的通用GUI，尽管某些LLM应用已经拥有特定的GUI。例如，ChatGPT目前的界面类似于文本气泡，但仍缺乏一个跨所有任务的通用GUI。这里还展示了一波cursor和Perplexity的GUI。例如，cursor中查看代码差异时，红绿色的视觉变化比纯文本更容易理解和操作（接受或拒绝更改）。此外，Tesla的Autopilot仪表盘上的GUI会显示神经网络所看到的内容，这也是GUI的应用实例。</p><p><strong>思考：</strong> 设计师们和可视化的研究者们的新舞台</p><h3 id="2-">2. 生成与验证的循环</h3><p>当前LLM应用中的工作流通常是AI负责生成内容，而人类负责验证。为了提高工作效率，加快AI生成与人类验证之间的循环（generation verification loop）至关重要。有两种主要方式可以做到这一点：1.如前所述，GUI通过视觉表示大大提高了人类审计工作的速度和效率。2.保持AI受控（“驯服AI”）。</p><h3 id="3-ai-keep-ai-on-the-leash">3. 驯服AI (Keep AI on the leash)</h3><p>因为如上面所述的LLM缺陷和局限性，以及AI agents可能会过度反应，生成过大或难以管理的内容（如，一次性生成10,000行代码，这使人类成为瓶颈，难以验证和确保其无错误或安全问题）等问题，所以一个可控的AI是必要的。</p><p><strong>解决方案：</strong></p><p>1.提供更具体、更精确的Prompt</p><p>2.在AI辅助的编程中，分小块、增量地进行工作</p><ol start="3"><li><p>例如在教育领域，可以设计一个教师来创建课程，然后一个学生来使用这些课程。这样，“课程”就成为一个可审计的中间工件，确保AI在特定教学大纲和项目进度下保持受控和一致。</p></li><li><p><strong>自主滑块（Autonomy Slider）</strong>：主要目的是允许用户根据任务的复杂性来调整AI的自主程度。例如，在Cursor中，你可以选择轻量级补全（你主导），修改代码块（特定范围），修改整个文件，或者完全自主地处理整个代码库。</p></li></ol><hr/><h2 id="llm">LLM是新的数字信息消费者</h2><p>Andrej Karpathy发现完全使用LLM进行软件开发的一个问题是，目前的使用文档主要是为人类设计的，例如包含图形用户界面（GUI）的指示和视觉元素，这使得LLM难以直接理解和操作。要让AI Agent理解文档并正确调用API，必须调整现有的结构，使其变得对LLM友好。尽管未来LLM可能能够自行点击网页，但目前而言，主动迎合LLM并使其更容易访问信息仍然非常重要。这里介绍了一些方法和工具：</p><h3 id="1the-llmstxt-file">1.The /llms.txt file：</h3><p>类似于网站用于指导网络爬虫的robots.txt文件，可以创建一个简单的Markdown格式的llm.txt文件。这个文件可以直接向LLM说明域名信息，告诉它们这个领域是关于什么的。相比让LLM解析复杂的HTML页面，这种方式更具可读性，且不易出错。</p><h3 id="2-llm">2. 转换为LLM更易理解的格式：</h3><p>文档中的列表、加粗字体、图片等视觉元素，这些对LLM来说并不直接可访问。需要将这些文档转换为LLM更易理解的格式，例如Markdown。Vercel和Stripe等公司已经开始将他们的文档过渡到专门为LLM设计的格式。</p><h3 id="3-">3. 修改文档中的指令：</h3><p>文档中常见的“点击”等动词对LLM来说是无效的，因为它们无法进行原生点击操作。因此，需要将这些动词替换为LLM代理可以直接执行的命令，例如使用curl命令。这使得文档内容可以直接转化为代理可执行的动作，如Vercel将“click”替换为等效的curl命令。</p><h3 id="4-">4. 模型上下文协议：</h3><p>除了上述通用调整外，还有像Enthropic的模型上下文协议这样的专用协议，它提供了一种直接与AI代理通信的方式。</p><h3 id="5-llm">5. 数据摄取工具以适配LLM：</h3><p>例如，像Gitingest这样的工具，可以将GitHub仓库的URL转换为一个包含所有文件内容和目录结构的单一巨大文本，方便直接复制粘贴到LLM中进行提问和处理。
更进一步的例子是Deep Wiki，它不仅摄取原始文件内容，还会让AI对GitHub仓库进行分析，并自动生成整个文档页面，使其对LLM更具帮助。</p><p><strong>思考：</strong> 
这一部分值得深思。虽然真正的智能体还未出现，但互联网产品已不只服务于人类，未来或许会出现同时面向 AI agent 和人类的新概念产品。</p></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/software_3.0#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/software_3.0</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/software_3.0</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Thu, 19 Jun 2025 08:16:08 GMT</pubDate></item><item><title><![CDATA[中文笔记：An Introduction to Discrete Variational Autoencoders]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/discreteVAE">https://www.coder-nova.com/posts/ai/discreteVAE</a></blockquote><div><h2 id="1-">1. 统计学基础：</h2><h3 id="">数学符号：</h3><p>标量（Scalar-valued variable）：$x$,</p><p>向量、矩阵或向量拼接（Vectors, matrices, concatenations of vectors）：$\boldsymbol{x}$,</p><p>概率分布（Probability Distributions）：$ \mathcal{D} $, 从分布中采样或随机变量的记法：$x \sim \mathcal{D}$，</p><p>可学习的参数：$\boldsymbol{\psi}$，</p><p>概率密度函数（或概率质量函数）： $p$, $q$，</p><p>分布在参数 $\boldsymbol{\psi}$ 下对 $x$ 的评估： $p_{\boldsymbol{\psi}}(x)$，</p><p>概率分布下的期望表示： $\mathbb{E}{p{\boldsymbol{\psi}}(x)}[f(x)]$， 积分形式展开：$
\mathbb{E}<em>{p</em>{\boldsymbol{\psi}}(x)}[f(x)] = \int<em>x p</em>{\boldsymbol{\psi}}(x) f(x) , dx
$</p><hr/><h3 id="probabilities-and-information-measures">概率与信息度量（Probabilities and Information Measures）</h3><table><thead><tr><th>编号</th><th>概念</th><th>表达式</th></tr></thead><tbody><tr><td>(1)</td><td>联合概率与条件概率关系</td><td>$p(A, B) = p(A \mid B)p(B) = p(B \mid A)p(A)$</td></tr><tr><td>(2)</td><td>全概率公式</td><td>$p(A) = \sum_{i=1}^{k} p(A \mid B_i)p(B_i)$</td></tr><tr><td>(3)</td><td>KL 散度（KL Divergence）</td><td>$D_{\mathrm{KL}}(q(A) \parallel p(A)) \triangleq \int q(A) \log \left[\frac{q(A)}{p(A)}\right] dA$</td></tr><tr><td></td><td></td><td>$= -\int q(A) \log \left[\frac{p(A)}{q(A)}\right] dA$</td></tr><tr><td>(4)</td><td>熵（Entropy）</td><td>$H(p(A)) \triangleq -\int p(A) \log p(A) , dA$</td></tr><tr><td>(5)</td><td>交叉熵（Cross-Entropy）</td><td>$H(p(A), q(A)) \triangleq -\int p(A) \log q(A) , dA$</td></tr><tr><td>(6)</td><td>离散熵（Discrete Entropy）</td><td>$\mathrm{Entropy}(\mathbf{a}) \triangleq -\sum_{i=1}^{k} a_i \log a_i$</td></tr><tr><td>(7)</td><td>离散交叉熵（Discrete Cross-Entropy）</td><td>$\mathrm{CE}(\mathbf{a}, \mathbf{b}) \triangleq -\sum_{i=1}^{k} a_i \log b_i$</td></tr><tr><td>(8)</td><td>二元交叉熵（Binary Cross-Entropy）</td><td>$\mathrm{BCE}(\mathbf{a}, \mathbf{b}) \triangleq -a_1 \log b_1 - (1 - a_1) \log(1 - b_1)$</td></tr><tr><td>(9)</td><td>批量熵（Aggregate Entropy）</td><td>$\overline{\mathrm{Entropy}}(\boldsymbol{\alpha}) \triangleq \sum_{j=1}^{m} \mathrm{Entropy}(\mathbf{a}^{(j)})$</td></tr><tr><td>(10)</td><td>批量二元交叉熵（Aggregate Binary Cross-Entropy）</td><td>$\overline{\mathrm{BCE}}(\boldsymbol{\alpha}, \boldsymbol{\beta}) \triangleq \sum_{j=1}^{m} \mathrm{BCE}(\mathbf{a}^{(j)}, \mathbf{b}^{(j)})$</td></tr></tbody></table><p>复习：</p><ol start="1"><li><p>条件概率表示在事件 B 发生的前提下，事件 A 发生的概率是多少。</p></li><li><p>KL 散度衡量的是：如果你用分布 p 来近似真实分布 q，会造成多大的“信息损失”。如果 $p(A) = q(A)$，即两分布完全一致，KL 散度为 0。它是非对称的：$D<em>{\mathrm{KL}}(q(A) \parallel p(A)) != D</em>{\mathrm{KL}}(p(A) \parallel q(A))$</p></li><li><p>熵用来量化一个概率分布的不确定性。如果一个事件很确定 —— 熵为 0。如果事件非常不确定，比如硬币有一半的几率是正面，一半是反面，那么结果完全不可预测 —— 熵最大。</p></li><li><p>交叉熵是评价用预测分布 q 来描述真实分布 p 有多糟？ = 真实熵 + 预测带来的额外损失（KL 散度）</p></li></ol><h3 id="discrete-probability-distributions">离散概率分布（Discrete Probability Distributions）</h3><ol start="1"><li>伯努利分布（Bernoulli Distribution）：适用于仅有两个结果（例如抛硬币）的事件。</li></ol><p>定义为：</p><p>$ X \sim \mathrm{Bernoulli}(p) $, p是一种情况发生的概率</p><p>伯努利分布概率质量函数为：</p><p>$f_X(x) = \begin{cases} p &amp; \text{if } x = 1 \\ 1 - p &amp; \text{if } x = 0 \end{cases}$</p><p>亦可写作：$f_X(x) = p^x (1 - p)^{1 - x}$</p><ol start="2"><li>分类分布（Categorical Distribution）：是伯努利分布在 $k &gt; 2$ 个结果上的扩展。</li></ol><p>定义为：</p><p>$X \sim \mathrm{Cat}(p)$</p><p>概率质量函数为：</p><p>$f_X(x) = \begin{cases} p_1 &amp; \text{if } x = 1 \\ \vdots \\ p_k &amp; \text{if } x = k \end{cases}$</p><p>可以使用Iverson Bracket简明表示为：</p><p>$[x = i] = \begin{cases} 1 &amp; \text{if Statement is true}\\ 0 &amp; \text{Otherwise} \end{cases}$</p><p>同样可以简写为：$f<em>X(x) = \sum</em>{i=1}^{k} [x = i] \cdot p_i$</p><h3 id="maximum-likelihood-estimation">最大似然估计（Maximum Likelihood Estimation）</h3><p>当我们建立一个模型来估计分布 $p_{\boldsymbol{\psi}}(X)$ 时，常见的方法是选择一组<strong>最优参数</strong> $\hat{\boldsymbol{\psi}}$，使得在该模型下观察到的数据的联合概率(joint probability)最大。这种方法称为<strong>最大似然估计（MLE）</strong>。</p><p>给定一组观测数据 ${\boldsymbol{x}<em>i}</em>{i=1}^n$，我们希望找到能最大化似然函数的参数：</p><p>$\hat{\boldsymbol{\psi}} = \arg\max<em>{\boldsymbol{\psi}} \mathcal{L}(\boldsymbol{\psi}) 
= \arg\max</em>{\boldsymbol{\psi}} \prod<em>{i=1}^{n} p</em>{\boldsymbol{\psi}}(x_i)$</p><p>由于直接对乘积求最大值在数值计算中容易出现问题，我们通常对似然函数取对数，转为对数似然函数:</p><p>$\hat{\boldsymbol{\psi}} = \arg\max<em>{\boldsymbol{\psi}} , \ell(\boldsymbol{\psi}) 
= \arg\max</em>{\boldsymbol{\psi}} \sum<em>{i=1}^{n} \log p</em>{\boldsymbol{\psi}}(x_i)$</p><p><strong>对数不会改变最大值的位置，所以最终解是相同的。</strong></p><h3 id="monte-carlo-sampling">蒙特卡洛采样（Monte Carlo Sampling）</h3><p>在优化模型时，我们经常需要计算如下形式的目标函数的梯度：</p><p>$$
\nabla<em>\phi , \mathbb{E}</em>{\mathbf{x} \sim \mathcal{D}}[f_\phi(\mathbf{x})]
$$</p><p>其中：</p><ul><li>$\phi$ 是模型的可学习参数；</li><li>$\mathcal{D}$ 是某个固定的分布（通常是训练数据分布）；</li><li>$f_\phi(\mathbf{x})$ 是与输入 $\mathbf{x}$ 和参数 $\phi$ 有关的函数，例如损失函数。</li></ul><p>上述期望一般是一个积分（或和），它包含了所有可能样本 $\mathbf{x}$ 的信息。但是，在实际中：</p><ul><li><strong>数据集有限</strong>，我们无法枚举所有 $\mathbf{x} \sim \mathcal{D}$；</li><li><strong>积分难以解析求解</strong>，尤其当 $\mathcal{D}$ 是复杂或隐式分布。</li></ul><p>因此，通常我们只能对一个（或几个）样本 $\mathbf{x}$ 估计这个梯度：</p><p>$$
\nabla<em>\phi f</em>\phi(\mathbf{x})
$$</p><p>这种做法称为 <strong>蒙特卡洛估计（Monte Carlo estimate）</strong>。</p><p>它的核心思想是：
&gt; <strong>用少量样本的梯度来近似整个分布下期望的梯度。</strong></p><p>当我们采样 $n$ 个样本 ${\mathbf{x}<em>i}</em>{i=1}^n \sim \mathcal{D}$，对每个计算梯度并取平均，有：</p><p>$$
\frac{1}{n} \sum<em>{i=1}^{n} \nabla</em>\phi f<em>\phi(\mathbf{x}_i) \to \nabla</em>\phi , \mathbb{E}<em>{\mathbf{x} \sim \mathcal{D}}[f</em>\phi(\mathbf{x})] \quad \text{as } n \to \infty
$$</p><blockquote><p>这意味着，当样本数量足够大时，我们就可以<strong>逼近真实的期望梯度</strong>。这个结论依赖于 <strong>大数定律（Law of Large Numbers）</strong>。</p></blockquote>
<p>使用蒙特卡洛采样得到的估计梯度可以简写为：</p><p>$$
\nabla<em>\phi , \mathbb{E}</em>{\mathbf{x} \sim \mathcal{D}}[f<em>\phi(\mathbf{x})] \approx</em>{mc} \nabla<em>\phi f</em>\phi(\mathbf{x}) \tag{21}
$$</p><p>即，用单个样本的梯度来近似整体期望的梯度。</p><hr/><h2 id="2-vae">2. VAE的机制</h2><ol start="1"><li>自编码器（Autoencoder）:</li></ol><ul><li><strong>结构</strong>：编码器 $f<em>{\theta}$ → 潜在空间特征 $\mathbf{z}$ → 解码器 $g</em>{\phi}$。</li><li><strong>目标</strong>：将 $\mathbf{x}\in\mathbb{R}^p$ 压缩到低维 $\mathbf{z}$，再重建 $\hat{\mathbf{x}}\approx\mathbf{x}$。</li></ul><ol start="2"><li><p>变分自编码器（Variational Autoencoder）的机制</p><ul><li>将确定性潜在空间特征替换为 <strong>指定的潜在空间中的分布</strong>（通常采用独立高斯）：</li></ul><p>$$
 (\boldsymbol{\mu},\boldsymbol{\sigma}) = f_{\theta}(\mathbf{x}),\quad
 z_i \sim \mathcal{N}\bigl(\mu_i,\sigma_i^2\bigr)
$$</p><ul><li>解码器对样本进行重建：</li></ul><p>$$
 \hat{\mathbf{x}} = g_{\phi}(\mathbf{z})
$$</p><ul><li>训练损失（ELBO 形式）：</li></ul><p>$$
 \mathcal{L}
   = \mathbb{E}<em>{q</em>{\phi}(\mathbf{z}\mid\mathbf{x})}
     \bigl[-\log p_{\theta}(\mathbf{x}\mid\mathbf{z})\bigr]</p><ul><li>D<em>{\mathrm{KL}}!\bigl(q</em>{\phi}(\mathbf{z}\mid\mathbf{x});|;p(\mathbf{z})\bigr)
$$</li></ul><p>– 第一项 = 重建误差；第二项 = 先验正则化。</p></li></ol><hr/><h2 id="3-">3. 目标函数推导</h2><h3 id="1-">1. 无法直接优化的目标</h3><ul><li><p><strong>最终目标：</strong> 和许多机器学习模型一样，我们的根本目标是<strong>最大化数据的对数似然 (log-likelihood)</strong>，即 $log p_{\theta}(x)$。这个值代表了在给定模型参数 $θ$ 的情况下，观测到真实数据 $x$ 的概率。概率越大，说明我们的模型越能“解释”或“生成”真实数据。</p></li><li><p><strong>VAE 的设定：</strong> VAE 是一个<strong>隐变量模型 (Latent Variable Model)</strong>。它假设我们观测到的数据 $x$ 是由一些我们无法直接观测到的<strong>隐变量 <code>z</code></strong> (latent variables) 所生成的。</p></li><li><p><strong>数学表达：</strong> 我们可以通过对所有可能的隐变量 <code>z</code> 进行积分（边缘化），来表达 $p_{\theta}(x)$：</p><p>  $$
  p<em>{\theta}(x) = \int p</em>{\theta}(x, z) dz
  $$</p>
<p>  使用条件概率法则，上式可以写为：</p>
<p>  $$
  p<em>{\theta}(x) = \int p</em>{\theta}(x|z)p_{\theta}(z)dz
  $$</p>
<p>  这里：</p><ul><li>$p(z)$ 是隐变量的<strong>先验分布</strong>（我们对 <code>z</code> 的预先假设，通常设为简单的标准正态分布）。</li><li>$p(x|z)$ 是给定一个隐变量 <code>z</code>，生成数据 <code>x</code> 的概率。</li></ul></li><li><p><strong>棘手之处：</strong> 公式中的<strong>积分是难以计算的 (intractable)</strong>。因为隐空间 <code>z</code> 通常是高维连续的，我们无法穷举所有 <code>z</code> 来计算这个积分。即使 <code>z</code>是离散的，其计算量也会随着维度呈指数级增长 (<code>m^n</code>)。</p></li></ul><h3 id="2-">2. 推导可行的目标函数</h3><p>既然直接优化行不通，我们需要找到一个替代方案。</p><ul><li><p><strong>第一步：引入后验概率</strong>
  我们利用贝叶斯公式 $p(z|x) = p(x,z) / p(x)$，反向得到 $p(x) = p(x,z) / p(z|x)$。取对数后：</p><p>  $$
  \log p<em>{\theta}(x) = \log\left[\frac{p</em>{\theta}(x, z)}{p_{\theta}(z|x)}\right]
  $$</p><p>  这个式子虽然没有了积分，但引入了一个新的难题：后验概率 $p<em>{\theta}(z|x)$。计算它需要知道 $p</em>{\theta}(x)$，这又回到了原点，陷入了循环论证。</p></li><li><p><strong>第二步：关键技巧——引入一个辅助分布 <code>q(z)</code></strong>
  为了打破僵局，我们引入一个由参数 $ϕ$ 控制的、关于 $z$ 的任意概率分布 $q(z)$。然后我们进行一系列数学变换：</p>
<p>  $$
   \begin{align}
   \log p<em>{\theta}(x) &amp;= \mathbb{E}</em>{q<em>{\phi}(z)}[\log p</em>{\theta}(x)]  \
   &amp;= \mathbb{E}<em>{q</em>{\phi}(z)}\left[\log\frac{p<em>{\theta}(x, z)}{p</em>{\theta}(z|x)}\right]  \
   &amp;= \mathbb{E}<em>{q</em>{\phi}(z)}\left[\log\left(\frac{p<em>{\theta}(x, z)}{q</em>{\phi}(z)} \cdot \frac{q<em>{\phi}(z)}{p</em>{\theta}(z|x)}\right)\right]  \
   &amp;= \mathbb{E}<em>{q</em>{\phi}(z)}\left[\log\frac{p<em>{\theta}(x, z)}{q</em>{\phi}(z)}\right] + \mathbb{E}<em>{q</em>{\phi}(z)}\left[\log\frac{q<em>{\phi}(z)}{p</em>{\theta}(z|x)}\right] 
   \end{align}
   $$</p><ul><li><strong>变换解释</strong>：
  <ul><li>行(1)：因为 $log p(x)$ 相对于 $z$ 是个常数，所以它在任何关于 $z$ 的分布 $q$下的期望都是它本身。</li><li>行(3)：在对数内部，同时乘以和除以 $q(z)$，这是一个值为1的恒等变换。</li><li>行(4)：利用对数的性质 $log(a*b) = log(a) + log(b)$，将式子拆成两项。</li></ul></li></ul></li></ul><h3 id="3-elbo-">3. ELBO 的诞生及其重要意义</h3><p><code>公式(4)</code> 的拆分是整个推导的核心。让我们来分析这两项：</p><ul><li><p><strong>第二项：KL 散度</strong></p><p>  $$
  \mathbb{E}<em>{q</em>{\phi}(z)}\left[\log\frac{q<em>{\phi}(z)}{p</em>{\theta}(z|x)}\right] = D<em>{KL}(q</em>{\phi}(z) \ || \ p_{\theta}(z|x))
  $$</p><p>  这一项正是 <code>q</code> 分布与真实后验分布 <code>p(z|x)</code> 之间的KL 散度 (KL-divergence)，永远非负。</p></li><li><p><strong>第一项：证据下界 (ELBO)</strong>
  既然 $log p(x)$ 等于第一项加上一个非负的 KL 散度，那么第一项必然是 $log p(x)$ 的一个<strong>下界</strong>。
  这个下界就是我们梦寐以求的可优化的目标，它被称为<strong>证据下界 (Evidence Lower Bound, ELBO)</strong>。
  如果我们能找到参数$\theta$和$\phi$使该下界最大化（同时不导致其他项发散），那么这将也是一个接近最大化对数似然本身的解。</p></li><li><p><strong>让 <code>q</code> 更有效：</strong> <code>q</code> 分布之前是任意的，但我们的目标是让这个下界尽可能地接近真实的 <code>log p(x)</code>。什么时候下界最紧呢？当 KL 散度为 0 时。而 KL 散度为 0 的条件是当且仅当两个分布完全相同，即 <code>q_{\phi}(z) = p_{\theta}(z|x)</code>。
  这启发我们，<code>q</code> 分布应该用来<strong>近似</strong> 那个我们算不出来的真实后验 <code>p(z|x)</code>。因此，我们让 <code>q</code> 也依赖于 <code>x</code>，将其写为 <code>q(z|x)</code>。</p></li><li><p><strong>最终的目标函数：</strong>
  将 <code>q(z)</code> 替换为 <code>q(z|x)</code> 后，我们得到了最终的 ELBO 表达式：</p><p>  $$
  \mathcal{L}<em>{\text{ELBO}</em>{\theta, \phi}}(x) \triangleq \mathbb{E}<em>{q</em>{\phi}(z|x)}\left[\log\frac{p<em>{\theta}(x, z)}{q</em>{\phi}(z|x)}\right]
  $$</p><p>  我们的优化问题就从“最大化 <code>log p(x)</code>” 变成了 “<strong>最大化 ELBO</strong>”。</p></li></ul><h3 id="4-elbo-">4. ELBO 的精妙之处：双重优化</h3><p>为了更好地理解我们到底在优化什么，我们将公式重新整理一下：</p><p>$$
\mathcal{L}<em>{\text{ELBO}</em>{\theta, \phi}}(x) = \log p<em>{\theta}(x) - D</em>{KL}(q<em>{\phi}(z|x) \ || \ p</em>{\theta}(z|x))
$$</p><p>从这个式子可以看出，<strong>最大化 ELBO</strong> 同时在做两件事情：</p><ol start="1"><li><p><strong>最大化数据似然 <code>log p(x)</code></strong>：
ELBO 的提升会直接推高 $log p_{\theta}(x)$。这意味着我们的模型更好地捕捉到观测数据的分布。</p></li><li><p><strong>最小化 KL 散度 <code>DKL(...)</code></strong>：
对于一个给定的数据 $x$，$log p(x)$ 是一个定值。此时，要让 ELBO 变大，就必须让 KL 散度变小。这使我们的近似后验分布 $q(z|x)$去不断逼近真实的后验分布 $p(z|x)$。</p></li></ol><hr/><h2 id="3--vae-discrete-vae">3. 离散 VAE (Discrete VAE)</h2><p>离散 VAE 的隐空间 <code>z</code> 不再是连续的，而是由一系列离散的类别变量构成。</p><h3 id="1--z-">1. 隐空间 <code>z</code> 的设计</h3><ul><li><strong>结构</strong>：隐空间由 <code>D</code> 个独立的隐变量组成，每个隐变量可以从 <code>K</code> 个离散的类别中取值。</li><li><strong>表示方法</strong>：为了在实践中实现这一点，每个隐变量都用一个 <strong>one-hot 编码</strong>的向量来表示。向量的长度为 <code>K</code>，在被选中的类别索引处为“1”，其余位置为“0”。</li><li><p><strong>数学表达</strong>：因此，一个完整的隐样本 <code>z</code> 是一个 <code>D x K</code> 的矩阵，即 <code>z ∈ {0,1}^{D×K}</code>，并且对于 <code>D</code> 个变量中的任何一个 <code>d</code>，其 <code>K</code> 个类别的总和都为1:</p><p>  $$
  \sum_{k=1}^{K} z^{(d)}_k = 1 \quad \forall \ d \in [1,D]
  $$</p></li></ul><hr/><h3 id="2-">2. 模型组件的具体选择</h3><ol start="1"><li><p><strong>先验分布 <code>p(z)</code></strong></p><ul><li>对于离散的隐变量，一个自然的选择是<strong>均匀范畴分布 (Uniform Categorical Distribution)</strong>。</li><li>这意味着，在没有任何信息的情况下，我们假设每个隐变量 <code>z^(d)</code> 从 <code>K</code> 个类别中选择任何一个的概率都是相等的 (<code>1/K</code>)。</li><li><p><strong>公式</strong>：</p><p>  $$
  z^{(d)} \sim_{\text{iid}} \text{Cat}(\mathbf{K}^{-1})
  $$</p><p>  这里的 <code>K^-1</code> 表示一个所有元素都为 <code>1/K</code> 的概率向量。</p></li></ul></li><li><p><strong>编码器 Encoder (近似后验 <code>q(z|x)</code>)</strong></p><ul><li>编码器的作用是根据输入数据 <code>x</code> 来推断隐变量 <code>z</code> 的分布。</li><li>它是一个神经网络 <code>f_ϕ(x)</code>，其输出是 <code>D x K</code> 个概率值。这些概率值定义了 <code>D</code> 个范畴分布的参数。</li><li><strong>前向传播过程</strong>：我们将输入 <code>x</code> 送入编码器网络 <code>f_ϕ(x)</code>，得到每个隐变量 <code>z^(d)</code> 的类别概率，然后从这个分布中进行采样，得到 one-hot 形式的 <code>z</code>。</li><li><p><strong>公式</strong>：</p><p>  $$
  z^{(d)} \sim<em>{\text{iid}} \text{Cat}(f</em>{\phi}(x)^{(d)})
  $$</p></li></ul></li><li><p><strong>解码器 Decoder (数据似然 <code>p(x|z)</code>)</strong></p><ul><li>解码器的作用是根据隐变量 <code>z</code> 重建原始输入概率 <code>x</code>。</li><li><p><strong>以二值化 MNIST 数据为例</strong>：</p><ul><li><strong>数据预处理</strong>：我们将 MNIST 的每个像素二值化为黑色（0）或白色（1），即 <code>x ∈ {0,1}^P</code>，其中 <code>P</code> 是像素总数。</li><li><strong>分布选择</strong>：对于这种二元数据，最自然的概率分布是<strong>伯努利分布 (Bernoulli Distribution)</strong>。</li><li><strong>解码器网络 <code>g_θ(z)</code></strong>：它是一个神经网络，接收隐变量 <code>z</code> 作为输入，输出 <code>P</code> 个概率值。每个概率值对应一个像素，代表该像素为白色（1）的概率。</li><li><p><strong>公式</strong>：</p><p>  $$
  x^{(p)} \sim<em>{\text{iid}} \text{Bernoulli}(g</em>{\theta}(z)^{(p)})
  $$</p></li></ul></li></ul></li></ol><hr/><h2 id="4--vae-">4. 离散 VAE 的梯度推导与损失函数</h2><p>理解了离散 VAE 的模型结构后，最后一步是推导其梯度，以便我们进行优化，并明确最终的损失函数。ELBO 的目标是最大化，但在实践中我们通常最小化其负数，即-ELBO。</p><h3 id="1-decoder---">1. 解码器（Decoder）参数 <code>θ</code> 的梯度 <code>∇θ</code></h3><p>这部分的推导相对直接。</p><ul><li><p><strong>核心思路</strong>：ELBO 中关于 <code>θ</code> 的项是 <code>E[log pθ(x|z)]</code>。因为期望是针对 <code>qϕ(z|x)</code> 计算的，它不依赖于 <code>θ</code>，所以我们可以将梯度算子 <code>∇θ</code> 直接移入期望内部。</p><p>  $$
  \nabla<em>{\theta} \mathbb{E}</em>{q<em>{\phi}(z|x)} [\log p</em>{\theta} (x|z)] = \mathbb{E}<em>{q</em>{\phi}(z|x)} [\nabla<em>{\theta} \log p</em>{\theta} (x|z)]
  $$</p></li><li><p><strong>推导过程</strong>：</p><ol start="1"><li><p>这一交换使得我们可以使用<strong>蒙特卡洛采样</strong>来近似梯度：从 <code>qϕ(z|x)</code> 中采样一个 <code>z</code>，然后计算 <code>∇θ log pθ(x|z)</code>。</p></li><li><p>对于二值化的独立像素，<code>log pθ(x|z)</code> 可以分解为每个像素的对数概率之和。</p></li><li><p>每个像素服从伯努利分布 <code>p(x) = p^x(1-p)^(1-x)</code>。其对数概率为 <code>x log(p) + (1-x) log(1-p)</code>。</p></li><li><p>将解码器网络 <code>gθ(z)</code> 的输出视为伯努利分布的参数 <code>p</code>，我们得到：</p><p>$$
\begin{align}
\hat{\nabla}<em>{\theta} &amp;\approx \nabla</em>{\theta} \left( \sum<em>{p=1}^{P} x^{(p)} \log g</em>{\theta} (z)^{(p)} + (1 - x^{(p)}) \log(1 - g<em>{\theta} (z)^{(p)}) \right) \
&amp;= -\nabla</em>{\theta} \sum<em>{p=1}^{P} \text{BCE}(g</em>{\theta} (z)^{(p)}, x^{(p)})  \
&amp;= -\nabla<em>{\theta} \text{BCE}(g</em>{\theta} (z), x) 
\end{align}
$$</p><blockquote><p>这里的梯度就是我们非常熟悉的<strong>二元交叉熵 (Binary Cross-Entropy, BCE) 损失</strong>的负梯度。在任何自动微分库（如 PyTorch）中，这都可以被直接计算。</p></blockquote>
</li></ol></li></ul><hr/><h3 id="2-encoder---">2. 编码器（Encoder）参数 <code>ϕ</code> 的梯度 <code>∇ϕ</code></h3><p>这部分要复杂得多，因为它包含两项，且其中一项的梯度不能直接计算。</p><h4 id="a-kl---dklqzxpz-">A. KL 散度项 <code>-DKL(qϕ(z|x)||p(z))</code> 的梯度</h4><ul><li><strong>核心思路</strong>：总的 KL 散度是 <code>D</code> 个独立隐变量的 KL 散度之和。我们可以先分析单个变量，再求和。</li><li><p><strong>推导过程</strong>：对于单个隐变量 <code>z^(d)</code>，其 KL 散度展开后经过化简可以得到：</p><p>  $$
  \begin{align}
  -D<em>{KL}(q</em>{\phi}(z^{(d)}|x)||p(z)) &amp;= \sum<em>{k=1}^{K} q</em>{\phi}(z^{(d)}<em>k |x) \log \frac{p(z)_k}{q</em>{\phi}(z^{(d)}<em>k |x)}  \
  &amp;= \sum q \log p - \sum q \log q \
  &amp;= \log \frac{1}{K} \sum q - \sum q \log q \quad &amp;(\text{因为 } p(z) \text{ 是均匀分布}) \
  &amp;= -\log K + \text{Entropy}(q</em>{\phi}(z^{(d)}|x))
  \end{align}
  $$</p><p>  这里 <code>Entropy</code> 是编码器输出的范畴分布的<strong>熵</strong>。</p><p>  对所有 <code>D</code> 个变量求和，这一项的梯度变为：</p><p>$$
\nabla<em>{\phi} \sum</em>{d=1}^{D} \text{Entropy}(f<em>{\phi}(x)^{(d)}) = \nabla</em>{\phi} \text{Entropy}(f_{\phi}(x))
$$</p><p>最大化 ELBO 意味着要最大化编码器输出分布的熵，这鼓励编码器不要对某个类别过于自信，起到正则化的作用。</p></li></ul><h6 id="b--elog-pxz-">B. 重建项 <code>E[log pθ(x|z)]</code> 的梯度</h6><ul><li><strong>挑战</strong>：在这里，我们不能将梯度 <code>∇ϕ</code> 直接移入期望，因为期望本身就是对 <code>qϕ</code> 计算的，<code>qϕ</code> 依赖于 <code>ϕ</code>。</li><li><p>解决方案：<strong>Log-Derivative Trick</strong>
  我们使用一种名为“对数-导数技巧”（在强化学习中也叫 REINFORCE）的方法来重写梯度：</p><p>  $$
  \nabla<em>{\phi}\mathbb{E}</em>{q<em>{\phi}(z|x)} [f(z)] = \mathbb{E}</em>{q<em>{\phi}(z|x)} [f(z) \nabla</em>{\phi} \log q_{\phi}(z|x)]
  $$</p><p>  这个技巧再次将梯度移入了期望内部，使我们又能使用蒙特卡洛采样。</p></li><li><p><strong>推导过程</strong>：</p><ol start="1"><li><p>应用该技巧后，我们的梯度近似为：</p><p>$$
\hat{\nabla}<em>{\phi} \approx \log p</em>{\theta} (x|z) \cdot \nabla<em>{\phi} \log q</em>{\phi}(z|x) \quad (73)
$$</p></li><li>第一部分 <code>log pθ(x|z)</code> 我们已经知道，它就是负的 BCE 损失：<code>-BCE(gθ(z), x)</code>。</li><li><p>第二部分 <code>log qϕ(z|x)</code> 是 <code>D</code> 个隐变量的对数概率之和。对于一个被采样出的 one-hot 样本 <code>z</code>，<code>log qϕ(z|x)</code> 等于所有被选中类别的对数概率之和。记 <code>k(d)</code> 为第 <code>d</code> 个变量被采样的类别索引，则：</p><p>$$
\log q<em>{\phi}(z|x) = \sum</em>{d=1}^{D} \log f<em>{\phi}(x)^{(d)}</em>{k^{(d)}} \quad (80)
$$</p></li><li><p>组合起来，得到最终的梯度表达式：</p><p>$$
\hat{\nabla}<em>{\phi} \approx - \text{BCE}(g</em>{\theta} (z), x) \nabla<em>{\phi} \left( \sum</em>{d=1}^{D} \log f<em>{\phi}(x)^{(d)}</em>{k^{(d)}} \right) \quad (81)
$$</p></li></ol></li><li><p><strong>直观理解</strong>：这个梯度形式可以看作是：<code>[奖励]</code> 乘以 <code>[采取动作的对数概率的梯度]</code>。这里的“奖励”是重建效果的好坏（<code>-BCE</code>，重建越好，此项值越大），“动作”是编码器选择了某个类别。</p></li></ul><hr/><h5 id="3--elbo-">3. 最终的 ELBO 损失函数</h5><p>综合以上推导，我们可以写出在训练中实际计算和追踪的 ELBO 的蒙特卡洛近似形式。记住，我们的目标是<strong>最大化</strong> ELBO。</p><p> $$
 \mathcal{L}<em>{\text{ELBO}} \approx \underbrace{\text{Entropy}(f</em>{\phi} (x)) - D \log K}<em>{\text{来自 } -D</em>{KL}(q||p) \text{ 项}} \underbrace{- \text{BCE}(g<em>{\theta} (z), x)}</em>{\text{来自 } E_q[\log p(x|z)] \text{ 项}} \quad (83)
  $$</p><p>在实践中，我们通常会最小化 <strong>-ELBO</strong>，其损失函数为：</p><p>$Loss = <code>BCE 重建损失</code> - <code>熵正则化项</code> + <code>常数</code>$</p><p>这个公式清晰地告诉了我们训练离散 VAE 的全部内容：</p><ol start="1"><li><strong>最小化重建损失 (BCE)</strong>：让解码器学会如何从隐变量中恢复原始图像。</li><li><strong>最大化熵 (Entropy)</strong>：鼓励编码器的输出分布更多样化，防止模式坍塌。</li><li><code>D log K</code> 是一个常数，在比较不同隐空间大小的模型时很重要，但在单次训练的梯度计算中可以忽略。</li></ol></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/discreteVAE#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/discreteVAE</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/discreteVAE</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Mon, 16 Jun 2025 03:04:13 GMT</pubDate></item><item><title><![CDATA[Mac连接Dell外接显示器时RGB模式颜色反转的解决方法]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/tech/mac-rgb-20250614">https://www.coder-nova.com/posts/tech/mac-rgb-20250614</a></blockquote><div><h2 id="">问题说明</h2><p>Mac外接Dell显示器时，会被识别为YPbPr模式，导致画面偏色。当在显示器设置中切换为RGB模式时，又可能出现颜色反转的问题。</p><hr/><h2 id="1-">1. 解决方案：修改系统配置文件</h2><p>英文原文：<a href="https://forums.macrumors.com/threads/mbp-m1-and-lg-27uk850-w-washed-out-colors.2270452/page-5?post=30262233#post-30262233">https://forums.macrumors.com/threads/mbp-m1-and-lg-27uk850-w-washed-out-colors.2270452/page-5?post=30262233#post-30262233</a></p><h3 id="">步骤</h3><ol start="1"><li><p>由于plist文件是二进制文件，所以无法用vscode直接打开，这里我使用的是vscode中的Binary Plist插件。</p></li><li><p>使用命令行前往文件夹:
<code>cd ~/Library/Preferences/ByHost</code></p></li><li><p>查找名为 <code>com.apple.windowserver.displays.[UUID].plist</code> 的文件备份并删除。（怕有问题的话建议备份！）</p></li><li><p>使用命令行前往文件夹：
<code>cd /Library/Preferences</code></p></li><li><p>找到并打开 <code>com.apple.windowserver.displays.plist</code> 文件</p><blockquote><p>注意：由于是系统文件，可能需要chmod来更改权限为777，修改完成后记得改回之前权限644。</p><p>注意：此文件为plist，必须用支持的编辑器（如vscode中的Binary Plist插件）打开。</p></blockquote>
</li><li><p>查找所有 <code>&lt;key&gt;CurrentInfo&lt;/key&gt;</code>，找到对应的 <code>&lt;dict&gt; ... &lt;/dict&gt;</code> 段落</p><blockquote><p>注意：应该可以仅调整需要的分辨率，我并没有尝试。</p></blockquote>
</li><li><p>在对应段落的 <code>&lt;/dict&gt;</code> 后插入如下内容：</p><blockquote><p>不必修改 <key>UnmirrorInfo</key> 开头的段落。</p></blockquote>
</li></ol><pre><code class="language-xml">&lt;key&gt;LinkDescription&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;BitDepth&lt;/key&gt;
    &lt;integer&gt;8&lt;/integer&gt;
    &lt;key&gt;EOTF&lt;/key&gt;
    &lt;integer&gt;0&lt;/integer&gt;
    &lt;key&gt;PixelEncoding&lt;/key&gt;
    &lt;integer&gt;0&lt;/integer&gt;
    &lt;key&gt;Range&lt;/key&gt;
    &lt;integer&gt;1&lt;/integer&gt;
&lt;/dict&gt;</code></pre><p>例（这里仅展示了第一个修改处）：</p><pre><code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
&lt;dict&gt;
    &lt;key&gt;DisplayAnyUserSets&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Configs&lt;/key&gt;
        &lt;array&gt;
            &lt;dict&gt;
                &lt;key&gt;ConfigVersion&lt;/key&gt;
                &lt;integer&gt;1&lt;/integer&gt;
                &lt;key&gt;DisplayConfig&lt;/key&gt;
                &lt;array&gt;
                    &lt;dict&gt;
                        &lt;key&gt;CurrentInfo&lt;/key&gt;
                        &lt;dict&gt;
                            &lt;key&gt;Depth&lt;/key&gt;
                            &lt;integer&gt;8&lt;/integer&gt;
                            &lt;key&gt;High&lt;/key&gt;
                            &lt;real&gt;900&lt;/real&gt;
                            &lt;key&gt;Hz&lt;/key&gt;
                            &lt;real&gt;60&lt;/real&gt;
                            &lt;key&gt;IsLink&lt;/key&gt;
                            &lt;false/&gt;
                            &lt;key&gt;IsVRR&lt;/key&gt;
                            &lt;false/&gt;
                            &lt;key&gt;OriginX&lt;/key&gt;
                            &lt;real&gt;0.0&lt;/real&gt;
                            &lt;key&gt;OriginY&lt;/key&gt;
                            &lt;real&gt;0.0&lt;/real&gt;
                            &lt;key&gt;Scale&lt;/key&gt;
                            &lt;real&gt;2&lt;/real&gt;
                            &lt;key&gt;Wide&lt;/key&gt;
                            &lt;real&gt;1440&lt;/real&gt;
                        &lt;/dict&gt;
                        &lt;key&gt;LinkDescription&lt;/key&gt;
                        &lt;dict&gt;
                            &lt;key&gt;BitDepth&lt;/key&gt;
                            &lt;integer&gt;8&lt;/integer&gt;
                            &lt;key&gt;EOTF&lt;/key&gt;
                            &lt;integer&gt;0&lt;/integer&gt;
                            &lt;key&gt;PixelEncoding&lt;/key&gt;
                            &lt;integer&gt;0&lt;/integer&gt;
                            &lt;key&gt;Range&lt;/key&gt;
                            &lt;integer&gt;1&lt;/integer&gt;
                        &lt;/dict&gt;
                        &lt;key&gt;Rotation&lt;/key&gt;
                        &lt;real&gt;0.0&lt;/real&gt;
                        &lt;key&gt;UUID&lt;/key&gt;
                        &lt;string&gt;[UUID xxx]&lt;/string&gt;
                        &lt;key&gt;UnmirrorInfo&lt;/key&gt;
                        &lt;dict&gt;
                            &lt;key&gt;Depth&lt;/key&gt;
                            &lt;integer&gt;8&lt;/integer&gt;
                            &lt;key&gt;High&lt;/key&gt;
                            &lt;real&gt;900&lt;/real&gt;
                            &lt;key&gt;Hz&lt;/key&gt;
                            &lt;real&gt;60&lt;/real&gt;
                            &lt;key&gt;IsLink&lt;/key&gt;
                            &lt;false/&gt;
                            &lt;key&gt;IsVRR&lt;/key&gt;
                            &lt;false/&gt;
                            &lt;key&gt;OriginX&lt;/key&gt;
                            &lt;real&gt;0.0&lt;/real&gt;
                            &lt;key&gt;OriginY&lt;/key&gt;
                            &lt;real&gt;0.0&lt;/real&gt;
                            &lt;key&gt;Scale&lt;/key&gt;
                            &lt;real&gt;2&lt;/real&gt;
                            &lt;key&gt;Wide&lt;/key&gt;
                            &lt;real&gt;1440&lt;/real&gt;
                        &lt;/dict&gt;
                    &lt;/dict&gt;
                    &lt;dict&gt;</code></pre><h2 id="2-rgb--ypbpr-chatgpt">2. 考察：RGB 与 YPbPr 显示模式的区别（ChatGPT）</h2><table><thead><tr><th>比较项目</th><th>RGB 模式</th><th>YPbPr 模式</th></tr></thead><tbody><tr><td>信号类型</td><td>数字信号，每个颜色分量单独传递</td><td>模拟色差信号，分量混合传递</td></tr><tr><td>色彩表现</td><td>色彩鲜艳自然，准确还原</td><td>色彩偏淡，容易发灰或失真</td></tr><tr><td>推荐场景</td><td>电脑、Mac、显示器等数码设备</td><td>电视、DVD、老视频设备等</td></tr></tbody></table></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/tech/mac-rgb-20250614#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/tech/mac-rgb-20250614</link><guid isPermaLink="true">https://www.coder-nova.com/posts/tech/mac-rgb-20250614</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Sat, 14 Jun 2025 08:02:34 GMT</pubDate></item><item><title><![CDATA[多臂赌博机（Multi-Armed Bandit）问题与UCB]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/bandit">https://www.coder-nova.com/posts/ai/bandit</a></blockquote><div><h1 id="-ucb-">强化学习入门：理解 UCB 动作选择策略</h1><h2 id="">前言：</h2><p>最近在阅读强化学习导论，由于内容过于理论，看的有些迷茫。为了更好地理解相关知识，计划开始结合AI的回答来做一些笔记。</p><h2 id="multi-armed-bandit">多臂赌博机（Multi-Armed Bandit）</h2><p>想象一下你面前有很多台老虎机，每台老虎机吐钱的概率是不同的，但是你事先不知道哪台概率高，哪台概率低。你的目标是在有限的次数内，尽可能多地从这些老虎机里赢钱。这就是一个经典的多臂赌博机（Multi-Armed Bandit）问题。</p><p>在强化学习中，智能体（Agent）就像是玩老虎机的你，它需要在一个环境中做出动作（Action），比如选择拉哪一台老虎机的摇臂。每次动作之后，环境会给出一个奖励（Reward），比如老虎机吐出的钱。智能体的目标是学习一个策略（Policy），也就是选择动作的方法，来最大化它能获得的总奖励。</p><h2 id="-exploration-vs--exploitation">核心挑战：探索 (Exploration) vs. 利用 (Exploitation)</h2><p>智能体如何选择动作呢？</p><ol start="1"><li><p><strong>利用 (Exploitation):</strong></p><ul><li><strong>做法：</strong> 坚持选择当前已知能够带来最高平均奖励的动作（比如一直玩那台看起来最容易出钱的老虎机）。</li><li><strong>好处：</strong> 能稳定地获得当前已知的最好奖励。</li><li><strong>坏处：</strong> 可能错过一个实际上更好但尚未充分尝试的动作。</li></ul></li><li><p><strong>探索 (Exploration):</strong></p><ul><li><strong>做法：</strong> 尝试不同的动作，包括那些目前看起来不是最优的，目的是收集更多关于它们的信息（比如试试别的老虎机）。</li><li><strong>好处：</strong> 有机会发现比当前已知最优动作更好的新动作。</li><li><strong>坏处：</strong> 可能会在效果不佳的动作上浪费尝试次数和时间。</li></ul></li></ol><h2 id="">简单的动作选择策略及其局限</h2><ul><li><strong>贪心策略 (Greedy):</strong> 永远选择当前看起来最好的动作。
  <ul><li><strong>问题：</strong> 纯粹利用，容易陷入局部最优解，无法发现潜在的更好选择。</li></ul></li><li><strong>ε-贪心策略 (Epsilon-Greedy):</strong> 大部分时间选择当前最好的动作（利用），但有 ε 的小概率随机选择一个动作（探索）。
  <ul><li><strong>问题：</strong> 探索是完全随机的，不够智能，没有优先考虑那些“更有探索价值”的动作。</li></ul></li></ul><h2 id="ucb-upper-confidence-bound----">UCB (Upper Confidence Bound - 置信区间上界) 策略</h2><ul><li><strong>优先考虑：</strong>
  <ul><li>已被证明效果好的动作（高平均奖励）。</li><li>尚未充分尝试，但<strong>潜力巨大</strong>（因为不确定性高而被赋予乐观估计）的动作。</li></ul></li><li><strong>效果：</strong> 它鼓励智能体尝试那些“知之甚少”的选项，有效避免过早收敛到次优动作，并随着信息积累逐渐聚焦于最优动作。</li></ul><p>它不仅考虑一个动作过去的平均奖励，还考虑我们对这个动作估计的 <strong>不确定性</strong>。对于每个可能的动作，UCB 会计算一个分数：</p><p><strong>UCB 分数 = (当前估计的平均奖励) + (不确定性奖励加成)</strong></p><ol start="1"><li><p><strong>当前估计的平均奖励 (Exploitation Part):</strong></p><ul><li>计算方式：该动作迄今为止获得的总奖励 / 该动作被选择的总次数。</li><li>作用：反映了该动作基于历史数据的表现，数值越高，越倾向于被“利用”。</li></ul></li><li><p><strong>不确定性奖励加成 (Exploration Part):</strong></p><ul><li>这是 UCB 的关键，用于量化对动作估计的不确定程度。</li><li><strong>特点：</strong>
  <ul><li>一个动作被选择的 <strong>次数越少</strong>，我们对它的了解就越少，<strong>不确定性越高</strong>，这个 <strong>加成项就越大</strong>，鼓励探索。</li><li>一个动作被选择的 <strong>次数越多</strong>，我们对它的估计就越自信，<strong>不确定性越低</strong>，这个 <strong>加成项就越小</strong>。</li></ul></li><li><strong>依赖关系：</strong> 这个加成项通常与总尝试次数（$N$）和该特定动作被尝试的次数（$n_a$）有关。一个常见的形式是 $c * sqrt(ln(N) / n_a)$，其中 $c$ 是一个超参数，用于控制探索的程度。</li></ul></li></ol><h2 id="ucb-">UCB 的工作流程</h2><p>在每个决策点：</p><ol start="1"><li>智能体为<strong>每一个</strong>可以采取的动作计算其当前的 UCB 分数。</li><li>智能体选择那个 <strong>UCB 分数最高的动作</strong> 执行。</li></ol><p><strong>这样如何平衡探索与利用？</strong></p><ul><li><strong>高平均奖励 + 低不确定性：</strong> 如果一个动作历史表现很好且被尝试多次（不确定性加成小），它的高平均奖励仍然可能使其 UCB 分数最高（倾向于利用）。</li><li><strong>中等/低平均奖励 + 高不确定性：</strong> 如果一个动作历史表现一般或较差，但被尝试的次数很少（不确定性加成很大），这个巨大的加成可能使其总 UCB 分数超过其他动作，从而被选中（倾向于探索）。</li><li><strong>动态调整：</strong> 随着某个动作被选择次数增多，其不确定性加成会下降。
  <ul><li>如果它确实是好动作，其平均奖励会保持或升高，继续被选中。</li><li>如果它是不好的动作，其平均奖励会下降，即使不确定性降低，总分也会下降，被选中的概率降低。</li></ul></li></ul></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/bandit#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/bandit</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/bandit</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Mon, 14 Apr 2025 15:01:18 GMT</pubDate></item><item><title><![CDATA[Deep Research: Deep Unrolling with ADMM and LASSO in NLOS, CT, and MRI Inverse Problems]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/deep_search_001">https://www.coder-nova.com/posts/ai/deep_search_001</a></blockquote><div><p>I will conduct a deep investigation into how deep unrolling (deep unfolding) methods integrate with ADMM and LASSO for solving inverse problems in NLOS, CT, and MRI reconstruction. The research will focus on:</p><ul><li><p><strong>Mathematical Formulation:</strong>  High-level explanations of inverse problem models and how deep unrolling approximates iterative solvers.</p></li><li><p><strong>Algorithmic Implementation:</strong>  How neural networks integrate with ADMM and LASSO-based optimization.</p></li><li><p><strong>Code-Level Analysis:</strong>  PyTorch implementations from open-source repositories.</p></li><li><p><strong>Performance Evaluation:</strong>  Comparison between deep unrolling methods and traditional solvers in terms of accuracy, convergence speed, and robustness.</p></li><li><p><strong>Datasets:</strong>  Identification of benchmark datasets for NLOS, CT, and MRI testing.</p></li><li><p><strong>Sources:</strong>  Top conferences and major journals, prioritizing those with GitHub links.</p></li></ul><h1 id="deep-unrolling-with-admm-and-lasso-in-nlos-ct-and-mri-inverse-problems">Deep Unrolling with ADMM and LASSO in NLOS, CT, and MRI Inverse Problems</h1><h2 id="mathematical-formulation-of-inverse-problems">Mathematical Formulation of Inverse Problems</h2><p><strong>Inverse Problems in NLOS, CT, and MRI:</strong>  Non-line-of-sight (NLOS) imaging, X-ray computed tomography (CT), and magnetic resonance imaging (MRI) can all be framed as inverse problems. Each has a forward model linking hidden object properties to measured data, and the goal is to invert this model to recover an image. NLOS imaging measures time-resolved light after multiple bounces to reconstruct a hidden scene – a highly ill-posed problem due to severe loss of information and noise (different hidden scenes can produce the same measurement)​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=On%20one%20hand%2C%20due%20to,spatial%20resolution%20will%20be%20limited">DIGLIB.EG.ORG</a> . CT reconstruction seeks to recover an interior attenuation map $x$ from projection data $y$ (sinograms) via the Radon transform $A$ (i.e. $y = A x + \epsilon$)​<a href="https://www.uni-bremen.de/fileadmin/user_upload/fachbereiche/fb3/techmath/images/research/dlip/lodopab-paper.pdf#:~:text=The%20task%20in%20CT%20belongs,The%20noise%20%CE%B5%20has%20a">UNI-BREMEN.DE</a> . Because the Radon transform is a compact operator and only finitely many angles are measured, the inverse problem is ill-posed​<a href="https://www.uni-bremen.de/fileadmin/user_upload/fachbereiche/fb3/techmath/images/research/dlip/lodopab-paper.pdf#:~:text=transform%20is%20linear%20and%20compact%2C,In%20the%20discrete%20case%20the">UNI-BREMEN.DE</a> , especially in <em>limited-view</em> or <em>low-dose</em> CT scenarios. MRI reconstruction involves recovering an image from undersampled $k$-space (Fourier) measurements. Accelerating MRI by undersampling makes the inverse problem ill-posed, as too few measurements lead to infinitely many solutions. Compressed sensing (CS) theory addresses this by imposing priors like sparsity (e.g. in wavelet domain) to constrain the solution​<a href="https://arxiv.org/html/2412.18668v1#:~:text=MRI%20acquisition%20can%20be%20accelerated,5%20%2C%20%2010">ARXIV.ORG</a> .</p><p><strong>Role of ADMM and LASSO in Sparse, Ill-posed Problems:</strong>  Ill-posed inverse problems are often tackled by formulating a regularized optimization. A common example is the LASSO (Least Absolute Shrinkage and Selection Operator), which uses an $\ell_1$-norm penalty to promote sparsity in the solution. For instance, one may solve $\min_x |A x - y|^2 + \lambda |x|_1$ for CT/MRI (sparsity in the image or transform domain) or use an $\ell_1$ prior on the hidden scene in NLOS to exploit sparsity of reflectance. The Alternating Direction Method of Multipliers (ADMM) is a popular algorithm to solve such problems with composite objectives. ADMM splits the problem into subproblems that are easier to handle – e.g. a least-squares data fidelity update and a separate proximal update for the $\ell_1$ regularization (soft-thresholding)​<a href="https://web.stanford.edu/class/ee364b/lectures/admm_slides.pdf#:~:text=i%20%3A%3D%20S%CE%BB%2F%CF%81%28vi%29%20%28soft%20thresholding%29,30">WEB.STANFORD.EDU</a> . In effect, ADMM transforms a difficult global problem into <em>alternating</em> updates that converge to the solution under broad conditions. For LASSO and related sparse recovery tasks, ADMM is advantageous because each iteration involves a simple shrinkage (thresholding) step for the sparsity prior​<a href="https://www.math.cuhk.edu.hk/course_builder/2122/math4230/admm-with-proof-revised.pdf#:~:text=%28ADMM%29%20www,n%5D%29">MATH.CUHK.EDU.HK</a> . This makes it well-suited for large-scale imaging problems. Overall, ADMM (and similar proximal algorithms) provide a physics-guided iterative framework to enforce data fidelity and sparsity constraints, helping recover images from limited or noisy measurements.</p><p><strong>Deep Unrolling as Learned Iterative Optimization:</strong>  <em>Deep unrolling (or unfolding)</em> is a technique that bridges model-based iterations and data-driven learning. In deep unrolling, one starts from a traditional iterative algorithm (like ADMM or ISTA used for solving the above inverse problems) and <strong>unrolls</strong>  its update steps into the layers of a deep neural network. The fixed iterations of the original algorithm become a sequential network of a corresponding number of layers. Importantly, certain parameters of the algorithm (e.g. step sizes, regularization weights, thresholds) are treated as learnable parameters to be optimized during training. This way, the network mimics the physics-based solver but can <strong>learn an optimal strategy</strong>  for convergence from data. Deep unrolled networks thereby approximate iterative optimization while leveraging training data to achieve faster or better reconstruction. They maintain interpretability (each layer has a known meaning) and often require far fewer iterations to reach high-quality solutions . In summary, the mathematical models (forward operators for NLOS, CT, MRI and sparsity priors) remain at the core, but deep unrolling introduces learnable components within the iterative solution process to handle ill-posedness more effectively.</p><h2 id="algorithmic-implementation-of-deep-unrolling-with-admm">Algorithmic Implementation of Deep Unrolling with ADMM</h2><p><strong>Unrolling ADMM-Based Solvers:</strong>  Deep unrolling techniques often take inspiration from ADMM when dealing with LASSO-like formulations. For example, the ADMM algorithm for a sparse inverse problem might involve: (1) a <strong>data update</strong>  solving a least-squares problem (e.g. using the measured data to update the image), (2) a <strong>sparsity proximal update</strong>  applying soft-thresholding (shrinkage) to enforce sparsity, and (3) a dual variable update. In a deep unrolled network, this sequence is mapped to network layers. Each unrolling <em>stage</em> (layer or group of layers) performs operations analogous to one ADMM iteration . Trainable parameters can be introduced, such as learnable thresholds or relaxation parameters at each stage. Yan <em>et al.</em>’s <strong>ADMM-CSNet</strong>  is a concrete example: it unrolls the ADMM solver for compressive sensing, with each network layer implementing the analytical steps of ADMM while allowing certain parameters (like the penalty parameter $\rho$ or threshold values) to be tuned by learning  . This combination retains the <em>structured updates</em> of ADMM but adapts them for better performance on natural images. In practice, unrolled ADMM networks often limit the number of stages (e.g. 5–15 iterations unrolled) to balance complexity and performance, since a fully convergent ADMM (tens of iterations) may not be needed once learning finds a good set of parameters.</p><p><strong>Neural Networks Approximating Iterative Solvers:</strong>  In deep unrolling, neural network components are sometimes inserted to replace or augment specific steps of the algorithm. A common approach is to replace the “proximal operator” (which enforces the prior) with a small learned network. For instance, instead of a simple soft-threshold, one could use a convolutional neural network as a learned denoiser or projector in each iteration. Many architectures have been proposed along these lines. <strong>ISTA-Net</strong>  (Zhang <em>et al.</em> 2018) unrolls the Iterative Shrinkage-Thresholding Algorithm (ISTA) for sparse image reconstruction, with learnable transforms and thresholds at each layer​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=19,PubMed">MDPI.COM</a> . <strong>ADMM-Net</strong>  and <strong>ADMM-CSNet</strong>  (Yang <em>et al.</em> 2016, 2018) unroll ADMM for MRI and general compressive imaging, learning the regularization parameters and achieving significant speed-ups​<a href="https://github.com/yangyan92/Deep-ADMM-Net#:~:text=This%20is%20a%20testing%20and,%28NIPS%202016">GITHUB.COM</a>  . <strong>Learned Primal-Dual</strong>  (Adler and Öktem 2018) unrolls a primal-dual hybrid gradient method for CT, with learnable operator blocks that handle forward and backward projection updates​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=22,Google%20Scholar">MDPI.COM</a> . In all these cases, the iterative solver’s mathematical operations (e.g. Fourier transforms in MRI, Radon projections in CT, light transport in NLOS) are embedded in the network’s layers, ensuring that <em>physics constraints are hard-wired</em>. The neural network introduces flexibility through trainable weights that can, for example, adapt the strength of regularization per iteration or learn an enhanced prior beyond simple sparsity. This yields an <strong>interpretable yet trainable</strong>  system: as one paper puts it, unrolled networks “incorporate the forward model of the imaging system…and [replace] one or more of its steps with a neural network,” then train by unrolling for a fixed number of steps​<a href="https://arxiv.org/html/2412.18668v1#:~:text=they%20do%20not%20directly%20incorporate,Based%20Deep%20Learning%20%28MoDL%29%C2%A0%5B14">ARXIV.ORG</a> . Essentially, the neural network <strong>learns to optimize</strong>  – it mimics the trajectory of an iterative algorithm but in a data-driven manner.</p><p><strong>Deep Learning vs. Analytical Approaches:</strong>  Compared to purely analytical solvers, deep unrolled methods offer a trade-off between domain knowledge and data adaptation. Traditional algorithms (like ADMM, FISTA, or iterative ART for CT) rely on manually chosen parameters and often need many iterations for high accuracy. They are generic and can be applied to any new data if one can tune the hyperparameters, but they don’t learn from examples. Deep unrolling infuses learning into these iterations: the algorithm’s <strong>structure</strong>  prevents the network from straying far from feasible solutions, while learning allows cutting down iteration count and adjusting to the characteristics of training data. This often yields <strong>faster convergence and higher accuracy</strong> . For example, ADMM-CSNet was shown to reconstruct images with the same accuracy using 10% fewer measurements than standard iterative methods and to run ~40× faster than a traditional algorithm on compressive sensing tasks . In CT reconstruction, unrolled model-based networks have outperformed conventional iterative reconstruction in low-dose or few-view settings in terms of PSNR/SSIM, since the network can suppress noise and artifacts more effectively by learning from training images . Moreover, unrolled models tend to be more <strong>interpretable</strong>  than generic deep networks (like pure U-Nets) because each layer corresponds to a known operation, making it easier to trust and analyze the reconstruction process . However, there are also trade-offs: deep models require a representative training dataset and may <strong>generalize poorly</strong>  outside the training distribution. If the noise level, sampling pattern, or object characteristics change, a network might not perform optimally unless retrained or designed for robustness. In a reported case, a top-performing MRI reconstruction network failed to reconstruct critical details when the test data had a slightly different noise distribution than what it saw in training​<a href="https://arxiv.org/html/2412.18668v1#:~:text=Deep%20learning%20methods%20achieve%20state,improve%20robustness%20and%20generalization%20include">ARXIV.ORG</a> . Traditional solvers, in contrast, can handle such changes by re-tuning parameters (since they don’t <em>learn</em> specific features, they inherently apply the same physics prior to any data). Researchers are actively addressing these issues, for example by incorporating uncertainty modeling or robust training into unrolled networks. In summary, deep unrolling marries the reliability of physics-based algorithms with the adaptivity of deep learning – often yielding superior speed and accuracy on benchmark tasks – but care must be taken to ensure they remain robust and generalizable beyond the training set.</p><h2 id="code-level-analysis-and-implementation-details">Code-Level Analysis and Implementation Details</h2><p><strong>Open-Source Implementations:</strong>  The growing interest in deep unfolding has led to numerous open-source projects and research code releases. For instance, <strong>DeepInverse (deepinv)</strong>  is a PyTorch-based library that provides a unified framework for inverse problems, including easy-to-build <em>unfolded architectures</em> for algorithms like ADMM and forward-backward splitting​<a href="https://github.com/deepinv/deepinv#:~:text=,Langevin%2C%20diffusion%2C%20etc">GITHUB.COM</a> . It offers predefined physics operators (for MRI, CT, deblurring, etc.) and allows researchers to quickly prototype unrolled networks. Many research papers also release code on GitHub: the authors of <em>Deep ADMM-Net for compressive MRI</em> (NIPS 2016) released MATLAB code for their trained model and layers (with the ADMM updates implemented as network layers)​<a href="https://github.com/yangyan92/Deep-ADMM-Net#:~:text=This%20is%20a%20testing%20and,%28NIPS%202016">GITHUB.COM</a> . More recent works typically use Python frameworks – e.g., <strong>CTprintNet</strong>  (an unrolled few-view CT reconstruction method) was implemented in Python using PyTorch​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=,View%20CT">MDPI.COM</a> . Similarly, a <em>primal-dual unrolling</em> approach for CT with a total variation prior (sometimes called PD-Net) was implemented in PyTorch in a 2021 study​<a href="https://aapm.onlinelibrary.wiley.com/doi/10.1002/mp.16307#:~:text=A%20total%20variation%20prior%20unrolling,that%20unfolding%20the%20TV">AAPM.ONLINELIBRARY.WILEY.COM</a> . These repositories often include training scripts and pretrained models, making it easier to reproduce results on common datasets. Beyond individual papers’ code, community toolboxes like <strong>MIRTorch</strong>  (Michigan Image Reconstruction Toolbox) and ODL (Operator Discretization Library) have started integrating deep learning modules with classic reconstruction, enabling custom unrolled networks using their operators.</p><p><strong>ADMM-Based Unfolding in PyTorch:</strong>  Implementing an ADMM-unrolled network in PyTorch typically involves writing a custom <code>nn.Module</code> for each iteration (or one module that iterates internally). Each iteration might consist of operations like linear forward projection (or Fourier transform), an inverse or pseudo-inverse step (often a convolution or FFT-based solve), and a shrinkage/threshold step. These are differentiable operations (soft-threshold is differentiable almost everywhere), so the whole unrolled loop can be backpropagated through. One straightforward approach is to explicitly unroll a fixed number of iterations and treat them as sequential layers. PyTorch’s autograd will handle the gradients through all iterations. However, unrolling many iterations can lead to <strong>high memory usage</strong>  because intermediate states from every layer must be stored for backpropagation. Researchers address this in code by using techniques like <em>gradient checkpointing</em>, which trades extra computation for lower memory by recomputing some intermediate results on the fly instead of storing them. Another approach is <strong>sequential or stage-wise training</strong> : instead of backpropagating through all unrolled iterations at once, one can train the network one iteration at a time or in small blocks, gradually building up to the full unrolled depth. This was demonstrated to drastically reduce memory requirements (by up to 98%) and enable training very deep unrolled models that were previously infeasible​<a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC7612803/#:~:text=reconstruction%20error%20compared%20to%20using,backpropagation%20through%20the%20entire%20network">PMC.NCBI.NLM.NIH.GOV</a> . For example, in 3D imaging (where each “image” is a volume, greatly increasing memory use), a sequential training strategy allowed a fully unrolled 3D reconstruction network to be trained when naive end-to-end training would exhaust GPU memory​<a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC7612803/#:~:text=reconstruction%20error%20compared%20to%20using,backpropagation%20through%20the%20entire%20network">PMC.NCBI.NLM.NIH.GOV</a> .</p><p><strong>Efficient GPU Computation:</strong>  Deep unfolding for imaging typically leverages heavy linear algebra (Fourier transforms in MRI, large matrix multiplications for CT projections, etc.), so efficient GPU utilization is critical. Implementations use batched operations and built-in primitives (like FFT routines or sparse matrix multiply) to speed up these physics-based layers. In MRI, for instance, one can implement the forward model as a fast FFT with masking of k-space samples, which PyTorch (or underlying libraries like FFTW/CuFFT) can do quickly. In CT, projection and backprojection can be the most time-consuming steps; libraries may use GPU-accelerated projectors (some researchers use custom CUDA kernels or the ASTRA toolbox via PyTorch interfaces). By integrating these with learnable CNN modules for the regularization part, the entire unrolled network runs on GPU end-to-end, avoiding slow data transfers. Memory optimization also involves using lower precision (mixed-precision training with float16) which many PyTorch frameworks support to reduce memory and increase throughput, without significant loss in reconstruction quality. Moreover, modern PyTorch allows dynamic computation graphs, so some implementations use a <em>for-loop</em> in the <code>forward</code> method to iterate through layers – this makes it easy to adjust the number of unrolled iterations as a parameter. Care is taken in such cases to ensure the loop is unrolled in the graph for backprop (PyTorch will unroll it since the loop length is fixed, resulting in the same effect as manually writing layers).</p><p>In summary, code-level best practices for deep unrolling include: using existing high-performance ops for the physics model, structuring the network in iterative blocks, managing memory via checkpointing or staged training, and leveraging GPU parallelism for heavy computations. Many open-source codes and libraries are available, lowering the barrier to implement ADMM-based unfolding for NLOS, CT, or MRI problems.</p><h2 id="performance-evaluation-of-deep-unrolling-vs-traditional-solvers">Performance Evaluation of Deep Unrolling vs Traditional Solvers</h2><p><strong>Accuracy and Reconstruction Quality:</strong>  Deep unrolled methods have demonstrated excellent accuracy in reconstructing images compared to traditional solvers. By learning an optimized prior or tuning algorithm parameters, they often achieve lower error (higher PSNR, SSIM) than purely physics-based methods under the same conditions. For example, ADMM-CSNet (for compressive sensing) improved reconstruction PSNR by about 3 dB over previous state-of-the-art methods at 20% sampling . In MRI, unrolled networks like MoDL and VarNet (a variational network used in the fastMRI challenge) have been shown to recover finer details and yield more natural-looking images than conventional compressed sensing (which might leave residual artifacts or noise) – provided the test data is similar to the training distribution. In CT, unrolled approaches (e.g. learned primal-dual, ISTA-Net) have produced higher quality images from sparse-view or low-dose data than analytic algorithms (like FBP with filtering) or even hand-crafted iterative regularization (like TV minimization). They excel at suppressing noise and streak artifacts by learning from example images. That said, the <strong>ultimate accuracy</strong>  can depend on training: if the network is well-trained on diverse data, it can outperform traditional methods across a range of cases; if not, there may be situations where a carefully tuned iterative method could still rival or beat the learned method (especially if the latter encounters an out-of-distribution case).</p><p><strong>Convergence Speed and Efficiency:</strong>  One of the key advantages observed in deep unrolling is faster inference – i.e., obtaining a solution in a fixed small number of network layers, rather than iterating until convergence. Traditional solvers like ADMM or conjugate gradient might need tens or hundreds of iterations for high-quality results, which can be slow (seconds or minutes for large 3D data). Unrolled networks typically cap the iterations (e.g. 10 iterations unrolled) and <strong>learn to make each iteration as effective as possible</strong> . The result is a huge speed-up at runtime. Empirical studies show large gains: for instance, a learned ADMM network was ~40 times faster than solving TV minimization via iterative methods for image deblurring . Even compared to other deep methods not using unrolling, the model-based unrolled networks can be more efficient – ADMM-CSNet was about twice as fast as a conventional CNN reconstruction called ReconNet . These speed-ups are crucial for applications like real-time imaging (e.g., reconstructing MRI on-the-fly during a scan, or CT during an interventional procedure). The training phase of deep networks is of course computationally intensive (may take hours or days on GPUs), but that is a one-time cost; traditional solvers don’t require training but “pay” the cost every time in terms of slow runtime. Thus, once deployed, deep unrolling can give <strong>fast and consistent performance</strong>  case after case. An important point in convergence: unrolled networks do not iterate until a mathematical convergence criterion – they stop at the fixed depth. If more accuracy is needed, one must train a deeper network or use a different approach. However, in practice, well-designed unrolled networks reach a good reconstruction within their fixed iterations and further iterations yield diminishing returns.</p><p><strong>Generalization and Robustness:</strong>  Generalization refers to how well a trained deep unrolling method works on data that differ from its training data. This is a critical evaluation aspect. <strong>Robustness to noise:</strong>  Traditional regularized solvers (ADMM, etc.) can be re-run with adjusted parameters for different noise levels, and methods like LASSO or total variation are known to handle noise by appropriate regularization. A deep unrolled network can be trained with simulated noise in the training data to encourage robustness – and many studies do add noise augmentation so the network learns to handle it. Within the range of noise it has seen, an unrolled model often maintains good performance (and can even outperform human-tuned algorithms, since it may learn an optimal denoising strategy). But if the noise statistics change significantly, the network might not optimally adapt. For example, an MRI unrolled network trained on one noise level saw a drop in performance when evaluated on data with a different noise variance​<a href="https://arxiv.org/html/2412.18668v1#:~:text=Deep%20learning%20methods%20achieve%20state,improve%20robustness%20and%20generalization%20include">ARXIV.ORG</a> . Recent research (like the PUN method mentioned earlier) is looking at ways to improve robustness, e.g., by pruning networks or using techniques from domain generalization. <strong>Missing data or different sampling patterns:</strong>  Similar concerns arise if, say, a CT network trained on one set of angles is applied to a scenario with a totally different set of projection angles, or an MRI network trained on random undersampling is tested on radial undersampling. If the forward model is integrated (which it is, in unrolled networks), the network <em>knows</em> the physics for any sampling pattern (since the forward operator $A$ can be changed or is a parameter to the network). However, the learned prior might be overfit to certain artifact patterns. A study of the 2019 fastMRI challenge noted that even minor shifts in the sampling pattern caused some deep learning models to miss subtle features​<a href="https://arxiv.org/html/2412.18668v1#:~:text=their%20training%20data,settings%20and%20anatomies%2C%20especially%20in">ARXIV.ORG</a> . Unrolled models, by virtue of being closer to model-based, generally handle moderate shifts better than pure black-box models, but they are not immune to generalization issues.</p><p>In terms of <strong>hardware and deployment constraints:</strong>  Traditional iterative solvers can be run on CPU (slowly) or GPU, and one can trade off speed for memory (e.g., using more iterations uses more time but not necessarily more memory at once). Deep networks typically <strong>require a capable GPU</strong>  (or specialized accelerator) at inference to achieve their speed advantage, which might be a constraint in some low-resource settings. They also consume GPU memory proportional to model size. However, once properly engineered, even large unrolled models (with e.g. 10 convolutional layers per iteration and 10 iterations) can run on a modern GPU within tens of milliseconds. There have been demonstrations of deep reconstructions running on scanner hardware or within streaming recon systems in hospitals, indicating it’s feasible with current tech. Another consideration is <strong>stability and reliability</strong> : iterative methods can be stopped early or adjusted if something looks off in the reconstruction; a deep network gives one shot output. Thus, extensive validation is needed to ensure the network is reliable across cases. Many evaluations in literature report not just average error metrics but also worst-case errors and visual inspection for artifacts, to ensure the learned method doesn’t introduce unpredictable errors (an essential aspect if these are to be used in safety-critical applications like medical diagnostics). So far, results are encouraging – deep unrolled methods often produce <em>fewer</em> noticeable artifacts than traditional methods, rather than more, when applied within their tested regime​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=when%20handling%20various%20scenarios%20with,transport%20measurements%20capturing%20short%20pulses">DIGLIB.EG.ORG</a> ​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=comparing%20existing%20deep%20learning%20method,generate%20unsatisfactory%20results%20with%20temporal">DIGLIB.EG.ORG</a> .</p><p>In summary, performance evaluations generally find that deep unrolling offers <strong>major gains in speed and often in reconstruction fidelity</strong>  for NLOS, CT, and MRI inverse problems. The trade-offs lie in the need for training and the careful assessment of robustness. Ongoing research is closing the gap in generalization, with techniques to make these learned solvers more adaptable to new conditions without retraining.</p><h2 id="datasets-for-nlos-ct-and-mri">Datasets for NLOS, CT, and MRI</h2><p><strong>NLOS Imaging Datasets:</strong>  Non-line-of-sight imaging is still a developing field, and as such, there are not as many standardized large-scale datasets as in CT or MRI. Nonetheless, there are a few benchmarks emerging:</p><ul><li><p><em>Synthetic Data:</em> One example is the <strong>Zaragoza NLOS dataset</strong> , which provides synthetic scenes and their corresponding time-resolved measurements rendered with physics-based simulation​<a href="https://graphics.unizar.es/nlos_dataset#:~:text=Lab%20graphics,from%20Jarabo%20et%20al%27s%20work">GRAPHICS.UNIZAR.ES</a> . This allows researchers to test algorithms on a variety of known scenes.</p></li><li><p><em>Real Data:</em> Many NLOS research papers provide data from their hardware experiments (e.g., the classic NLOS corner camera experiment by Velten <em>et al.</em> had a small set of examples like hidden mannequins, and later works by MIT or Stanford include captured transients for hidden scenes like cardboard cut-outs or real objects). These are sometimes released alongside papers. For instance, Chen <em>et al.</em> 2020 (“Learned Feature Embeddings for NLOS”) and subsequent works provide their captured data of hidden objects as a reference.</p></li><li><p><em>Recent Public Datasets:</em> A <strong>passive NLOS imaging dataset</strong>  was released with a 2022 study that used an optimal transport framework​<a href="https://ieeexplore.ieee.org/document/9623377/#:~:text=Passive%20Non,Volume%3A%2031">IEEEXPLORE.IEEE.ORG</a> . This dataset (NLOS-Passive) contains measurements where the illumination is ambient light rather than an active laser, which is a different challenge. Additionally, code and data for specific algorithms like the <strong>frequency-domain NLOS (f-k migration)</strong>  by Lindell <em>et al.</em> were made public on GitHub​<a href="https://github.com/computational-imaging/nlos-fk#:~:text=GitHub%20github.com%20%20Non,k%20Migration%20by%20David%20B">GITHUB.COM</a> , which includes some real-world scans.</p></li><li><p><em>Towards a Benchmark:</em> The 2023 MIMU paper introduced a large-scale synthetic dataset with varying resolutions and noise, aiming to serve as a universal training set for NLOS learning methods​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=information%20about%20the%20input%20features,synthetic%20data%20and%20real%20captures">DIGLIB.EG.ORG</a> . This hints at a future where NLOS might have something akin to ImageNet for hidden scenes.</p></li></ul><p>In summary, NLOS datasets exist in pieces – researchers often compile their own – but there is a trend toward sharing and standardizing, with both synthetic benchmarks and real captured data becoming available for the community.</p><p><strong>CT Reconstruction Datasets:</strong>  The medical imaging community has several well-known datasets for CT reconstruction, especially for low-dose or sparse-view reconstruction tasks:</p><ul><li><p>The <strong>Mayo Clinic Low-Dose CT Challenge Dataset (AAPM 2016)</strong>  is a widely used set of 3D CT scans. It contains paired high-dose and simulated low-dose scans of patients (mostly abdominal scans). This allows supervised training and evaluation of denoising or reconstruction algorithms that turn low-dose input into high-quality output. Many deep learning papers (including unrolling methods like LEARN​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=,Google%20Scholar">MDPI.COM</a>  or others) have used this data to show improvements over filtered back-projection or iterative methods.</p></li><li><p>The <strong>LoDoPaB-CT dataset</strong>  (Low Dose Parallel Beam CT) is a public benchmark introduced in 2020. It consists of over 40,000 2D slice images derived from ~800 patients from the LIDC-IDRI lung CT database, along with simulated projection data (Radon transform) at low-dose settings​<a href="https://arxiv.org/abs/1910.01113#:~:text=on%20the%20data%20and%20the,also%20include%20first%20baseline%20results">ARXIV.ORG</a> . Importantly, LoDoPaB provides a standardized train/validation/test split, which has been used in papers to quantitatively compare different reconstruction approaches​<a href="https://arxiv.org/abs/1910.01113#:~:text=,In%20this%20paper%20we">ARXIV.ORG</a> . It’s becoming a reference dataset for sparse-view and low-dose CT research.</p></li><li><p><strong>Sparse-View CT data:</strong>  Some works simulate extremely limited angle scenarios. The <em>IEEE VIP Cup 2019</em> provided a challenge dataset for sparse-view (e.g., 30 or 60 views) CT reconstruction, which has been used to test learned primal-dual and other unrolled methods.</p></li><li><p><strong>Phantom and Analytical Data:</strong>  Beyond patient scans, there are standard phantoms like the Shepp-Logan phantom (a classic synthetic image) for which “true” projections can be computed. While not a dataset per se, these are often used for initial validation of algorithms. Some studies create their own simulation datasets by taking images (from MRI or other modalities or even natural images) and treating them as “CT slices” to forward project. This is especially common in academic research to provide unlimited training data (since one can generate as many random phantom images and their projections as needed).</p></li><li><p>It’s worth noting that clinical CT datasets are typically 3D (volumes), but many learning papers work with 2D slices for simplicity. However, some recent research is moving to 3D reconstruction with unrolled networks as well, using multiple slices or even the full volume as input (which is much heavier computationally).</p></li></ul><p><strong>MRI Reconstruction Datasets:</strong>  MRI has benefited from some large open datasets in recent years, spurred in part by challenges to accelerate MRI:</p><ul><li><p>The <strong>fastMRI dataset</strong>  by NYU (in collaboration with Facebook AI) is a comprehensive open dataset for accelerated MRI reconstruction​<a href="https://arxiv.org/html/2412.18668v1#:~:text=match%20at%20L374%20,Lungren%2C%20%E2%80%9Cfastmri%2B%2C%20clinical">ARXIV.ORG</a> . It includes over 1,500 clinical MRI scans of the knee (multi-coil raw k-space data and ground truth images), as well as brain MRI data. The fastMRI dataset comes with predefined train/val/test splits and has been used in a public leader-board competition. It has become a standard for evaluating deep learning reconstruction – many unrolled models (VarNet, MoDL, etc.) report results on fastMRI, making it easy to compare performance.</p></li><li><p>The <strong>Calgary-Campinas (CC359) dataset</strong>  is another open set containing 359 multi-coil brain MRI volumes at 3T, which can be used for training and evaluating reconstruction algorithms. It’s somewhat smaller than fastMRI but focused on brain imaging.</p></li><li><p>The <strong>Stanford MRNet dataset</strong>  contains knee MRI images (sagittal knee scans) primarily for abnormality detection, but it has been repurposed by some for reconstruction research by simulating undersampling on those images.</p></li><li><p>Legacy datasets like the <strong>IXI dataset</strong>  (a collection of brain MR images from multiple scanners) or <strong>OASIS</strong>  (brain MRI for Alzheimer’s study) have also been used to augment training data or evaluate generalization, though they are not specifically designed for reconstruction tasks.</p></li><li><p>In MRI, researchers also use a lot of <em>simulated undersampling</em>. Given a fully-sampled image or k-space, one can digitally undersample (e.g., drop 80% of k-space points) to create a test case for reconstruction. Thus, even if a fully-sampled image dataset is small, one can create many undersampled versions to test different acceleration factors or patterns. For example, the fastMRI challenge provided specific masks (Cartesian subsampling patterns) for 4x or 8x acceleration, and participants evaluated their unrolled models on those.</p></li><li><p>Additionally, there are sample data from manufacturers or hospitals (like Mayo Clinic has released some MRI data, and the ISMRM challenge datasets for reconstruction like the 2013 challenge on dynamic imaging). These are used in more specialized scenarios (e.g., dynamic MRI, where time sequences are reconstructed).
Overall, for each modality – <strong>NLOS, CT, MRI</strong>  – the field is supported by a growing set of datasets that enable both training of deep models and standardized evaluation. NLOS is catching up with more shared data emerging. CT has both real clinical data and plenty of simulated data in public domain. MRI likely has the largest public datasets for this purpose (fastMRI being a prime example). The availability of open datasets and code is accelerating research on deep unrolling, allowing rigorous comparison of techniques in solving these challenging inverse problems.</p></li></ul><p><strong>References:</strong></p><ul><li><p>MIMU (Multi-scale Iterative Model-guided Unfolding) network for NLOS: ill-posed problem discussion​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=On%20one%20hand%2C%20due%20to,spatial%20resolution%20will%20be%20limited">DIGLIB.EG.ORG</a>  and multi-scale unrolling approach​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=and%20a%20voxel%20mapping%20module,ro%02bustly%2C%20we%20adopt%20a%20more">DIGLIB.EG.ORG</a> .</p></li><li><p>LoDoPaB-CT dataset paper: describes CT inverse problem and dataset details​<a href="https://www.uni-bremen.de/fileadmin/user_upload/fachbereiche/fb3/techmath/images/research/dlip/lodopab-paper.pdf#:~:text=transform%20is%20linear%20and%20compact%2C,In%20the%20discrete%20case%20the">UNI-BREMEN.DE</a> ​<a href="https://arxiv.org/abs/1910.01113#:~:text=on%20the%20data%20and%20the,also%20include%20first%20baseline%20results">ARXIV.ORG</a> .</p></li><li><p>Pruning Unrolled Networks (PUN) for MRI: introduction to unrolled networks​<a href="https://arxiv.org/html/2412.18668v1#:~:text=they%20do%20not%20directly%20incorporate,Based%20Deep%20Learning%20%28MoDL%29%C2%A0%5B14">ARXIV.ORG</a>  and generalization issues noted in fastMRI challenge​<a href="https://arxiv.org/html/2412.18668v1#:~:text=Deep%20learning%20methods%20achieve%20state,improve%20robustness%20and%20generalization%20include">ARXIV.ORG</a> .</p></li><li><p>Monga <em>et al.</em>, <em>IEEE SPM 2021</em>: overview of algorithm unrolling and ADMM-CSNet performance gains  .</p></li><li><p>Yang <em>et al.</em>, <em>TPAMI 2020</em>: ADMM-CSNet, unrolling ADMM for compressive imaging (builds on NIPS 2016 ADMM-Net for MRI) .</p></li><li><p>Adler &amp; Öktem 2018: Learned Primal-Dual for CT (unrolled primal-dual algorithm)​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=22,Google%20Scholar">MDPI.COM</a> .</p></li><li><p>Zhang &amp; Ghanem 2018 (CVPR): ISTA-Net (unrolled ISTA) for image CS​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=19,PubMed">MDPI.COM</a> .</p></li><li><p>Hammernik <em>et al.</em> 2018: Variational Network for MRI (unrolled gradient descent with learned regularizer).</p></li><li><p>DeepInverse (PyTorch library) documentation​<a href="https://github.com/deepinv/deepinv#:~:text=,Langevin%2C%20diffusion%2C%20etc">GITHUB.COM</a> .</p></li><li><p><strong>GitHub</strong> : yangyan92/Deep-ADMM-Net (NIPS 2016 code release)​<a href="https://github.com/yangyan92/Deep-ADMM-Net#:~:text=This%20is%20a%20testing%20and,%28NIPS%202016">GITHUB.COM</a> ; deepinv/deepinv (library)​<a href="https://github.com/deepinv/deepinv#:~:text=,Langevin%2C%20diffusion%2C%20etc">GITHUB.COM</a> .</p></li><li><p>CTprintNet 2023: PyTorch implementation for unrolled CT recon​<a href="https://www.mdpi.com/1999-4893/16/6/270#:~:text=,View%20CT">MDPI.COM</a> .</p></li><li><p>G. Chen <em>et al.</em> 2020, <em>TOG</em>: Learned Feature Embeddings for NLOS (NLOS dataset and learning-based recon).</p></li><li><p>X. Liu <em>et al.</em> 2023, <em>CGF</em>: MIMU NLOS unfolding with dataset augmentation​<a href="https://diglib.eg.org/bitstream/handle/10.1111/cgf14958/v42i7_30_14958.pdf#:~:text=information%20about%20the%20input%20features,synthetic%20data%20and%20real%20captures">DIGLIB.EG.ORG</a> .</p></li><li><p>FastMRI dataset paper (Zbontar et al. 2019)​<a href="https://arxiv.org/html/2412.18668v1#:~:text=match%20at%20L374%20,Lungren%2C%20%E2%80%9Cfastmri%2B%2C%20clinical">ARXIV.ORG</a> .</p></li><li><p>Johannes Leuschner et al. 2021: LoDoPaB-CT dataset description​<a href="https://arxiv.org/abs/1910.01113#:~:text=on%20the%20data%20and%20the,also%20include%20first%20baseline%20results">ARXIV.ORG</a> .</p></li><li><p><em>Memory-efficient unrolling:</em> G. Zaharchuk et al. 2020 (FBSEM-Net for PET) – sequential training reduces memory by 98%​<a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC7612803/#:~:text=reconstruction%20error%20compared%20to%20using,backpropagation%20through%20the%20entire%20network">PMC.NCBI.NLM.NIH.GOV</a> .</p></li><li><p>Additional references as cited inline above.</p></li></ul></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/deep_search_001#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/deep_search_001</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/deep_search_001</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Wed, 26 Feb 2025 04:29:16 GMT</pubDate></item><item><title><![CDATA[中文笔记：DERT]]></title><description><![CDATA[<div><blockquote>This rendering is generated by Shiro API, and there may be formatting issues. For the best experience, please visit:<a href="https://www.coder-nova.com/posts/ai/dert">https://www.coder-nova.com/posts/ai/dert</a></blockquote><div><h1 id="">前言</h1><p>最近在看Video Moment Retrieval和Highlight Detection的相关研究，其中效果比较好的工作如Moment-DETR，QD-DETR，CG-DETR都使用了DETR作为基本结构？所以有了这篇笔记。</p><h1 id="detr-detection-transformer-">DETR (Detection Transformer) 概述</h1><p>DETR 将目标检测任务视为集合预测问题，主要目标是设计一个端到端的模型，不依赖人工设计的先验信息（如non-maximum suppression和anchor generation）。该网络可以分为四个主要部分：</p><ol start="1"><li><p><strong>CNN特征提取：</strong><br/>使用卷积神经网络（CNN）从输入图像中提取特征。</p></li><li><p><strong>Transformer编码器进行全局特征表征：</strong><br/>编码器采用 Transformer 架构，可以更好地捕捉图像中的全局上下文，有助于后续移除冗余的预测框。</p></li><li><p><strong>使用解码器生成预测框：</strong><br/>Transformer 解码器用于生成预测框。<code>Object Query</code> 用来控制生成多少个预测框。</p></li><li><p><strong>双边匹配损失：</strong><br/>使用双边匹配损失来将预测框与真实标注进行匹配，未匹配上的预测框会被标记为背景。在推理时，这一步会被省略，使用一个设定好的阈值来选择置信度较高的预测框作为输出。</p></li></ol><h3 id="detr-">DETR 成功的原因</h3><p>DETR 的成功很大程度上归功于 Transformer，能够更好地从图像中抽取全局特征，从而提高检测性能。</p><hr/><h2 id="">集合预测损失</h2><p>DETR 引入了一种新颖的集合预测损失，包含以下两个关键步骤：</p><ol start="1"><li><p><strong>最优双边匹配 (optimal bipartite matching)：</strong><br/>这个过程类似于为工人分配任务，目标是使总成本最小化。在 DETR 中，预测框相当于工人，真实框相当于任务，cost矩阵中的cost为分类损失和预测框损失之和。这个匹配问题可以通过匈牙利算法（在 Python 中使用 <code>scipy.linear-sum-assignment</code>）解决。</p></li><li><p><strong>损失计算：</strong><br/>在预测框与真实框匹配后，计算实际损失并进行反向传播。与传统目标检测损失相比，DETR 进行了以下改进：</p><ul><li><strong>去掉分类损失中的 log 函数。</strong></li><li><strong>预测框损失：</strong> 除了使用 L1 损失，还引入了 IOU（generalized Intersection over Union）损失，用于约束那些因为全局特征提取而预测出的大框。</li></ul></li></ol><hr/><h2 id="">推理过程</h2><p>在推理时，第四步（双边匹配损失）会被省略，直接通过设置的置信度阈值来筛选输出的预测框。</p></div><p style="text-align:right"><a href="https://www.coder-nova.com/posts/ai/dert#comments">Finished reading? Say something</a></p></div>]]></description><link>https://www.coder-nova.com/posts/ai/dert</link><guid isPermaLink="true">https://www.coder-nova.com/posts/ai/dert</guid><dc:creator><![CDATA[yang]]></dc:creator><pubDate>Thu, 26 Sep 2024 07:37:41 GMT</pubDate></item></channel></rss>