Documentation
¶
Overview ¶
Package mathx 提供常用的数学工具函数。
包含随机数生成、概率计算、浮点数精度处理等功能。
对比统计:小样本通过率的诚实区间估计与配对二分类差异检验。 显著水平对应的 z 由调用方传入(如 1.96)。收编自 agentkit/reportutil (v0.10.41 起单源在此,agentkit 侧消费本包)。
Index ¶
- func Clamp[T cmp.Ordered](v, lo, hi T) T
- func DivisionN(dividend, divisor float64, n int) float64
- func Floor(x float64, n int) float64
- func McNemarExact(n01, n10 int) float64
- func Probability(band []int) (index, r int)
- func ProbabilityElems(elems []float64, precise float64) []int
- func RandIntn(maxInt int) int
- func RangeRandFloat64(min, max float64) float64
- func Round(x float64, n int) float64
- func ToFixed(num float64, precise int) float64
- func WilsonCI(passed, total int, z float64) (lo, hi float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func McNemarExact ¶
McNemarExact McNemar 精确检验(双侧):n01=甲败乙过数,n10=甲过乙败数。 返回 p 值;n01+n10=0(无任何翻转)返回 1(无差异);p 钳到 1。
func Probability ¶
Probability 根据累积概率边界返回随机选中的索引。 band 为空时返回 (0, 0)。
func ProbabilityElems ¶
ProbabilityElems 计算概率分布的累积边界。 elems 是概率值切片(所有权重必须 > 0),precise 是精度基数。 不修改输入切片(内部排序副本)。 存在 0/负权重时直接 panic:log10(precise/0) 产生 +Inf/NaN,band 会静默 退化为全 0,Probability 恒选 index 0——概率路由静默出错比快速失败更危险。
func RangeRandFloat64 ¶
RangeRandFloat64 返回 [min, max) 范围内的随机浮点数。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.