Skip to content

COSMIT don't use docstrings in tests (gp kernel tests) #7399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions sklearn/gaussian_process/tests/test_gpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ def f(x):


def test_predict_consistent():
""" Check binary predict decision has also predicted probability above 0.5.
"""
# Check binary predict decision has also predicted probability above 0.5.
for kernel in kernels:
gpc = GaussianProcessClassifier(kernel=kernel).fit(X, y)
assert_array_equal(gpc.predict(X),
gpc.predict_proba(X)[:, 1] >= 0.5)


def test_lml_improving():
""" Test that hyperparameter-tuning improves log-marginal likelihood. """
# Test that hyperparameter-tuning improves log-marginal likelihood.
for kernel in kernels:
if kernel == fixed_kernel:
continue
Expand All @@ -53,15 +52,15 @@ def test_lml_improving():


def test_lml_precomputed():
""" Test that lml of optimized kernel is stored correctly. """
# Test that lml of optimized kernel is stored correctly.
for kernel in kernels:
gpc = GaussianProcessClassifier(kernel=kernel).fit(X, y)
assert_almost_equal(gpc.log_marginal_likelihood(gpc.kernel_.theta),
gpc.log_marginal_likelihood(), 7)


def test_converged_to_local_maximum():
""" Test that we are in local maximum after hyperparameter-optimization."""
# Test that we are in local maximum after hyperparameter-optimization.
for kernel in kernels:
if kernel == fixed_kernel:
continue
Expand All @@ -76,7 +75,7 @@ def test_converged_to_local_maximum():


def test_lml_gradient():
""" Compare analytic and numeric gradient of log marginal likelihood. """
# Compare analytic and numeric gradient of log marginal likelihood.
for kernel in kernels:
gpc = GaussianProcessClassifier(kernel=kernel).fit(X, y)

Expand All @@ -91,10 +90,8 @@ def test_lml_gradient():


def test_random_starts():
"""
Test that an increasing number of random-starts of GP fitting only
increases the log marginal likelihood of the chosen theta.
"""
# Test that an increasing number of random-starts of GP fitting only
# increases the log marginal likelihood of the chosen theta.
n_samples, n_features = 25, 2
np.random.seed(0)
rng = np.random.RandomState(0)
Expand All @@ -115,7 +112,7 @@ def test_random_starts():


def test_custom_optimizer():
""" Test that GPC can use externally defined optimizers. """
# Test that GPC can use externally defined optimizers.
# Define a dummy optimizer that simply tests 50 random hyperparameters
def optimizer(obj_func, initial_theta, bounds):
rng = np.random.RandomState(0)
Expand All @@ -140,7 +137,7 @@ def optimizer(obj_func, initial_theta, bounds):


def test_multi_class():
""" Test GPC for multi-class classification problems. """
# Test GPC for multi-class classification problems.
for kernel in kernels:
gpc = GaussianProcessClassifier(kernel=kernel)
gpc.fit(X, y_mc)
Expand All @@ -153,7 +150,7 @@ def test_multi_class():


def test_multi_class_n_jobs():
""" Test that multi-class GPC produces identical results with n_jobs>1. """
# Test that multi-class GPC produces identical results with n_jobs>1.
for kernel in kernels:
gpc = GaussianProcessClassifier(kernel=kernel)
gpc.fit(X, y_mc)
Expand Down
41 changes: 19 additions & 22 deletions sklearn/gaussian_process/tests/test_gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def f(x):


def test_gpr_interpolation():
"""Test the interpolating property for different kernels."""
# Test the interpolating property for different kernels.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)
y_pred, y_cov = gpr.predict(X, return_cov=True)
Expand All @@ -46,7 +46,7 @@ def test_gpr_interpolation():


def test_lml_improving():
""" Test that hyperparameter-tuning improves log-marginal likelihood. """
# Test that hyperparameter-tuning improves log-marginal likelihood.
for kernel in kernels:
if kernel == fixed_kernel:
continue
Expand All @@ -56,15 +56,15 @@ def test_lml_improving():


def test_lml_precomputed():
""" Test that lml of optimized kernel is stored correctly. """
# Test that lml of optimized kernel is stored correctly.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)
assert_equal(gpr.log_marginal_likelihood(gpr.kernel_.theta),
gpr.log_marginal_likelihood())


