Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b57744
commit fe01657
Showing
7 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import binom | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
# NOTE: since Tensorflow has no special functions, the values here are | ||
# only an approximation | ||
assert np.allclose(val_ed.eval(), val_true, atol=1e-4) | ||
|
||
def _test_logpmf(x, n, p): | ||
xtf = tf.constant(x) | ||
val_true = stats.binom.logpmf(x, n, p) | ||
_assert_eq(binom.logpmf(xtf, n, p), val_true) | ||
_assert_eq(binom.logpmf(xtf, tf.constant(n), tf.constant(p)), val_true) | ||
_assert_eq(binom.logpmf(xtf, tf.constant([n]), tf.constant([p])), val_true) | ||
|
||
def test_logpmf_int_scalar(): | ||
_test_logpmf(0, 1, 0.5) | ||
_test_logpmf(1, 2, 0.75) | ||
|
||
def test_logpmf_float_scalar(): | ||
_test_logpmf(0.0, 1, 0.5) | ||
_test_logpmf(1.0, 2, 0.75) | ||
|
||
def test_logpmf_int_1d(): | ||
_test_logpmf([0, 1, 0], 1, 0.5) | ||
_test_logpmf([1, 0, 0], 1, 0.75) | ||
|
||
def test_logpmf_float_1d(): | ||
_test_logpmf([0.0, 1.0, 0.0], 1, 0.5) | ||
_test_logpmf([1.0, 0.0, 0.0], 1, 0.75) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import chi2 | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
# NOTE: since Tensorflow has no special functions, the values here are | ||
# only an approximation | ||
assert np.allclose(val_ed.eval(), val_true, atol=1e-4) | ||
|
||
def _test_logpdf(x, df): | ||
xtf = tf.constant(x) | ||
val_true = stats.chi2.logpdf(x, df) | ||
_assert_eq(chi2.logpdf(xtf, df), val_true) | ||
_assert_eq(chi2.logpdf(xtf, tf.constant(df)), val_true) | ||
_assert_eq(chi2.logpdf(xtf, tf.constant([df])), val_true) | ||
|
||
def test_logpdf_scalar(): | ||
_test_logpdf(0.2, df=2) | ||
_test_logpdf(0.623, df=2) | ||
|
||
def test_logpdf_1d(): | ||
_test_logpdf([0.1, 1.0, 0.58, 2.3], df=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import geom | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
assert np.allclose(val_ed.eval(), val_true) | ||
|
||
def _test_logpmf(x, p): | ||
xtf = tf.constant(x) | ||
val_true = stats.geom.logpmf(x, p) | ||
_assert_eq(geom.logpmf(xtf, p), val_true) | ||
_assert_eq(geom.logpmf(xtf, tf.constant(p)), val_true) | ||
_assert_eq(geom.logpmf(xtf, tf.constant([p])), val_true) | ||
|
||
def test_logpmf_int_scalar(): | ||
_test_logpmf(1, 0.5) | ||
_test_logpmf(2, 0.75) | ||
|
||
def test_logpmf_float_scalar(): | ||
_test_logpmf(1.0, 0.5) | ||
_test_logpmf(2.0, 0.75) | ||
|
||
def test_logpmf_int_1d(): | ||
_test_logpmf([1, 5, 3], 0.5) | ||
_test_logpmf([2, 8, 2], 0.75) | ||
|
||
def test_logpmf_float_1d(): | ||
_test_logpmf([1.0, 5.0, 3.0], 0.5) | ||
_test_logpmf([2.0, 8.0, 2.0], 0.75) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import lognorm | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
assert np.allclose(val_ed.eval(), val_true) | ||
|
||
def _test_logpdf(x, s=1): | ||
xtf = tf.constant(x) | ||
val_true = stats.lognorm.logpdf(x, s) | ||
_assert_eq(lognorm.logpdf(xtf, s), val_true) | ||
_assert_eq(lognorm.logpdf(xtf, tf.constant(s)), val_true) | ||
_assert_eq(lognorm.logpdf(xtf, tf.constant([s])), val_true) | ||
|
||
def test_logpdf_scalar(): | ||
_test_logpdf(2.0) | ||
_test_logpdf(0.623) | ||
|
||
def test_logpdf_1d(): | ||
_test_logpdf([2.0, 1.0, 0.58, 2.3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import nbinom | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
# NOTE: since Tensorflow has no special functions, the values here are | ||
# only an approximation | ||
assert np.allclose(val_ed.eval(), val_true, atol=1e-4) | ||
|
||
def _test_logpmf(x, n, p): | ||
xtf = tf.constant(x) | ||
val_true = stats.nbinom.logpmf(x, n, p) | ||
_assert_eq(nbinom.logpmf(xtf, n, p), val_true) | ||
_assert_eq(nbinom.logpmf(xtf, tf.constant(n), tf.constant(p)), val_true) | ||
_assert_eq(nbinom.logpmf(xtf, tf.constant(n), tf.constant([p])), val_true) | ||
_assert_eq(nbinom.logpmf(xtf, tf.constant([n]), tf.constant(p)), val_true) | ||
_assert_eq(nbinom.logpmf(xtf, tf.constant([n]), tf.constant([p])), val_true) | ||
|
||
def test_logpmf_int_scalar(): | ||
_test_logpmf(1, 5, 0.5) | ||
_test_logpmf(2, 5, 0.75) | ||
|
||
def test_logpmf_float_scalar(): | ||
_test_logpmf(1.0, 5, 0.5) | ||
_test_logpmf(2.0, 5, 0.75) | ||
|
||
def test_logpmf_int_1d(): | ||
_test_logpmf([1, 5, 3], 5, 0.5) | ||
_test_logpmf([2, 8, 2], 5, 0.75) | ||
|
||
def test_logpmf_float_1d(): | ||
_test_logpmf([1.0, 5.0, 3.0], 5, 0.5) | ||
_test_logpmf([2.0, 8.0, 2.0], 5, 0.75) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.stats import uniform | ||
from scipy import stats | ||
|
||
sess = tf.Session() | ||
|
||
def _assert_eq(val_ed, val_true): | ||
with sess.as_default(): | ||
assert np.allclose(val_ed.eval(), val_true) | ||
|
||
def _test_logpdf(x, loc=0, scale=1): | ||
xtf = tf.constant(x) | ||
val_true = stats.uniform.logpdf(x, loc, scale) | ||
_assert_eq(uniform.logpdf(xtf, loc, scale), val_true) | ||
_assert_eq(uniform.logpdf(xtf, tf.constant(loc), tf.constant(scale)), val_true) | ||
_assert_eq(uniform.logpdf(xtf, tf.constant([loc]), tf.constant(scale)), val_true) | ||
_assert_eq(uniform.logpdf(xtf, tf.constant(loc), tf.constant([scale])), val_true) | ||
_assert_eq(uniform.logpdf(xtf, tf.constant([loc]), tf.constant([scale])), val_true) | ||
|
||
def test_logpdf_scalar(): | ||
_test_logpdf(0.3) | ||
_test_logpdf(0.7) | ||
|
||
_test_logpdf(1.3, loc=1.0, scale=1.0) | ||
_test_logpdf(1.7, loc=1.0, scale=1.0) | ||
|
||
_test_logpdf(2.3, loc=0.5, scale=5.0) | ||
_test_logpdf(2.7, loc=0.5, scale=5.0) | ||
|
||
_test_logpdf(5.3, loc=5.0, scale=0.5) | ||
_test_logpdf(5.1, loc=5.0, scale=0.5) | ||
|
||
def test_logpdf_1d(): | ||
_test_logpdf([0.5, 0.3, 0.8, 0.2], loc=0.1, scale=0.9) |