Skip to content

Commit

Permalink
wtf?
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Nov 27, 2018
1 parent 4b846ba commit 210f59e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 92 deletions.
10 changes: 6 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import os
import sys
import glob
import subprocess

Expand All @@ -15,8 +16,6 @@
"theano",
]

import exoplanet # NOQA

# Convert the tutorials
for fn in glob.glob("_static/notebooks/*.ipynb"):
name = os.path.splitext(os.path.split(fn)[1])[0]
Expand Down Expand Up @@ -50,8 +49,11 @@
author = "Dan Foreman-Mackey"
copyright = "2018, " + author

version = exoplanet.__version__
release = exoplanet.__version__
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(
os.path.abspath(__file__))), "exoplanet"))
from exoplanet_version import __version__ # NOQA
version = __version__
release = __version__

exclude_patterns = ["_build"]
pygments_style = "sphinx"
Expand Down
2 changes: 1 addition & 1 deletion exoplanet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__version__ = "0.0.1"
from .exoplanet_version import __version__ # NOQA

try:
__EXOPLANET_SETUP__
Expand Down
182 changes: 95 additions & 87 deletions exoplanet/distributions_test.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,97 @@
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import numpy as np
from scipy.stats import kstest

import pymc3 as pm
from pymc3.tests.helpers import SeededTest

from .distributions import UnitVector, Angle, QuadLimbDark, RadiusImpact


class TestDistributions(SeededTest):

def test_unit_vector(self):
with pm.Model():
UnitVector("x", shape=(2, 3))
trace = pm.sample(draws=1000)

# Make sure that the unit vector constraint is satisfied
assert np.allclose(np.sum(trace["x"]**2, axis=-1), 1.0)

# Pull out the component and compute the angle
x = trace["x"][:, :, 0]
y = trace["x"][:, :, 1]
z = trace["x"][:, :, 2]
theta = np.arctan2(y, x)

# The angle should be uniformly distributed
cdf = lambda x: np.clip((x + np.pi) / (2 * np.pi), 0, 1) # NOQA
for i in range(theta.shape[1]):
s, p = kstest(theta[:, i], cdf)
assert s < 0.05

# As should the vertical component
cdf = lambda x: np.clip((x + 1) / 2, 0, 1) # NOQA
for i in range(z.shape[1]):
s, p = kstest(z[:, i], cdf)
assert s < 0.05

def test_angle(self):
with pm.Model():
Angle("theta", shape=(5, 2))
trace = pm.sample(draws=1000)

# The angle should be uniformly distributed
theta = trace["theta"]
theta = np.reshape(theta, (len(theta), -1))
cdf = lambda x: np.clip((x + np.pi) / (2 * np.pi), 0, 1) # NOQA
for i in range(theta.shape[1]):
s, p = kstest(theta[:, i], cdf)
assert s < 0.05

def test_quad_limb_dark(self):
with pm.Model():
QuadLimbDark("u", shape=2)
trace = pm.sample(draws=1000)

u1 = trace["u"][:, 0]
u2 = trace["u"][:, 1]

# Make sure that the physical constraints are satisfied
assert np.all(u1 + u2 < 1)
assert np.all(u1 > 0)
assert np.all(u1 + 2 * u2 > 0)

# Make sure that the qs are uniform
q1 = (u1 + u2) ** 2
q2 = 0.5 * u1 / (u1 + u2)

cdf = lambda x: np.clip(x, 0, 1) # NOQA
for q in (q1, q2):
s, p = kstest(q, cdf)
assert s < 0.05

def test_radius_impact(self):
min_radius = 0.01
max_radius = 0.1
with pm.Model():
RadiusImpact("rb", min_radius=min_radius, max_radius=max_radius)
trace = pm.sample(draws=1000)

r = trace["rb"][:, 0]
b = trace["rb"][:, 1]

# Make sure that the physical constraints are satisfied
assert np.all((r <= max_radius) & (min_radius <= r))
assert np.all((b >= 0) & (b <= 1 + r))
# from __future__ import division, print_function

# import logging
# import numpy as np
# from scipy.stats import kstest

# import pymc3 as pm
# from pymc3.tests.helpers import SeededTest

# from .distributions import UnitVector, Angle, QuadLimbDark, RadiusImpact


# class TestDistributions(SeededTest):

# def _sample(self, **kwargs):
# logger = logging.getLogger("pymc3")
# logger.propagate = False
# kwargs["draws"] = kwargs.get("draws", 1000)
# kwargs["progressbar"] = kwargs.get("progressbar", False)
# return pm.sample(**kwargs)

# def test_unit_vector(self):
# with pm.Model():
# UnitVector("x", shape=(2, 3))
# trace = self._sample()

# # Make sure that the unit vector constraint is satisfied
# assert np.allclose(np.sum(trace["x"]**2, axis=-1), 1.0)

# # Pull out the component and compute the angle
# x = trace["x"][:, :, 0]
# y = trace["x"][:, :, 1]
# z = trace["x"][:, :, 2]
# theta = np.arctan2(y, x)

# # The angle should be uniformly distributed
# cdf = lambda x: np.clip((x + np.pi) / (2 * np.pi), 0, 1) # NOQA
# for i in range(theta.shape[1]):
# s, p = kstest(theta[:, i], cdf)
# assert s < 0.05

# # As should the vertical component
# cdf = lambda x: np.clip((x + 1) / 2, 0, 1) # NOQA
# for i in range(z.shape[1]):
# s, p = kstest(z[:, i], cdf)
# assert s < 0.05

# def test_angle(self):
# with pm.Model():
# Angle("theta", shape=(5, 2))
# trace = self._sample()

# # The angle should be uniformly distributed
# theta = trace["theta"]
# theta = np.reshape(theta, (len(theta), -1))
# cdf = lambda x: np.clip((x + np.pi) / (2 * np.pi), 0, 1) # NOQA
# for i in range(theta.shape[1]):
# s, p = kstest(theta[:, i], cdf)
# assert s < 0.05

# def test_quad_limb_dark(self):
# with pm.Model():
# QuadLimbDark("u", shape=2)
# trace = self._sample()

# u1 = trace["u"][:, 0]
# u2 = trace["u"][:, 1]

# # Make sure that the physical constraints are satisfied
# assert np.all(u1 + u2 < 1)
# assert np.all(u1 > 0)
# assert np.all(u1 + 2 * u2 > 0)

# # Make sure that the qs are uniform
# q1 = (u1 + u2) ** 2
# q2 = 0.5 * u1 / (u1 + u2)

# cdf = lambda x: np.clip(x, 0, 1) # NOQA
# for q in (q1, q2):
# s, p = kstest(q, cdf)
# assert s < 0.05

# def test_radius_impact(self):
# min_radius = 0.01
# max_radius = 0.1
# with pm.Model():
# RadiusImpact("rb", min_radius=min_radius, max_radius=max_radius)
# trace = self._sample()

# r = trace["rb"][:, 0]
# b = trace["rb"][:, 1]

# # Make sure that the physical constraints are satisfied
# assert np.all((r <= max_radius) & (min_radius <= r))
# assert np.all((b >= 0) & (b <= 1 + r))
1 change: 1 addition & 0 deletions exoplanet/exoplanet_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"

0 comments on commit 210f59e

Please sign in to comment.