-
Notifications
You must be signed in to change notification settings - Fork 219
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
update() method for updating a fitted model with new data #2308
Comments
Additionally, when I try to save the model using JLD2 and then load it, it throws a warning:
and then errors when using it (the model is of type
|
Hey @DominiqueMakowski – sorry it's been a bit quiet in this issue. There is too much work for all of us to do 😅 Just reading #2309 as well. The So if you want to be able to run the sampling and the predictions in separate files, you need to serialise both the model as well as the chain itself. I think the workflow you're looking for could be something like this, perhaps? # 1. Define a model
@model function f(data)
...
end
#2. 'Fit' the model
model = f(data)
#3. Sample from it
chain = sample(model, NUTS(), 1000)
#4. Save both the fitted model and the chain to disk
save(model, "model")
save(chain, "chain") And then in a different file: # 1. Load the fitted model and the chain
model = load(model)
chain = load(chain)
# 2. 'Refit' to some other data
new_model = update(model, new_data)
# 3. Run predictions
preds = predict(new_model, chain) The I know the pseudocode doesn't look quite so different from what you suggested and it might seem like I'm splitting hairs, but I just wanted to be clear about the exact interface we want to work towards :) |
Ah, just writing that all out made me realise that I've basically repeated what you've already said. In that case, I guess you should consider the above comment as a request for you to check that I have correctly understood it, rather than a clarification for you :) |
The issue is that it currently doesn't work if the model function is not available in the workspace, for instance if the model is loaded and stored within a dictionary or a list, which is unfortunate given that it seems like all the necessary information should be contained within the "fitted" model object (by that I mean the model function applied on data) Basically can we remove the need to keep depending on the original model function and pull the necessary information from the fitted model when running predictions? |
This isn't possible in the way you describe, unfortunately 😕 Models are Julia code, and they can depend on arbitrary Julia code. This is, arguably, one of the selling points of Turing.jl:) But this means that you cannot save a Turing.jl model to disk without also being explicit about its dependencies. It miiiight be possible to something like compile the model into a binary and re-use that once static compilation becomes more of a thing in Julia, but highly doubt this is possible at this moment. However, it's "easy enough" to set up a custom solution that does what you want by just putting each model and what it needs into it's own file and then call |
@torfjelde I was thinking it might still be useful to expose a convenience function that does exactly that custom solution / defines a particular way to package the model together with the underlying methods? 😄 |
But this seems difficult to do without something like static compilation, no? The |
Currently to generate predictions one has to refit the model on
missing
data, which requires having access to the model object.It would be quite convenient to be able to update the data of a fitted model using
update()
(à-la-R), which would allow more flexibility (my use case is that I'm running and saving models locally, and then running some predictions in another step, and currently I need to save the model, the fitted version and the posteriors which is a bit cumbersome).Would that make sense in Turing? Thanks!
Related, from #2309
The text was updated successfully, but these errors were encountered: