From dd5e819c04a33e4e3e7c563cdd500b0cf89e0fbe Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Thu, 19 Sep 2019 16:32:53 -0400 Subject: [PATCH] fixing normaliztion of vaneylen distribution --- exoplanet/distributions/eccentricity.py | 2 +- exoplanet/distributions/eccentricity_test.py | 44 +++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/exoplanet/distributions/eccentricity.py b/exoplanet/distributions/eccentricity.py index de79bb9d2..062c2f5cc 100644 --- a/exoplanet/distributions/eccentricity.py +++ b/exoplanet/distributions/eccentricity.py @@ -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 ) diff --git a/exoplanet/distributions/eccentricity_test.py b/exoplanet/distributions/eccentricity_test.py index 0dc35eb34..5c75ea90e 100644 --- a/exoplanet/distributions/eccentricity_test.py +++ b/exoplanet/distributions/eccentricity_test.py @@ -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 @@ -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) @@ -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