def _lnlike(r, a, b, c, n, i, p, t, flux, data_cov): gp = StarryProcess( r=r, a=a, b=b, c=c, n=n, marginalize_over_inclination=marginalize_over_inclination, normalized=False, ) return gp.log_likelihood(t, flux, data_cov, p=p, i=i)
def test_profile_marg(gradient, profile, ydeg=15, npts=1000): # Free parameters r = tt.dscalar() a = tt.dscalar() b = tt.dscalar() c = tt.dscalar() n = tt.dscalar() p = tt.dscalar() t = tt.dvector() flux = tt.dvector() data_cov = tt.dscalar() # Compute the mean and covariance gp = StarryProcess( r=r, a=a, b=b, c=c, n=n, marginalize_over_inclination=True ) # Compile the function if gradient: g = lambda f, x: tt.grad(f, x) else: g = lambda f, x: f func = theano.function( [r, a, b, c, n, p, t, flux, data_cov], [ g(gp.log_likelihood(t, flux, data_cov, p=p), a) ], # wrt a for definiteness profile=profile, ) # Run it t = np.linspace(0, 1, npts) flux = np.random.randn(npts) data_cov = 1.0 run = lambda: func( defaults["r"], defaults["a"], defaults["b"], defaults["c"], defaults["n"], defaults["p"], t, flux, data_cov, ) if profile: # Profile the full function run() print(func.profile.summary()) else: # Time the execution number = 100 time = timeit.timeit(run, number=number) / number print("time elapsed: {:.4f} s".format(time)) if (gradient and time > 0.2) or (not gradient and time > 0.1): warnings.warn("too slow! ({:.4f} s)".format(time))
def test_likelihood(): t = np.linspace(0, 1, 100) flux = np.random.randn(100) sp = StarryProcess(r=10) + StarryProcess(r=20) ll = sp.log_likelihood(t, flux, 1.0).eval() assert np.isfinite(ll)