Skip to content

Commit

Permalink
save gp hyper par for each iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirky committed Sep 23, 2020
1 parent bade33b commit a08e859
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions approxposterior/approx.py
Expand Up @@ -361,6 +361,7 @@ def run(self, m=10, nmax=2, seed=None, timing=False, verbose=True,
if cache:
np.savez(str(runName) + "APFModelCache.npz",
theta=self.theta, y=self.y)
self.gpPar = list()

# Set RNG seed?
if seed is not None:
Expand Down Expand Up @@ -424,11 +425,10 @@ def run(self, m=10, nmax=2, seed=None, timing=False, verbose=True,
if timing:
self.trainingTime.append(time.time() - start)

# If cache, save current GP hyperparameters
if cache:
np.savez(str(runName) + "APGP.npz",
gpParamNames=self.gp.get_parameter_names(),
gpParamValues=self.gp.get_parameter_vector())
gpParamNames=self.gp.get_parameter_names(),
gpParamValues=self.gpPar)

# 3) GP updated: run MCMC sampler to obtain new posterior conditioned
# on {theta_n, log(L_t*prior)}. Use emcee to obtain posterior dist.
Expand Down Expand Up @@ -703,6 +703,11 @@ def findNextPoint(self, theta0=None, computeLnLike=True, seed=None,
# Always need to compute the covariance matrix when we find
# a new theta
currentHype = self.gp.get_parameter_vector()
if verbose:
print('hyperparameters', currentHype)
if cache:
self.gpPar.append(currentHype)

self.gp = george.GP(kernel=self.gp.kernel, fit_mean=True,
mean=self.gp.mean,
white_noise=self.gp.white_noise,
Expand Down

0 comments on commit a08e859

Please sign in to comment.