Skip to content
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

Model storage and persistence #126

Open
mhangaard opened this issue Nov 26, 2019 · 3 comments
Open

Model storage and persistence #126

mhangaard opened this issue Nov 26, 2019 · 3 comments

Comments

@mhangaard
Copy link

What would be good ways to store and persist a GP optimized with GP.jl? The purpose would be to make predictions with mean and standard deviation at a later time than training.

@thomaspinder
Copy link
Member

Hi @mhangaard, this is something I've thought about before using BSON.jl.

It's certainly something that would be useful in the package, however, I'm not sure I personally have the time currently, so I've left it as an open issue.

@maximerischard
Copy link
Contributor

If you keep hold of the training data and the kernel specification, all you need is the vector of parameters output by get_params. Then you would just re-create the GP object and feed the stored parameters to set_params!. Anything beyond that (such as some kind of serialisation scheme for the kernel and mean specification) would need some serious thought.

@thomaspinder
Copy link
Member

One option for this @mhangaard is to use JLD.jl. A minimal working example would look something like

using Random, Distributions, GaussianProcesses, JLD
Random.seed!(13579)               # Set the seed using the 'Random' package
n = 20;                           # number of training points
x = 2π * rand(n);                 # predictors
y = sin.(x) + 0.05*randn(n);      # regressors

# Select mean and covariance function
mZero = MeanZero()                  # Zero mean function
kern = SE(0.0,0.0)                  # Sqaured exponential kernel
logObsNoise = -1.0                  # log standard deviation of observation noise
gp = GP(x,y,mZero,kern,logObsNoise) # Fit the GP
optimize!(gp) #Optimise the parameters

From which the model can be saved by save("gp_model.jld", "gp", gp) and consequently loaded back in by gp = load("gp_model.jld", "gp").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants