Julia并行循环,两次减少

Cok*_*kes 4 julia

我想在Julia的并行for循环中执行两次缩减.我正在尝试计算并行for循环内随机林中的错误,因为每个树都是构建的.有任何想法吗?

当前:

forest = @parallel (vcat) for i in 1:ntrees
    inds = rand(1:Nlabels, Nsamples)
    build_tree(labels[inds], features[inds,:], nsubfeatures)
end
Run Code Online (Sandbox Code Playgroud)

我想要的是,直观地说是在这个for循环中做一个补充,以便解决包误差.这就是我希望它的工作方式:

forest, ooberror = @parallel (vcat, +) for i in 1:ntrees
    inds = rand(1:Nlabels, Nsamples)
    tree = build_tree(labels[inds], features[inds,:], nsubfeatures)
    error = geterror(ids, features, tree)
    (tree, error)
end
Run Code Online (Sandbox Code Playgroud)

Iai*_*ing 5

例如,在简单性和清晰度方面使用类型可能是最佳的

type Forest
  trees :: Vector
  error
end
join(a::Forest, b::Forest) = Forest(vcat(a.trees,b.trees), a.error+b.error)

#...

forest = @parallel (join) for i in 1:ntrees
    inds  = rand(1:Nlabels, Nsamples)
    tree  = build_tree(labels[inds], features[inds,:], nsubfeatures)
    error = geterror(ids, features, tree)
    Forest(tree, error)
end
Run Code Online (Sandbox Code Playgroud)