mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-24 20:36:23 +02:00
[fix #380] reloading ep
This commit is contained in:
parent
7da7460377
commit
e4d76a133a
2 changed files with 29 additions and 2 deletions
|
|
@ -51,7 +51,7 @@ class EP(EPBase, ExactGaussianInference):
|
|||
if K is None:
|
||||
K = kern.K(X)
|
||||
|
||||
if self._ep_approximation is None:
|
||||
if getattr(self, '_ep_approximation', None) is None:
|
||||
#if we don't yet have the results of runnign EP, run EP and store the computed factors in self._ep_approximation
|
||||
mu, Sigma, mu_tilde, tau_tilde, Z_tilde = self._ep_approximation = self.expectation_propagation(K, Y, likelihood, Y_metadata)
|
||||
else:
|
||||
|
|
@ -159,7 +159,7 @@ class EPDTC(EPBase, VarDTC):
|
|||
else:
|
||||
Kmn = psi1.T
|
||||
|
||||
if self._ep_approximation is None:
|
||||
if getattr(self, '_ep_approximation', None) is None:
|
||||
mu, Sigma, mu_tilde, tau_tilde, Z_tilde = self._ep_approximation = self.expectation_propagation(Kmm, Kmn, Y, likelihood, Y_metadata)
|
||||
else:
|
||||
mu, Sigma, mu_tilde, tau_tilde, Z_tilde = self._ep_approximation
|
||||
|
|
|
|||
27
README.md
27
README.md
|
|
@ -84,6 +84,33 @@ If you're having trouble installing GPy via `pip install GPy` here is a probable
|
|||
[](https://pypi.python.org/pypi/GPy)
|
||||
[](https://pypi.python.org/pypi/GPy)
|
||||
|
||||
# Saving models in a consistent way across versions:
|
||||
|
||||
As pickle is inconsistent across python versions and heavily dependent on class structure, it behaves inconsistent across versions.
|
||||
Pickling as meant to serialize models within the same environment, and not to store models on disk to be used later on.
|
||||
|
||||
To save a model it is best to save the m.param_array of it to disk (using numpy’s np.save).
|
||||
Additionally, you save the script, which creates the model.
|
||||
In this script you can create the model using initialize=False as a keyword argument and with the data loaded as normal.
|
||||
You then set the model parameters by setting m.param_array[:] = loaded_params as the previously saved parameters.
|
||||
Then you initialize the model by m.initialize_parameter(), which will make the model usable.
|
||||
Be aware that up to this point the model is in an inconsistent state and cannot be used to produce any results.
|
||||
|
||||
```python
|
||||
# let X, Y be data loaded above
|
||||
# Model creation:
|
||||
m = GPy.models.GPRegression(X, Y)
|
||||
m.optimize()
|
||||
# 1: Saving a model:
|
||||
np.save('model_save.npy', m.param_array)
|
||||
# 2: loading a model
|
||||
# Model creation, without initialization:
|
||||
m = GPy.models(GPRegression(X,Y,initialize=False)
|
||||
m[:] = np.load('model_save.npy')
|
||||
m.initialize_parameter()
|
||||
print m
|
||||
```
|
||||
|
||||
## Running unit tests:
|
||||
|
||||
Ensure nose is installed via pip:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue