美文网首页
bug修复 | org.apache.commons.math3

bug修复 | org.apache.commons.math3

作者: 学习之术 | 来源:发表于2019-01-06 23:01 被阅读22次

显示的错误:org.apache.commons.math3.exception.NoBracketingException: function values at endpoints do not have different signs, endpoints: [0, 1], values: [-0.694, 0.306]

原因:beta分布的参数为负数,导致采样时出现上述错误。

算法中需要对beta分布进行采样,采样时会用到Inverse transform sampling

解决时间:3h

定位问题:

1. 通过log确定出错的代码:beta分布采样

2. 搜索这个error,并没有发现与beta分布采样有关的资料,现有的资料都是说在解方程时没有解造成的错误。

3. 由于代码没动过,怀疑和beta参数有关,于是打印beta分布的参数。期间犯了新手的错误,没有collect(),导致在executer上打印了参数

4. 期间查看org.apache.commons.math3.distribution.BetaDistribution,发现sample方法会用到inversion method,这方法会解方程

5. collect()之后发现参数有负值(参数alpha),这个值表示的是奖励,在不继地累加,而类型是int,最终超过了上限变成了负值。

定位策略优化:

1. 定位到是beta分布采样时出错,首先要做的是检查beta分布的参数是否异常,应该要先打印参数检查下。

2. 搜索 BetaDistribution sample org.apache.commons.math3.exception.NoBracketingException没结果时,要学会分别搜索BetaDistribution sample及org.apache.commons.math3.exception.NoBracketingException

相关文章

网友评论

      本文标题:bug修复 | org.apache.commons.math3

      本文链接:https://www.haomeiwen.com/subject/upnerqtx.html