Skip to content

Commit

Permalink
Add coveralls configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamrick committed Nov 27, 2013
1 parent 13f44ca commit c2d27de
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
docs/_build
gp/ext/*.c
gp/ext/*.so
.coverage
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ before_install:
- export PATH=/home/travis/anaconda/bin:$PATH
# Install packages
install:
- conda install --yes pip python=$TRAVIS_PYTHON_VERSION numpy nose scipy sympy matplotlib cython
- conda install --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy sympy matplotlib cython
- pip install -r requirements.txt --use-mirrors
- pip install pytest pytest-cov coveralls
- python setup.py build_ext --inplace

script: nosetests
script:
- py.test --cov gp

after_success:
- coveralls
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cython:
$(PYCMD) build_ext --inplace

test:
nosetests
py.test --cov gp

gh-pages:
make clean || true
Expand Down
Empty file added gp/tests/__init__.py
Empty file.
17 changes: 8 additions & 9 deletions gp/tests/test_gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
np.seterr(all='raise')
np.random.seed(2348)

from gp import GP
from gp import GaussianKernel as kernel
from util import opt, rand_params, approx_deriv
from .. import GP
from .. import GaussianKernel as kernel
from .util import opt, rand_params, approx_deriv

DTYPE = np.float64

Expand All @@ -31,12 +31,11 @@ def make_gp():

class TestGP(object):

def __init__(self):
self.N_big = opt['n_big_test_iters']
self.N_small = opt['n_small_test_iters']
self.thresh = 1e-5
self.dtheta = 1e-5
self.pfail = 5
N_big = opt['n_big_test_iters']
N_small = opt['n_small_test_iters']
thresh = 1e-5
dtheta = 1e-5
pfail = 5

def check_mean(self, gp, y):
diff = np.abs(gp.mean(gp.x) - y)
Expand Down
31 changes: 14 additions & 17 deletions gp/tests/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
np.seterr(all='raise')
np.random.seed(2348)

from gp import GaussianKernel, PeriodicKernel
from util import opt, rand_params, approx_deriv
from .. import GaussianKernel, PeriodicKernel
from .util import opt, rand_params, approx_deriv

EPS = np.finfo(float).eps

Expand All @@ -13,10 +13,10 @@

class TestKernels(object):

def __init__(self):
self.N_big = opt['n_big_test_iters']
self.N_small = opt['n_small_test_iters']
self.thresh = 1e-5
N_big = opt['n_big_test_iters']
N_small = opt['n_small_test_iters']
thresh = 1e-3
dtheta = 1e-5

def check_params(self, kernel, params):
k = kernel(*params)
Expand Down Expand Up @@ -60,17 +60,16 @@ def check_periodic_K(self, x, dx, params):
def check_jacobian(self, kernel, params, x):
k = kernel(*params)
jac = k.jacobian(x, x)
dtheta = self.thresh

approx_jac = np.empty(jac.shape)
for i in xrange(len(params)):
p0 = list(params)
p0[i] -= dtheta
p0[i] -= self.dtheta
p1 = list(params)
p1[i] += dtheta
p1[i] += self.dtheta
k0 = kernel(*p0)(x, x)
k1 = kernel(*p1)(x, x)
approx_jac[i] = approx_deriv(k0, k1, dtheta)
approx_jac[i] = approx_deriv(k0, k1, self.dtheta)

diff = jac - approx_jac
bad = np.abs(diff) > self.thresh
Expand All @@ -83,23 +82,21 @@ def check_jacobian(self, kernel, params, x):
def check_hessian(self, kernel, params, x):
k = kernel(*params)
hess = k.hessian(x, x)
dtheta = self.thresh

approx_hess = np.empty(hess.shape)
for i in xrange(len(params)):
p0 = list(params)
p1 = list(params)
p0[i] -= dtheta
p1[i] += dtheta
p0[i] -= self.dtheta
p1[i] += self.dtheta
jac0 = kernel(*p0).jacobian(x, x)
jac1 = kernel(*p1).jacobian(x, x)
approx_hess[:, i] = approx_deriv(jac0, jac1, dtheta)
approx_hess[:, i] = approx_deriv(jac0, jac1, self.dtheta)

diff = hess - approx_hess
thresh = 1e-4
bad = np.abs(diff) > thresh
bad = np.abs(diff) > self.thresh
if bad.any():
print "threshold:", thresh
print "threshold:", self.thresh
print "worst err:", np.abs(diff).max()
print "frac bad: ", (np.sum(bad) / float(bad.size))
raise AssertionError("bad hessian")
Expand Down

0 comments on commit c2d27de

Please sign in to comment.