def lnlike(params, bjd, mag, magerr): a_gp, l_gp = np.exp(params[:2]) k1 = kernels.ExpSquaredKernel(l_gp) kernel = a_gp * k1 gp = george.GP(kernel) #, solver=george.HODLRSolver) try: gp.compute(bjd, magerr) except (ValueError, np.linalg.LinAlgError): return 1e26 model = lcmodel.get_lc1(params[2:], bjd) return gp.lnlikelihood(mag - model, quiet=True)
def get_model(self): '''Compute the QP GP model after running the mcmc.''' if self.GPonly: # Compute GP model a_gp, l_gp, G_gp, P_gp = self.hyperparams k1 = kernels.ExpSquaredKernel(l_gp) k2 = kernels.ExpSine2Kernel(G_gp, P_gp) kernel = a_gp * k1 * k2 gp = george.GP(kernel) gp.compute(self.bjdtrimbin, self.emagtrimbin) x = np.linspace(min(self.bjd), max(self.bjd), 5e2) mu, cov = gp.predict(self.magtrimbin, x) std = np.sqrt(np.diag(cov)) xpred = np.linspace(max(self.bjd), max(self.bjd) + 600, 1e3) mupred, covpred = gp.predict(self.magtrimbin, xpred) stdpred = np.sqrt(np.diag(covpred)) else: # Compute GP model a_gp, l_gp = self.hyperparams k1 = kernels.ExpSquaredKernel(l_gp) kernel = a_gp * k1 gp = george.GP(kernel, solver=george.HODLRSolver) gp.compute(self.bjdtrimbin, self.emagtrimbin) x = np.linspace(min(self.bjd), max(self.bjd), 3e2) #mu, cov = gp.predict(self.magtrimbin, x) modelsmall = lcmodel.get_lc1(self.mcmcparams, self.bjdtrimbin) modellarge = lcmodel.get_lc1(self.mcmcparams, x) samples = gp.sample_conditional(self.magtrimbin - modelsmall, x, size=100) mu = np.mean(samples, axis=0) + modellarge std = np.std(samples, axis=0) + modellarge self.modelbjd = x self.model = mu self.modelerr = std self.predbjd = xpred self.predmodel = mupred self.predmodelerr = stdpred
def get_model(self): '''Compute the QP GP model after running the mcmc.''' if self.GPonly: # Compute GP model a_gp, l_gp, G_gp, P_gp = self.hyperparams k1 = kernels.ExpSquaredKernel(l_gp) k2 = kernels.ExpSine2Kernel(G_gp, P_gp) kernel = a_gp*k1*k2 gp = george.GP(kernel) gp.compute(self.bjdtrimbin, self.emagtrimbin) x = np.linspace(min(self.bjd), max(self.bjd), 5e2) mu, cov = gp.predict(self.magtrimbin, x) std = np.sqrt(np.diag(cov)) xpred = np.linspace(max(self.bjd), max(self.bjd)+600, 1e3) mupred, covpred = gp.predict(self.magtrimbin, xpred) stdpred = np.sqrt(np.diag(covpred)) else: # Compute GP model a_gp, l_gp = self.hyperparams k1 = kernels.ExpSquaredKernel(l_gp) kernel = a_gp*k1 gp = george.GP(kernel, solver=george.HODLRSolver) gp.compute(self.bjdtrimbin, self.emagtrimbin) x = np.linspace(min(self.bjd), max(self.bjd), 3e2) #mu, cov = gp.predict(self.magtrimbin, x) modelsmall = lcmodel.get_lc1(self.mcmcparams, self.bjdtrimbin) modellarge = lcmodel.get_lc1(self.mcmcparams, x) samples = gp.sample_conditional(self.magtrimbin - modelsmall, x, size=100) mu = np.mean(samples, axis=0) + modellarge std = np.std(samples, axis=0) + modellarge self.modelbjd = x self.model = mu self.modelerr = std self.predbjd = xpred self.predmodel = mupred self.predmodelerr = stdpred