-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minibatch
/ stochastic_gradient
operation on models
#633
Comments
Hi @yebai ! I think minibatching will require a more invasive solution than a syntax akin to @model function logistic(X, y)
θ ~ MvNormal(Zeros(d), I)
y .~ BernoulliLogit(X*θ)
end Then we could levereage The problem is models that do have latent variables like matrix factorization: @model function nmf(k, y)
m, n = size(y)
items ~ filldist(Gamma(1, 1), m, k)
users ~ filldist(Gamma(1,1), k, n)
Λ = items*users
@. y ~ Poisson(Λ)
end Let's say we want to subsample over the users, which would correspond to the columns of The way @model function nmf(k, y)
m, n = size(y)
items ~ filldist(Gamma(1, 1), m, k)
users ~ filldist(Gamma(1, 1), k, n)
idx = @dataindex(1:n)
Λ = items*users[:,idx]
ysub = y[:,idx]
@. ysub ~ Poisson(Λ)
end When subsampling, the backend would modify the output of On a related note, to properly support subsampling, So long story short, I think a new syntax will be needed to properly support subsampling. @torfjelde any thoughts? |
We can treat the @model function nmf(k, y; idx = 1:n) # inference algorithm can override the default `idx=1:n`.
m, n = size(y)
items ~ filldist(Gamma(1, 1), m, k)
users ~ filldist(Gamma(1, 1), k, n)
Λ = items*users[:,idx]
ysub = y[:,idx]
@. ysub ~ Poisson(Λ)
end Do you think that's enough?
IIUC, we won't need splitting |
Oh yes, I think that would actually work for now if we assume subsampling over the prior is not supported. Though, for generality, it would probably be better to restruct
I am not sure what you mean here by the tilde pipeline. I was thinking of the case where |
For clarity (sorry for lack of details above), all the operations can be wrapped in a |
Yes how to do all this is pretty clear to me now! Just in terms of the details, though, I was thinking more like sub_iter = sample(subsample_range, B, replace=false)
minibatched = minibatch(model, (sub_iter=sub_iter,)) where |
We have some interesting operators on DynamicPPL models, such as
condition
/decondition
,fix
, andgenerated_quantities
. The advantage of these operators is that models can be specified without knowing them, which is in line with the broad principle of separating modelling and inference specification.https://turinglang.org/DynamicPPL.jl/stable/api/#AbstractPPL.condition
The operators mentioned above prompt me to wonder whether we can introduce operators like
minibatch
/stocchastic_gradient
on models involving a loop over IID data points. These operators would throw an error if the input model does not contain IID data points but would return a new (minibatched
) model if it does.cc @Red-Portal, who will find this useful for stochastic VI.
The text was updated successfully, but these errors were encountered: