Skip to content

Instantly share code, notes, and snippets.

@dfm
Created July 16, 2019 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfm/9d83404ce5282cc01a3bb25fd3d5e558 to your computer and use it in GitHub Desktop.
Save dfm/9d83404ce5282cc01a3bb25fd3d5e558 to your computer and use it in GitHub Desktop.
import pymc3 as pm
import numpy as np
import exoplanet as xo
import theano.tensor as tt
with pm.Model() as simple_model:
period = pm.Flat("period", testval=10.0)
nu = pm.Flat("nu", testval=15)
phi = xo.distributions.Angle("phi")
logasini = pm.Uniform("logasini", lower=np.log(1), upper=np.log(1000),
testval=np.log(10))
drift = pm.Normal("drift", mu=0, sd=1.0)
M = 2.0 * np.pi * time / period - phi
factor = 2. * np.pi * nu
A = factor * (1 + drift) * time
B = -factor * (tt.exp(logasini) / 86400) * tt.sin(M)
sinarg = tt.sin(A+B)
cosarg = tt.cos(A+B)
DT = tt.stack((sinarg, cosarg, tt.ones_like(sinarg)))
w = tt.slinalg.solve(tt.dot(DT, DT.T), tt.dot(DT, mag))
pm.Deterministic("w", w)
pm.Deterministic("phase", tt.arctan2(w[1], w[0]))
lc_model = tt.dot(DT.T, w)
pm.Normal("obs", mu=lc_model, observed=mag)
fit_params = [v for v in simple_model.vars if v.name not in ["period", "nu"]]
def run_fit(p, nu):
with simple_model:
start = dict(simple_model.test_point)
start["period"] = p
start["nu"] = nu
point, info = xo.optimize(start, vars=fit_params, return_info=True, verbose=False)
return -info.fun, point
periods = np.exp(np.linspace(np.log(100), np.log(300), 50))
results = []
for f in freq:
results.append([run_fit(p, f) for p in tqdm.tqdm(periods)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment