mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
Merge branch devel into gradientsxx
This commit is contained in:
commit
4efb92c554
2 changed files with 37 additions and 2 deletions
|
|
@ -40,6 +40,14 @@ class EPBase(object):
|
|||
# TODO: update approximation in the end as well? Maybe even with a switch?
|
||||
pass
|
||||
|
||||
def __setstate__(self, state):
|
||||
super(EPBase, self).__setstate__(state[0])
|
||||
self.epsilon, self.eta, self.delta = state[1]
|
||||
self.reset()
|
||||
|
||||
def __getstate__(self):
|
||||
return [super(EPBase, self).__getstate__() , [self.epsilon, self.eta, self.delta]]
|
||||
|
||||
class EP(EPBase, ExactGaussianInference):
|
||||
def inference(self, kern, X, likelihood, Y, mean_function=None, Y_metadata=None, precision=None, K=None):
|
||||
if self.always_reset:
|
||||
|
|
@ -51,7 +59,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 +167,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