Skip to content

Commit

Permalink
Merge 194a3d1 into b85dd66
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbern committed Jul 7, 2019
2 parents b85dd66 + 194a3d1 commit 5460b0f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 91 deletions.
48 changes: 0 additions & 48 deletions convoys/gamma.py

This file was deleted.

2 changes: 1 addition & 1 deletion convoys/regression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import autograd
from autograd_gamma import gammainc
import emcee
import numpy
from scipy.special import gammaincinv
Expand All @@ -7,7 +8,6 @@
import scipy.optimize
import sys
import warnings
from convoys.gamma import gammainc


__all__ = ['Exponential',
Expand Down
3 changes: 0 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@ Full API documentation
.. automodule:: convoys.utils
:members:

.. automodule:: convoys.gamma
:members:

.. include:: afterwords.rst
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
packages=find_packages(),
install_requires=[
'autograd',
'autograd-gamma>=0.2.0',
'emcee',
'matplotlib>=2.0.0',
'pandas',
Expand Down
39 changes: 0 additions & 39 deletions test_convoys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import pandas
import pytest
import random
import scipy.special
import scipy.stats
matplotlib.use('Agg') # Needed for matplotlib to run in Travis
import convoys
import convoys.gamma
import convoys.plotting
import convoys.regression
import convoys.single
Expand All @@ -29,43 +27,6 @@ def generate_censored_data(N, E, C):
return B, T


def test_gammainc(k=2.5, x=4.2, g_eps=1e-7):
# Verify that function values are correct
assert convoys.gamma.gammainc(k, x) == pytest.approx(scipy.special.gammainc(k, x))

# Verify that it handles vectors
assert convoys.gamma.gammainc(k, numpy.array([1, 2, 3])) == \
pytest.approx(scipy.special.gammainc(k, numpy.array([1, 2, 3])))

# Verify the derivative wrt k
f_grad_k = autograd.grad(
lambda k: convoys.gamma.gammainc(k, x))
f_grad_k_numeric = (scipy.special.gammainc(k + g_eps, x) -
scipy.special.gammainc(k, x)) / g_eps
assert f_grad_k(k) == pytest.approx(f_grad_k_numeric)

# Verify the derivative wrt x
f_grad_x = autograd.grad(
lambda x: convoys.gamma.gammainc(k, x))
f_grad_x_numeric = (scipy.special.gammainc(k, x + g_eps) -
scipy.special.gammainc(k, x)) / g_eps
assert f_grad_x(x) == pytest.approx(f_grad_x_numeric)

# Verify the derivative wrt x when x is a vector
f_grad_x = autograd.grad(
lambda x: autograd.numpy.sum(convoys.gamma.gammainc(1.0, x)))
f_grad_x_correct = autograd.grad(
lambda x: autograd.numpy.sum(1.0 - autograd.numpy.exp(-x)))
xs = numpy.array([1., 2., 3.])
assert f_grad_x(xs) == pytest.approx(f_grad_x_correct(xs))

# Verify the derivative wrt k when x is a vector
xs = numpy.array([1., 2., 3.])
f_grad_k = autograd.grad(
lambda k: autograd.numpy.sum(convoys.gamma.gammainc(k, xs)))
assert f_grad_k(xs).shape == (3,)


def test_kaplan_meier_model():
data = [
(2, 0),
Expand Down

0 comments on commit 5460b0f

Please sign in to comment.