R中which.max函数的公差是多少? [英] What's the tolerance of the which.max function in R?

查看:211
本文介绍了R中which.max函数的公差是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于我在这里讨论的问题: https://stackoverflow.com/a/57364028/2725773 我想知道R中which.max函数的公差/精度是多少.

Based on a problem I discussed here: https://stackoverflow.com/a/57364028/2725773 I'm wondering what's the tolerance/precision of the which.max function in R.

具体来说,替代功能max.col的公差为1e-5,这意味着0.12345与0.12346相同.

Specifically, the alternative max.col function has a tolerance of 1e-5, which means that 0.12345 is the same for it as 0.12346.

max.col的帮助页面建议了一种替代方法,即使用unname(apply(m, 1, which.max)),这使我想到了which.max的公差是多少?

The help page for max.col suggests an alternative, namely using unname(apply(m, 1, which.max)), which brings me to the questions what's the tolerance of which.max?

推荐答案

引人入胜的问题.我不知道确切的答案.但是可以测试一些非常小数字以查看会发生什么.

Fascinating question. I do not know the precise answer. But it's possible to test some very small numbers to see what happens..

# the fourth element is the max
c(1,2,3,4,2) %>% which.max
# [1] 4

vec <- c(1,2,3,4,2)

# how tiny can the numbers become before which.max cannot tell the difference between them?
for(i in 1:30) {

  vec <- vec / (10 ^ i)
  max_num <- vec %>% which.max 
  print(vec)
  print(max_num)

}

这些数字可以达到的最小值似乎是1e-300 2e-300 3e-300 4e-300 2e-300(在下一次迭代中,which.max无法分辨出差异)

It looks like the smallest these numbers can get to is 1e-300 2e-300 3e-300 4e-300 2e-300 (on the next iteration, which.max cannot tell the difference)

这篇关于R中which.max函数的公差是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