GPy.testing package¶
Submodules¶
GPy.testing.cython_tests module¶
-
class
CythonTestChols
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
test_choleskies_backprop
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.ep_likelihood_tests module¶
GPy.testing.examples_tests module¶
GPy.testing.fitc module¶
GPy.testing.gp_tests module¶
Created on 4 Sep 2015
@author: maxz
GPy.testing.gpy_kernels_state_space_tests module¶
Testing state space related functions.
-
class
StateSpaceKernelsTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.grid_tests module¶
GPy.testing.inference_tests module¶
The test cases for various inference algorithms
-
class
HMCSamplerTest
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
InferenceGPEP
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
InferenceXTestCase
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
MCMCSamplerTest
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.kernel_tests module¶
-
class
Coregionalize_cython_test
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Make sure that the coregionalize kernel work with and without cython enabled
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
Kern_check_d2K_dXdX
(kernel=None, dL_dK=None, X=None, X2=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_model
This class allows gradient checks for the secondderivative of a kernel with respect to X.
-
class
Kern_check_d2Kdiag_dXdX
(kernel=None, dL_dK=None, X=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_model
This class allows gradient checks for the second derivative of a kernel with respect to X.
-
class
Kern_check_dK_dX
(kernel=None, dL_dK=None, X=None, X2=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_model
This class allows gradient checks for the gradient of a kernel with respect to X.
-
class
Kern_check_dK_dtheta
(kernel=None, dL_dK=None, X=None, X2=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_model
This class allows gradient checks for the gradient of a kernel with respect to parameters.
-
class
Kern_check_dKdiag_dX
(kernel=None, dL_dK=None, X=None, X2=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_dK_dX
This class allows gradient checks for the gradient of a kernel diagonal with respect to X.
-
class
Kern_check_dKdiag_dtheta
(kernel=None, dL_dK=None, X=None)[source]¶ Bases:
GPy.testing.kernel_tests.Kern_check_model
This class allows gradient checks of the gradient of the diagonal of a kernel with respect to the parameters.
-
class
Kern_check_model
(kernel=None, dL_dK=None, X=None, X2=None)[source]¶ Bases:
GPy.core.model.Model
This is a dummy model class used as a base class for checking that the gradients of a given kernel are implemented correctly. It enables checkgrad() to be called independently on a kernel.
-
class
KernelGradientTestsContinuous
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
KernelTestsMiscellaneous
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
KernelTestsNonContinuous
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
KernelTestsProductWithZeroValues
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
Kernel_Psi_statistics_GradientTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
check_kernel_gradient_functions
(kern, X=None, X2=None, output_ind=None, verbose=False, fixed_X_dims=None)[source]¶ This function runs on kernels to check the correctness of their implementation. It checks that the covariance function is positive definite for a randomly generated data set.
Parameters: - kern (GPy.kern.Kernpart) – the kernel to be tested.
- X (ndarray) – X input values to test the covariance function.
- X2 (ndarray) – X2 input values to test the covariance function.
GPy.testing.likelihood_tests module¶
-
class
LaplaceTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Specific likelihood tests, not general enough for the above tests
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
TestNoiseModels
[source]¶ Bases:
object
Generic model checker
-
constrain_bounded
(regex, model, lower, upper)[source]¶ Used like: partial(constrain_bounded, lower=0, upper=1)
-
t_d2logpdf2_dlink2_dparams
(model, Y, f, Y_metadata, params, param_names, param_constraints)[source]¶
-
-
dparam_checkgrad
(func, dfunc, params, params_names, args, constraints=None, randomize=False, verbose=False)[source]¶ checkgrad expects a f: R^N -> R^1 and df: R^N -> R^N However if we are holding other parameters fixed and moving something else We need to check the gradient of each of the fixed parameters (f and y for example) seperately, whilst moving another parameter. Otherwise f: gives back R^N and
df: gives back R^NxM where M isThe number of parameters and N is the number of data Need to take a slice out from f and a slice out of df
-
dparam_partial
(inst_func, *args)[source]¶ If we have a instance method that needs to be called but that doesn’t take the parameter we wish to change to checkgrad, then this function will change the variable using set params.
- inst_func: should be a instance function of an object that we would like
- to change
param: the param that will be given to set_params args: anything else that needs to be given to the function (for example
the f or Y that are being used in the function whilst we tweak the param
GPy.testing.linalg_test module¶
-
class
LinalgTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.link_function_tests module¶
GPy.testing.mapping_tests module¶
-
class
MappingGradChecker
(mapping, X, name='map_grad_check')[source]¶ Bases:
GPy.core.model.Model
This class has everything we need to check the gradient of a mapping. It implement a simple likelihood which is a weighted sum of the outputs of the mapping. the gradients are checked against the parameters of the mapping and the input.
GPy.testing.meanfunc_tests module¶
-
class
MFtests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
test_parametric_mean_function
()[source]¶ A linear mean function with parameters that we’ll learn alongside the kernel
-
test_parametric_mean_function_additive
()[source]¶ A linear mean function with parameters that we’ll learn alongside the kernel
-
test_parametric_mean_function_composition
()[source]¶ A linear mean function with parameters that we’ll learn alongside the kernel
-
GPy.testing.minibatch_tests module¶
Created on 4 Sep 2015
@author: maxz
-
class
BGPLVMTest
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.misc_tests module¶
GPy.testing.model_tests module¶
-
class
GradientTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
test_GPRegression_exponential_1D
()[source]¶ Testing the GP regression with exponential kernel on 1d data
-
test_GPRegression_exponential_2D
()[source]¶ Testing the GP regression with exponential kernel on 2d data
-
test_GPRegression_exponential_ARD_2D
()[source]¶ Testing the GP regression with exponential kernel on 2d data
-
test_GPRegression_linear_kern_1D_ARD
()[source]¶ Testing the GP regression with linear kernel on 1d data
-
test_GPRegression_linear_kern_2D_ARD
()[source]¶ Testing the GP regression with linear kernel on 2d data
-
test_GPRegression_matern32_ARD_2D
()[source]¶ Testing the GP regression with matern32 kernel on 2d data
-
test_GPRegression_matern52_ARD_2D
()[source]¶ Testing the GP regression with matern52 kernel on 2d data
-
test_GPRegression_mlp_1d
()[source]¶ Testing the GP regression with mlp kernel with white kernel on 1d data
-
test_GPRegression_rbf_1d
()[source]¶ Testing the GP regression with rbf kernel with white kernel on 1d data
-
test_SparseGPRegression_rbf_linear_white_kern_1D
()[source]¶ Testing the sparse GP regression with rbf kernel on 1d data
-
test_SparseGPRegression_rbf_linear_white_kern_2D
()[source]¶ Testing the sparse GP regression with rbf kernel on 2d data
-
test_SparseGPRegression_rbf_white_kern_1D_uncertain_inputs
()[source]¶ Testing the sparse GP regression with rbf, linear kernel on 1d data with uncertain inputs
-
test_SparseGPRegression_rbf_white_kern_1d
()[source]¶ Testing the sparse GP regression with rbf kernel with white kernel on 1d data
-
test_SparseGPRegression_rbf_white_kern_2D
()[source]¶ Testing the sparse GP regression with rbf kernel on 2d data
-
test_SparseGPRegression_rbf_white_kern_2D_uncertain_inputs
()[source]¶ Testing the sparse GP regression with rbf, linear kernel on 2d data with uncertain inputs
-
test_TPRegression_matern32_ARD_2D
()[source]¶ Testing the TP regression with matern32 kernel on 2d data
-
test_TPRegression_matern52_ARD_2D
()[source]¶ Testing the TP regression with matern52 kernel on 2d data
-
test_posterior_covariance_between_points_with_normalizer
()[source]¶ Check that model.posterior_covariance_between_points returns the covariance from model.predict when normalizer=True
-
-
class
MiscTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
test_input_warped_gp_identity
()[source]¶ A InputWarpedGP with the identity warping function should be equal to a standard GP.
-
test_multioutput_regression_with_normalizer
()[source]¶ Test that normalizing works in multi-output case
-
test_predict_uncertain_inputs
()[source]¶ Projection of Gaussian through a linear function is still gaussian, and moments are analytical to compute, so we can check this case for predictions easily
-
test_raw_predict_numerical_stability
()[source]¶ Test whether the predicted variance of normal GP goes negative under numerical unstable situation. Thanks simbartonels@github for reporting the bug and providing the following example.
-
test_warped_gp_cubic_sine
(max_iters=100)[source]¶ A test replicating the cubic sine regression problem from Snelson’s paper. This test doesn’t have any assertions, it’s just to ensure coverage of the tanh warping function code.
-
GPy.testing.mpi_tests module¶
GPy.testing.pep_tests module¶
GPy.testing.pickle_tests module¶
Created on 13 Mar 2014
@author: maxz
-
class
ListDictTestCase
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
Test
(methodName='runTest')[source]¶ Bases:
GPy.testing.pickle_tests.ListDictTestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
test_load_pickle
= SkipTest(<function Test.test_load_pickle>)¶
-
GPy.testing.plotting_tests module¶
GPy.testing.prior_tests module¶
GPy.testing.quadrature_tests module¶
-
class
QuadTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
test file for checking implementation of gaussian-kronrod quadrature. we will take a function which can be integrated analytically and check if quadgk result is similar or not! through this file we can test how numerically accurate quadrature implementation in native numpy or manual code is.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.rv_transformation_tests module¶
Test if hyperparameters in models are properly transformed.
-
class
RVTransformationTestCase
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
TestModel
(theta=1.0)[source]¶ Bases:
GPy.core.model.Model
A simple GPy model with one parameter.
GPy.testing.serialization_tests module¶
Created on 20 April 2017
@author: pgmoren
GPy.testing.state_space_main_tests module¶
Test module for state_space_main.py
-
class
StateSpaceKernelsTests
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
run_continuous_model
(F, L, Qc, p_H, p_R, P_inf, X_data, Y_data, index=None, m_init=None, P_init=None, use_cython=False, kalman_filter_type='regular', calc_log_likelihood=True, calc_grad_log_likelihood=True, grad_params_no=0, grad_calc_params=None)[source]¶
-
run_descr_model
(measurements, A, Q, H, R, true_states=None, mean_compare_decimal=8, m_init=None, P_init=None, dA=None, dQ=None, dH=None, dR=None, use_cython=False, kalman_filter_type='regular', calc_log_likelihood=True, calc_grad_log_likelihood=True)[source]¶
-
test_discrete_ss_1D
(plot=False)[source]¶ This function tests Kalman filter and smoothing when the state dimensionality is one dimensional.
-
-
generate_brownian_data
(x_points=None, kernel_var=2.0, noise_var=2.0, plot=False, points_num=100, x_interval=(0, 20), random=True)[source]¶ Generate brownian data - data from Brownian motion. First point is always 0, and Beta(0) = 0 - standard conditions for Brownian motion.
- x_points: np.array
- Previously generated X points
- variance: float
- Gaussian noise variance added to the sine function
- plot: bool
- Whether to plot generated data
(if x_points is None, the the following parameters are used to generate those. They are the same as in ‘generate_x_points’ function)
points_num: int
x_interval: tuple (a,b)
random: bool
-
generate_linear_data
(x_points=None, tangent=2.0, add_term=1.0, noise_var=2.0, plot=False, points_num=100, x_interval=(0, 20), random=True)[source]¶ Function generates linear data.
- x_points: np.array
- Previously generated X points
- tangent: float
- Factor with which independent variable is multiplied in linear equation.
- add_term: float
- Additive term in linear equation.
- noise_var: float
- Gaussian noise variance added to the sine function
- plot: bool
- Whether to plot generated data
(if x_points is None, the the following parameters are used to generate those. They are the same as in ‘generate_x_points’ function)
points_num: int
x_interval: tuple (a,b)
random: bool
-
generate_linear_plus_sin
(x_points=None, tangent=2.0, add_term=1.0, noise_var=2.0, sin_period=2.0, sin_ampl=10.0, plot=False, points_num=100, x_interval=(0, 20), random=True)[source]¶ Generate the sum of linear trend and the sine function.
For parameters see the ‘generate_linear’ and ‘generate_sine’.
Comment: Gaussian noise variance is added only once (for linear function).
-
generate_random_y_data
(samples, dim, ts_no)[source]¶ Generate data:
samples - how many samples dim - dimensionality of the data ts_no - number of time series
Y: np.array((samples, dim, ts_no))
-
generate_sine_data
(x_points=None, sin_period=2.0, sin_ampl=10.0, noise_var=2.0, plot=False, points_num=100, x_interval=(0, 20), random=True)[source]¶ Function generates sinusoidal data.
- x_points: np.array
- Previously generated X points
- sin_period: float
- Sine period
- sin_ampl: float
- Sine amplitude
- noise_var: float
- Gaussian noise variance added to the sine function
- plot: bool
- Whether to plot generated data
(if x_points is None, the the following parameters are used to generate those. They are the same as in ‘generate_x_points’ function)
points_num: int
x_interval: tuple (a,b)
random: bool
-
generate_x_points
(points_num=100, x_interval=(0, 20), random=True)[source]¶ Function generates (sorted) points on the x axis.
- points_num: int
- How many points to generate
- x_interval: tuple (a,b)
- On which interval to generate points
- random: bool
- Regular points or random
- x_points: np.array
- Generated points
GPy.testing.svgp_tests module¶
-
class
SVGP_Poisson_with_meanfunction
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Inference in the SVGP with a Bernoulli likelihood
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
SVGP_classification
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Inference in the SVGP with a Bernoulli likelihood
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.tp_tests module¶
Created on 14 Jul 2017, based on gp_tests
@author: javdrher
GPy.testing.util_tests module¶
-
class
TestDebug
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
-
class
TestStandardize
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
GPy.testing.variational_tests module¶
Copyright (c) 2015, Max Zwiessele All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of paramax nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
class
KLGrad
(Xvar, kl)[source]¶ Bases:
GPy.core.model.Model
-
objective_function
()[source]¶ The objective function for the given algorithm.
This function is the true objective, which wants to be minimized. Note that all parameters are already set and in place, so you just need to return the objective function here.
For probabilistic models this is the negative log_likelihood (including the MAP prior), so we return it here. If your model is not probabilistic, just return your objective to minimize here!
-