gpt4 book ai didi

algorithm - 如何编写这个简单的阈值算法?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:30:33 24 4
gpt4 key购买 nike

score = 50;
thresholdMax = 70;
thresholdMin = 30;

if (score > thresholdMax) return 1;
if (score < thresholdMin) return 0;
else return //the fraction between thresholdMax and thresholdMin that score is, as a value between 0 and 1.

我知道这一定很简单,但我就是想不出怎么写。

我这样试过,但我认为它不起作用:

spread = ThresholdMax - ThresholdMin;
diff = score - ThresholdMin;
return Math.round(diff / spread);

最佳答案

您也可以尝试使用 minmax 函数:

return min(1, max(0, (score-thresholdMin)/(thresholdMax-thresholdMin)));

关于algorithm - 如何编写这个简单的阈值算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48943507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com