Skip to content

Commit f85e010

Browse files
committed
fix: computeKMax 硬上限 N² 改为 N³,修复小 N 下高档位被 4096 截平
1 parent bf06bc4 commit f85e010

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

web-tools/orthogonal-demo/js/montecarlo.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@
4545
}
4646

4747
/**
48-
* K 上限:min(内存约束, 运算约束, N²),至少为 2。
48+
* K 上限:min(内存约束, 运算约束, N³),至少为 2。
4949
* 顺序逐条轨迹模型:内存约束为单条轨迹的向量(4·K·N 字节),
5050
* opsBudget 为单条轨迹的乘加预算(K²·N/2 次,决定单条耗时)。
51+
* N³ 与 UI 的 K 滑块上限一致(曾是 N²,滑块扩到 N³ 后小 N 下
52+
* 各档位的运算约束全被 N² 截平,如 N=64 时高档位都变成 4096)。
5153
*/
5254
function computeKMax(N, memBytes, opsBudget) {
5355
var byMem = Math.floor(memBytes / (4 * N));
5456
var byOps = Math.floor(Math.sqrt((2 * opsBudget) / N));
55-
return Math.max(2, Math.min(byMem, byOps, N * N));
57+
return Math.max(2, Math.min(byMem, byOps, N * N * N));
5658
}
5759

5860
/** 点积槽位直方图:bins 个等宽内槽 + 首尾两个开口槽;每槽存 sum 与 count */

web-tools/orthogonal-demo/monte-carlo-design.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ K_max 变化):快速 $2.5\times10^8$ / 标准 $2.5\times10^9$(默认)/
118118
$$K_{\max} = \min\Bigl\lfloor
119119
\frac{B_{\text{mem}}}{4N},\;
120120
\sqrt{\frac{2C_{\text{ops}}}{N}},\;
121-
N^2 \Bigr\rfloor,\qquad K_{\max} \ge 2$$
121+
N^3 \Bigr\rfloor,\qquad K_{\max} \ge 2$$
122+
123+
(硬上限与 K 滑块一致取 N³;曾取 N²,滑块扩到 N³ 后未同步,导致
124+
N=64 时三个高档位的运算约束全被 N²=4096 截平。)
122125

123126
默认下 K_max 被**运算预算**封顶(单条轨迹内存仅 MB 级,内存永不沾边),
124127
标准档示例:

web-tools/orthogonal-demo/test/mc-selftest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ console.log('[1] 预算函数与 K 上限');
4545
'got ' + MC.computeKMax(1024, 2 * 1024 * MB, 2.5e8));
4646
check('超宽档 4e10 -> 8838', MC.computeKMax(1024, 2 * 1024 * MB, 4e10) === 8838,
4747
'got ' + MC.computeKMax(1024, 2 * 1024 * MB, 4e10));
48+
// 回归:N=64 时标准档曾被 N²=4096 硬封顶(高档位全部挤在 4096),
49+
// 硬上限已与滑块一致改为 N³,标准档应由运算约束封顶为 8838
50+
check('N=64 标准档 2.5e9 -> 8838(N³ 不截平)',
51+
MC.computeKMax(64, 2 * 1024 * MB, 2.5e9) === 8838,
52+
'got ' + MC.computeKMax(64, 2 * 1024 * MB, 2.5e9));
4853
}
4954

5055
// ---------- 2. K=2 单侧中位数 ≈ 0 ----------

0 commit comments

Comments
 (0)