Average multiple evaluations of the same function

It depends on the type of output, but something like:

julia> function average_over(f::Function, args...; n::Int)
           return reduce(.+, f(args...) for _ in 1:n) ./ n
       end
average_over (generic function with 1 method)

julia> foo(args...) = map(a -> a .+ randn(2), args)
foo (generic function with 1 method)

julia> average_over(foo, 1, 2; n = 10)
([0.8054566798422351, 1.1462985508680306], [2.8200773922538627, 2.0001120212986656])
1 Like