Hello,
I am parallelizing my gradient calculation in a mini-batch stochastic gradient optimization routine. I am wondering what is the best way to configure cfg = ForwardDiff.GradientConfig() when my function’s input is multiple dimensional (the function is real-valued) but I need to calculate gradient wrt to only one of them.
Please see the code posted below for what I am trying to achieve. I want to calculate the gradient wrt. beta (a 14 dimensional parameter) and would like to pass cfg as an argument, if possible (though this is by no means critical).
@everywhere function diff_distributed(beta::Array{T}, data::V, z::R, cfg::W) where {T<:Real, V<:Array{IndexedTable}, R<:DataFrame, W<:ForwardDiff.GradientConfig}
z = @distributed (vcat) for k in 1:size(data)[1]
grad_final_k = ForwardDiff.gradient!(Array{Float64}(undef, 1, 14), x -> loglike_not_para(x, data[k], z), beta, cfg, Val{false}())
end
#sum
return sum(z, dims = 1)
end