def test_converged_to_local_maximum():
""" Test that we are in local maximum after hyperparameter-optimization."""
# Test that we are in local maximum after hyperparameter-optimization.
for kernel in kernels:
if kernel == fixed_kernel:
continue
Expand All @@ -79,7 +79,7 @@ def test_converged_to_local_maximum():


def test_solution_inside_bounds():
""" Test that hyperparameter-optimization remains in bounds"""
# Test that hyperparameter-optimization remains in bounds#
for kernel in kernels:
if kernel == fixed_kernel:
continue
Expand All @@ -95,7 +95,7 @@ def test_solution_inside_bounds():


def test_lml_gradient():
""" Compare analytic and numeric gradient of log marginal likelihood. """
# Compare analytic and numeric gradient of log marginal likelihood.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)

Expand All @@ -110,7 +110,7 @@ def test_lml_gradient():


def test_prior():
""" Test that GP prior has mean 0 and identical variances."""
# Test that GP prior has mean 0 and identical variances.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel)

Expand All @@ -125,7 +125,7 @@ def test_prior():


def test_sample_statistics():
""" Test that statistics of samples drawn from GP are correct."""
# Test that statistics of samples drawn from GP are correct.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)

Expand All @@ -140,14 +140,14 @@ def test_sample_statistics():


def test_no_optimizer():
""" Test that kernel parameters are unmodified when optimizer is None."""
# Test that kernel parameters are unmodified when optimizer is None.
kernel = RBF(1.0)
gpr = GaussianProcessRegressor(kernel=kernel, optimizer=None).fit(X, y)
assert_equal(np.exp(gpr.kernel_.theta), 1.0)


def test_predict_cov_vs_std():
""" Test that predicted std.-dev. is consistent with cov's diagonal."""
# Test that predicted std.-dev. is consistent with cov's diagonal.
for kernel in kernels:
gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)
y_mean, y_cov = gpr.predict(X2, return_cov=True)
Expand All @@ -156,7 +156,7 @@ def test_predict_cov_vs_std():


def test_anisotropic_kernel():
""" Test that GPR can identify meaningful anisotropic length-scales. """
# Test that GPR can identify meaningful anisotropic length-scales.
# We learn a function which varies in one dimension ten-times slower
# than in the other. The corresponding length-scales should differ by at
# least a factor 5
Expand All @@ -171,10 +171,8 @@ def test_anisotropic_kernel():


def test_random_starts():
"""
Test that an increasing number of random-starts of GP fitting only
increases the log marginal likelihood of the chosen theta.
"""
# Test that an increasing number of random-starts of GP fitting only
# increases the log marginal likelihood of the chosen theta.
n_samples, n_features = 25, 2
np.random.seed(0)
rng = np.random.RandomState(0)
Expand All @@ -197,11 +195,10 @@ def test_random_starts():


def test_y_normalization():
""" Test normalization of the target values in GP
# Test normalization of the target values in GP

Fitting non-normalizing GP on normalized y and fitting normalizing GP
on unnormalized y should yield identical results
"""
# Fitting non-normalizing GP on normalized y and fitting normalizing GP
# on unnormalized y should yield identical results
y_mean = y.mean(0)
y_norm = y - y_mean
for kernel in kernels:
Expand All @@ -226,7 +223,7 @@ def test_y_normalization():


def test_y_multioutput():
""" Test that GPR can deal with multi-dimensional target values"""
# Test that GPR can deal with multi-dimensional target values
y_2d = np.vstack((y, y * 2)).T

# Test for fixed kernel that first dimension of 2d GP equals the output
Expand Down Expand Up @@ -269,7 +266,7 @@ def test_y_multioutput():


def test_custom_optimizer():
""" Test that GPR can use externally defined optimizers. """
# Test that GPR can use externally defined optimizers.
# Define a dummy optimizer that simply tests 50 random hyperparameters
def optimizer(obj_func, initial_theta, bounds):
rng = np.random.RandomState(0)
Expand All @@ -294,7 +291,7 @@ def optimizer(obj_func, initial_theta, bounds):


def test_duplicate_input():
""" Test GPR can handle two different output-values for the same input. """
# Test GPR can handle two different output-values for the same input.
for kernel in kernels:
gpr_equal_inputs = \
GaussianProcessRegressor(kernel=kernel, alpha=1e-2)
Expand Down
Loading