Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

subsample outside of loop #15

Open
@boennecd

Description

@boennecd

This

pre/R/pre.R

Lines 949 to 963 ine156fbe

## Set up subsamples (outside of the loop):
subsample<-list()
for (iin1:ntrees) {
if (is.function(sampfrac)) {
subsample[[i]]<- sampfrac(n=n,weights=weights)
}
elseif (sampfrac==1) {
subsample[[i]]<- sample(1:n,size=n,replace=TRUE,
prob=weights)
}
elseif (sampfrac<1) {
subsample[[i]]<- sample(1:n,size= round(sampfrac*n),
replace=FALSE,prob=weights)
}
}

is bad idea as it scales very poorly. E.g., suppose there are 200000 rows, we want to sub-sample to half the size and we want 1000 trees. Then it requires 10^5 * 10^3 * 4 = 400 mega bytes of ram. I do see that the reason is theforeach call later

pre/R/pre.R

Line 998 ine156fbe

rules<-foreach::foreach(i=1:ntrees,.combine="c",.packages= c("partykit","pre")) %dopar% {

However, one may still be able to get reproducible results ifclusterSetRNGStream is used withforeach. Though, I have not used theforeach package much and it requires that the loop iterator is split equally to each thread. An alternative is to replace theforeach withparSapply which I know will work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp