1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ztable_fast.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-03-04 12:30 . 置信区间和Z分值的转换函数
package stat
import "sort"
const (
kMaximumPercentage = float64(0.9999) // 最大百分比
kMinimumPercentage = float64(0.0001) // 最小百分比
kMaxScale = 10000 // 最大尺寸
)
func FindPercent(zScore float64) (percent float64) {
index := sort.SearchFloat64s(__percentToZscore, zScore)
percent = float64(index) / float64(kMaxScale)
return percent
}
func FindZScore(percent float64) (zScore float64) {
// 第一步约束 percentage在0~9999范围内
index := int(percent*(kMaxScale)) % kMaxScale
return __percentToZscore[index]
}
// ConfidenceIntervalToZscore 通过置信区间百分比查找Z分值
func ConfidenceIntervalToZscore(confidenceInterval float64) (zScore float64) {
// 约束 percentage在0~9999范围内
index := int(confidenceInterval*(kMaxScale)) % kMaxScale
return __z_table[index]
}
// ZscoreToConfidenceInterval 通过分值查找置信区间
func ZscoreToConfidenceInterval(zScore float64) (confidenceInterval float64) {
index := __SearchFloat64s(__z_table, zScore)
confidenceInterval = float64(index) / float64(kMaxScale)
return confidenceInterval
}
func __SearchFloat64s_v1(a []float64, x float64) int {
n := sort.Search(len(a), func(i int) bool { return a[i] >= x })
return n
}
func __SearchFloat64s(a []float64, x float64) int {
n, found := sort.Find(len(a), func(i int) int {
m := x - a[i]
return int(m * kMaxScale)
})
if !found {
n = n - 1
}
return n
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.3.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891