Turing.jl: SGLD / SGHMC implementations

Created on 11 Sep 2018  路  4Comments  路  Source: TuringLang/Turing.jl

Both the SGLD and SGHMC implementations contains lines similar to the following in their step functions:

if verifygrad(grad)
    @debug "update latent variables..."
    v = zeros(Float64, size(old_胃))
    for k in 1:size(old_胃, 1)
        noise = rand(MvNormal(zeros(length(old_胃[k,:])), sqrt.(系_t)*ones(length(old_胃[k,:]))))
        胃[k,:] = old_胃[k,:] - 0.5 * 系_t * grad[k,:] + noise
    end
end

It's not clear to me why we're indexing into old_胃, , and grad using [k, :]. It's my understanding that all of these variables are Vectors, so their kth rows will always have length one. Is it possible for this not to be the case? Otherwise we should probably move to using [k] rather than [k, :] or broadcasting.

enhancement question

All 4 comments

Hi @emilemathieu, will is refactoring your sghmc code. Can you help him out? Thanks!

Hi !

are the parameters of the model - v and grad have the same dimension.
I believe for k in 1:size(old_胃, 1) loops though each parameters of the model, which can be a vector. I can't remind how the parameters are saved in memory though (concatenated vector? matrix?).
In any case you're right using [k] is better.

Cheers,
Emile

Thanks @emilemathieu . This was my suspicion, I just wanted to ensure that there's nothing strange going on with the stochastic gradient stuff. Will close this when my current PR is merged.

Closed by #515

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mateuszbaran picture mateuszbaran  路  5Comments

krishvishal picture krishvishal  路  6Comments

fredcallaway picture fredcallaway  路  5Comments

scheidan picture scheidan  路  5Comments

marcoct picture marcoct  路  6Comments