runlmc.util.testing_utils module

The following methods are useful for generating various matrices for testing.

“PSDT” stands for positive semi-definite Toeplitz (and, implicitly, symmetric).

class runlmc.util.testing_utils.BasicModel(dists, Y, kern)[source]

Bases: runlmc.parameterization.model.Model

log_likelihood()[source]
Returns:the log likelihood of the current model with respect to its

current inputs and outputs and the current prior. This should NOT include the likelihood of the parameters given their priors. In other words, this value should be \(\log p(\mathbf{y}|\theta,\phi)\)

parameters_changed()[source]

This method gets called when parameters have changed. Another way of listening to param changes is to add self as a listener to the param, such that updates get passed through. See :py:function:paramz.param.Observable.add_observer

class runlmc.util.testing_utils.RandomTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

This test case sets the random seed to be based on the time that the test is run.

If there is a SEED variable in the enviornment, then this is used as the seed.

Sets both random and numpy.random. Prints the seed to stdout before running each test case.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

class runlmc.util.testing_utils.SingleGradOptimizer(lipschitz=1)[source]

Bases: paramz.optimization.optimization.Optimizer

opt(x_init, f_fp=None, f=None, fp=None)[source]
runlmc.util.testing_utils.check_np_lists(a, b, atol=1e-07, rtol=1e-07)[source]

Verifies that two lists of numpy arrays are all close. :param a: :param b:

runlmc.util.testing_utils.error_context(s)[source]
runlmc.util.testing_utils.exp_decr_toep(n)[source]
Returns:top row of a PSDT matrix of size n with terms exponentially decreasing in distance from the main diagonal; the rate of which is randomly generated but at least \(e\).
runlmc.util.testing_utils.poor_cond_toep(n)[source]
Parameters:n – size of output
Returns:the top row of a randomly scaled PSDT matrix whose \(L^2\) condition number scales exponentially with n
runlmc.util.testing_utils.rand_pd(n)[source]
Returns:a random n by n symmetric PSD matrix with positive entries
runlmc.util.testing_utils.random_toep(n)[source]
Returns:top row of a random PSDT matrix of size n.
runlmc.util.testing_utils.run_main(f, help_str)[source]

A helper function which is re-used in setting up benchmarks for kernels that are shaped in a specific manner; namely, sums of Kronecker products of small dense and large Toeplitz matrices.

This function reads in command-line arguments and executes a simple benchmarking script.

Parameters:
  • f – benchmarking function to pass generated inputs with user-specified parameters to.
  • help_str – a help-string to be printed when the user does not call a correct invocation of the program.
runlmc.util.testing_utils.vectorize_inputs(f)[source]

Convert a multi-input vector function to accept matrices with each column corresponding to an input