def test_posterior_implementations(tmp_path): all_classes = inspect.getmembers(posterior, inspect.isclass) classes = [c[1] for c in all_classes if isinstance(c[1](), proc.Procedure)] for procedure_class in classes: procedure = procedure_class() experiment = exp.PosteriorSamplingExperiment(procedure, str(tmp_path)) experiment.run(func.Cosine(), finish_line=250) shutil.rmtree(str(tmp_path))
def test_testfunction_cosine(): function = func.Cosine() minima = [[-3 * np.pi], [-np.pi], [np.pi], [3 * np.pi]] value_minima = 0 # Validate the default configuration assert function.get_dimensionality() == 1 # Validate function properties assert function.is_bounded() is True assert function.is_differentiable() is True # Validate minima y = function(np.array(minima)) assert np.sum(1.0 * (np.around(y, 8) == value_minima)) == len(y) # Validate that these minima are indeed minima x = np.random.rand(10000, function.get_dimensionality()) x *= function.ranges[:, 1] - function.ranges[:, 0] x += function.ranges[:, 0] y = function(x) assert np.sum(1.0 * (np.around(y, 8) == value_minima)) <= len(y) # Validate output shape assert y.shape == (10000, 1) assert function(x, True).shape == (10000, function.get_dimensionality())