【问题标题】:How to implement this equation in numpy如何在 numpy 中实现这个方程
【发布时间】:2021-02-01 14:28:02
【问题描述】:

我是 numpy 的新手,正在尝试实现以下等式。

这个方程有两部分,应该给出一个叫做 Sigma 的最终值。

方程取自论文,如下图: image of the equation to provide the result of Sigma

我尝试如下实现它,但是在运行代码时,值 c 给出了 nan

c = np.sqrt(np.log(2 / np.sqrt( 16 * delta + 1 ) -1 ))

sigma = (c + np.sqrt(np.square(c) + epsilon) ) * s / (epsilon * np.sqrt(2))

如果您能就如何在 numpy 中实现它提出建议,不胜感激

【问题讨论】:

  • cepsilondelta 的值是多少?
  • np.sqrt( 16 * delta + 1 ) -1 应该在括号中。否则2 / np.sqrt( 16 * delta + 1 ) 是积极的小东西,-1 使它成为消极的 log。而log 不喜欢负值
  • 这要么是错字(我假设 OP 知道操作顺序),要么是“需要调试详细信息”,因为没有提供任何输入。
  • @Ananda 感谢您的跟进,我使用 delta 的固定值 0.02 并尝试从 0.1 到 10 的几个 epsilon 值

标签: python numpy machine-learning


【解决方案1】:

您在代码中遗漏了一个括号

c = np.sqrt(np.log(2 / (np.sqrt( 16 * delta + 1 ) -1 )))

sigma = (c + np.sqrt(np.square(c) + epsilon) ) * s / (epsilon * np.sqrt(2))

要获得有效的 c 值,您应该输入 delta,例如 0

【讨论】:

  • 例如,您使用什么增量值?
【解决方案2】:

您缺少括号。这是正确的公式:

c = np.sqrt(np.log(2/(np.sqrt(16*delta + 1) -1)))

另外,请记住(如论文所述)这是仅为 定义的。

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    相关资源
    最近更新 更多