安排包 - 顺序 128 的排列

发布于 2025-01-11 16:21:56 字数 516 浏览 0 评论 0原文

我正在尝试使用 R 上的安排包在 128 个空格上运行“x”和“y”的简单排列。

我不断收到以下错误消息:

    Error in permutations(test, k = 128, replace = TRUE) : too many results

我运行的代码如下:

    library(arrangements)
    test <- c('x','y')
    permutations(test, k = 128, replace = TRUE)

sessionInfo() 如下:

    R version 4.1.2 (2021-11-01)
    Platform: x86_64-apple-darwin17.0 (64-bit)
    Running under: macOS Monterey 12.2.1

有我可以使用的解决方法吗?我也在尝试并行包。请指教。

I am trying to run a simple permutation of 'x' and 'y' across 128 spaces using the arrangements package on R.

I keep getting the following error message :

    Error in permutations(test, k = 128, replace = TRUE) : too many results

The code that I ran was as follows:

    library(arrangements)
    test <- c('x','y')
    permutations(test, k = 128, replace = TRUE)

sessionInfo() is as follows:

    R version 4.1.2 (2021-11-01)
    Platform: x86_64-apple-darwin17.0 (64-bit)
    Running under: macOS Monterey 12.2.1

Is there a work around I can use? I am also experimenting with the parallel package. Please advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里人 2025-01-18 16:21:56

正如 @Rui 在评论中指出的那样,结果太多了:

npermutations(2, 128, replace=TRUE, bigz = TRUE)
Big Integer ('bigz') :
[1] 340282366920938463463374607431768211456

使用 skipnitem 参数怎么样?这允许用户一次检索少量结果。

## First 100,000 results
system.time(res <- permutations(c('x', 'y'), 128, replace = TRUE, nitem = 1e5))
# user  system elapsed 
# 0.146   0.000   0.146

## process res

## Next 100,000 results
res <- permutations(c('x', 'y'), 128, replace = TRUE, skip = 1e5, nitem = 1e5)

## process res

## 100,000 results starting at leixcographical index 1e19 + 1
## n.b. need to use strings or bigz type
res <- permutations(c('x', 'y'), 128, replace = TRUE,
                    skip = "10000000000000000000", nitem = 1e5)

## process res
## etc.

如果需要的话,这可以很容易地推广到并行处理。

That's way too many results as @Rui points out in the comments:

npermutations(2, 128, replace=TRUE, bigz = TRUE)
Big Integer ('bigz') :
[1] 340282366920938463463374607431768211456

How about using the skip and nitem parameters? This allows a user to retrieve a handful of results at a time.

## First 100,000 results
system.time(res <- permutations(c('x', 'y'), 128, replace = TRUE, nitem = 1e5))
# user  system elapsed 
# 0.146   0.000   0.146

## process res

## Next 100,000 results
res <- permutations(c('x', 'y'), 128, replace = TRUE, skip = 1e5, nitem = 1e5)

## process res

## 100,000 results starting at leixcographical index 1e19 + 1
## n.b. need to use strings or bigz type
res <- permutations(c('x', 'y'), 128, replace = TRUE,
                    skip = "10000000000000000000", nitem = 1e5)

## process res
## etc.

This can easily be generalized to parallel processing if needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文