Skip to content

Commit

Permalink
fixing normaliztion of vaneylen distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Sep 19, 2019
1 parent f41125b commit dd5e819
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion exoplanet/distributions/eccentricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def vaneylen19(name, fixed=False, multi=False, model=None, **kwargs):
"frac", mu=frac_mu, sd=frac_sd, testval=frac_mu
)

gauss = pm.Normal.dist(mu=0, sd=sigma_gauss)
gauss = pm.HalfNormal.dist(sigma=sigma_gauss)
rayleigh = pm.Weibull.dist(
alpha=2, beta=np.sqrt(2) * sigma_rayleigh
)
Expand Down
44 changes: 34 additions & 10 deletions exoplanet/distributions/eccentricity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import numpy as np
from scipy.stats import kstest, beta
from scipy.stats import kstest, beta, halfnorm, rayleigh

from .base_test import _Base
from .eccentricity import kipping13, vaneylen19
Expand Down Expand Up @@ -64,15 +64,7 @@ def test_kipping13_short(self):
s, p = kstest(ecc, cdf)
assert s < 0.05

@pytest.mark.parametrize(
"kwargs",
[
dict(),
dict(fixed=True),
dict(multi=True),
dict(fixed=True, multi=True),
],
)
@pytest.mark.parametrize("kwargs", [dict(), dict(multi=True)])
def test_vaneylen19(self, kwargs):
with self._model() as model:
dist = vaneylen19("ecc", shape=(5, 2), **kwargs)
Expand All @@ -91,3 +83,35 @@ def test_vaneylen19(self, kwargs):

ecc = trace["ecc"]
assert np.all((0 <= ecc) & (ecc <= 1))

def test_vaneylen19_single(self):
with self._model():
vaneylen19("ecc", fixed=True, multi=False, shape=2)
trace = self._sample()

ecc = trace["ecc"].flatten()
assert np.all((0 <= ecc) & (ecc <= 1))

f = 0.76
cdf = lambda x: ( # NOQA
(1 - f) * halfnorm.cdf(x, scale=0.049)
+ f * rayleigh.cdf(x, scale=0.26)
)
s, p = kstest(ecc, cdf)
assert s < 0.05

def test_vaneylen19_multi(self):
with self._model():
vaneylen19("ecc", fixed=True, multi=True, shape=3)
trace = self._sample()

ecc = trace["ecc"].flatten()
assert np.all((0 <= ecc) & (ecc <= 1))

f = 0.08
cdf = lambda x: ( # NOQA
(1 - f) * halfnorm.cdf(x, scale=0.049)
+ f * rayleigh.cdf(x, scale=0.26)
)
s, p = kstest(ecc, cdf)
assert s < 0.05

0 comments on commit dd5e819

Please sign in to comment.