Julia 并行 for 循环有两个归约
Julia parallel for loop with two reductions
我想在 Julia 中的并行 for 循环中执行两次归约。我正在尝试在构建每棵树时计算并行 for 循环内的随机森林中的错误。有什么想法吗?
当前:
forest = @parallel (vcat) for i in 1:ntrees
inds = rand(1:Nlabels, Nsamples)
build_tree(labels[inds], features[inds,:], nsubfeatures)
end
直觉上,我想要的是在这个 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
就简单性和清晰性而言,使用类型可能是最好的,例如
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
我想在 Julia 中的并行 for 循环中执行两次归约。我正在尝试在构建每棵树时计算并行 for 循环内的随机森林中的错误。有什么想法吗?
当前:
forest = @parallel (vcat) for i in 1:ntrees
inds = rand(1:Nlabels, Nsamples)
build_tree(labels[inds], features[inds,:], nsubfeatures)
end
直觉上,我想要的是在这个 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
就简单性和清晰性而言,使用类型可能是最好的,例如
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