def test_base_terms(name, args): term = getattr(terms, name)(**args) pyterm = getattr(pyterms, name)(**args) compare_terms(term, pyterm) compare_terms(terms.TermDiff(term), pyterms.TermDiff(pyterm)) compare_terms(terms.TermConvolution(term, 0.5), pyterms.TermConvolution(pyterm, 0.5)) term0 = terms.SHOTerm(S0=1.0, w0=0.5, Q=1.5) pyterm0 = pyterms.SHOTerm(S0=1.0, w0=0.5, Q=1.5) compare_terms(term + term0, pyterm + pyterm0) compare_terms(term * term0, pyterm * pyterm0) term0 = terms.SHOTerm(S0=1.0, w0=0.5, Q=0.2) pyterm0 = pyterms.SHOTerm(S0=1.0, w0=0.5, Q=0.2) compare_terms(term + term0, pyterm + pyterm0) compare_terms(term * term0, pyterm * pyterm0)
def test_citations(data): pm = pytest.importorskip("pymc3") x, diag, y, t = data with pm.Model() as model: term = terms.SHOTerm(S0=1.0, w0=0.5, Q=3.0) gp = GaussianProcess(term, t=x, diag=diag) gp.marginal("obs", observed=y) assert model.__citations__["celerite2"] == CITATIONS
def test_marginal(data): pm = pytest.importorskip("pymc3") x, diag, y, t = data with pm.Model() as model: term = terms.SHOTerm(S0=1.0, w0=0.5, Q=3.0) gp = GaussianProcess(term, t=x, diag=diag) gp.marginal("obs", observed=y) assert np.allclose( model.fastfn(model.logpt)(model.test_point), model.fastfn(gp.log_likelihood(y))(model.test_point), )
def test_errors(data): x, diag, y, t = data term = terms.SHOTerm(S0=1.0, w0=0.5, Q=3.0) gp = GaussianProcess(term) # Need to call compute first with pytest.raises(RuntimeError): gp.log_likelihood(y) # Sorted with pytest.raises(AssertionError): gp.compute(x[::-1], diag=diag) gp._d.eval() # 1D with pytest.raises(ValueError): gp.compute(np.tile(x[:, None], (1, 5)), diag=diag) # Only one of diag and yerr with pytest.raises(ValueError): gp.compute(x, diag=diag, yerr=np.sqrt(diag)) # Not positive definite with pytest.raises(celerite2.backprop.LinAlgError): gp.compute(x, diag=-10 * diag) gp._d.eval() # Not positive definite with `quiet` gp.compute(x, diag=-10 * diag, quiet=True) ld = gp._log_det.eval() assert np.isinf(ld) assert ld < 0 # Compute correctly gp.compute(x, diag=diag) gp.log_likelihood(y).eval() # Dimension mismatch with pytest.raises(ValueError): gp.log_likelihood(y[:-1]).eval() with pytest.raises(ValueError): gp.log_likelihood(np.tile(y[:, None], (1, 5))) with pytest.raises(ValueError): gp.predict(y, t=np.tile(t[:, None], (1, 5)))
# + import pymc3 as pm import celerite2.theano from celerite2.theano import terms as theano_terms with pm.Model() as model: mean = pm.Normal("mean", mu=0.0, sigma=prior_sigma) jitter = pm.Lognormal("jitter", mu=0.0, sigma=prior_sigma) sigma1 = pm.Lognormal("sigma1", mu=0.0, sigma=prior_sigma) rho1 = pm.Lognormal("rho1", mu=0.0, sigma=prior_sigma) tau = pm.Lognormal("tau", mu=0.0, sigma=prior_sigma) term1 = theano_terms.SHOTerm(sigma=sigma1, rho=rho1, tau=tau) sigma2 = pm.Lognormal("sigma2", mu=0.0, sigma=prior_sigma) rho2 = pm.Lognormal("rho2", mu=0.0, sigma=prior_sigma) term2 = theano_terms.SHOTerm(sigma=sigma2, rho=rho2, Q=0.25) kernel = term1 + term2 gp = celerite2.theano.GaussianProcess(kernel, mean=mean) gp.compute(t, diag=yerr**2 + jitter, quiet=True) gp.marginal("obs", observed=y) pm.Deterministic("psd", kernel.get_psd(omega)) trace = pm.sample( tune=1000, draws=1000,
import pymc3 as pm import celerite2.theano from celerite2.theano import terms as theano_terms with pm.Model() as model: mean = pm.Normal("mean", mu=0.0, sigma=prior_sigma) log_jitter = pm.Normal("log_jitter", mu=0.0, sigma=prior_sigma) log_sigma1 = pm.Normal("log_sigma1", mu=0.0, sigma=prior_sigma) log_rho1 = pm.Normal("log_rho1", mu=0.0, sigma=prior_sigma) log_tau = pm.Normal("log_tau", mu=0.0, sigma=prior_sigma) term1 = theano_terms.SHOTerm( sigma=pm.math.exp(log_sigma1), rho=pm.math.exp(log_rho1), tau=pm.math.exp(log_tau), ) log_sigma2 = pm.Normal("log_sigma2", mu=0.0, sigma=prior_sigma) log_rho2 = pm.Normal("log_rho2", mu=0.0, sigma=prior_sigma) term2 = theano_terms.SHOTerm(sigma=pm.math.exp(log_sigma2), rho=pm.math.exp(log_rho2), Q=0.25) kernel = term1 + term2 gp = celerite2.theano.GaussianProcess(kernel, mean=mean) gp.compute(t, diag=yerr**2 + pm.math.exp(log_jitter), quiet=True) gp.marginal("obs", observed=y) pm.Deterministic("psd", kernel.get_psd(omega))