S.validate(x_guess) S.validate(x_guess2) # Test sanity of output D, = lower.shape x_guess_w = S.warp(x_guess) assert type(x_guess_w) == np.ndarray assert x_guess_w.dtype.kind == "f" assert x_guess_w.shape == (n_suggest, D) assert x_guess_w.shape == (n_suggest, D) assert np.all(x_guess_w <= upper) @given( gufunc_floats("(n,D),(n)->()", min_value=0.0, max_value=1.0, min_side={"D": 1}), integers(min_value=1, max_value=10), seeds(), ) @settings(deadline=None) def test_random_search_suggest_diff(api_args, n_suggest, seed): # Hard to know how many iters needed for arbitrary space that we need to # run so that we don't get dupes by chance. So, for now, let's just stick # with this simple space. dim = {"space": "linear", "type": "real", "range": [1.0, 5.0]} # Use at least 10 n_suggest to make sure don't get same answer by chance X_w, y = api_args D = X_w.shape[1]
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from hypothesis import given, settings import bayesmark.experiment_baseline as base from bayesmark import experiment_analysis as anal from bayesmark.constants import TRIAL from bayesmark.np_util import argmin_2d from hypothesis_util import gufunc_floats from util import perf_dataarrays @given(gufunc_floats("(n,p,t),(n,p,t)->(n,t)", allow_nan=False, unique=True, min_side=1)) def test_get_perf_array(args): """Behavior for tie-breaking in `evals_visible` is complex, so only testing all unique case here.""" evals, evals_visible = args n_iter, _, n_trials = evals.shape perf_array = anal.get_perf_array(evals, evals_visible) assert perf_array.shape == (n_iter, n_trials) for ii in range(n_iter): for jj in range(n_trials): idx0, idx1 = argmin_2d(evals_visible[: ii + 1, :, jj]) assert perf_array[ii, jj] == evals[idx0, idx1, jj]
def order_stats_trim(X): Y = qt.order_stats(X) X_ss = np.array(X.shape) X_ss[-1] = X_ss[-1] + 2 assert Y.shape == tuple(X_ss) assert np.all(Y[..., 0] == -np.inf) assert np.all(Y[..., -1] == np.inf) Y = Y[..., 1:-1] # Trim out infs assert Y.shape == tuple(X.shape) return Y @given(gufunc_floats("(n)->(m)", allow_nan=False)) def test_order_stats(args): X, = args o_stats = qt.order_stats(X) assert len(o_stats) == len(X) + 2 # test is sorted assert not np.any(np.diff(o_stats) < 0) # limit elements assert o_stats[0] == -np.inf assert o_stats[-1] == np.inf # equal to equiv versions with lists
map_=decoder_gen_broadcast, ) @given(gufunc("()->()", dtype=np.float_, elements=floats())) def test_bilog_props(args): x, = args y = sp.bilog(x) assert sp.bilog(0) == 0 # This could be its own test assert close_enough(y, -sp.bilog(-x), equal_nan=True) assert np.isfinite(y) == np.isfinite(x) @given(gufunc_floats("(2)->(2)", allow_infinity=False, allow_nan=False)) def test_bilog_monotonic(args): x, = args x1, x2 = sorted(np.abs(x)) assert sp.bilog(x1) < sp.bilog((1 + 1e-6) * x2 + 1e-6) @given(gufunc("()->()", dtype=np.float_, elements=floats())) def test_bilog_biexp(args): x, = args assert close_enough(sp.biexp(sp.bilog(x)), x, equal_nan=True)
from hypothesis_util import broadcast_tester, close_enough, gufunc_floats, seeds @given(seeds()) def test_random_seed(seed): random = np.random.RandomState(seed) seed = np_util.random_seed(random) @given(lists(lists(floats())), seeds()) def test_shuffle_2d(X, seed): random = np.random.RandomState(seed) np_util.shuffle_2d(X, random) @given(gufunc_floats("(n,m)->()"), integers(1, 5), seeds()) def test_strat_split(X, n_splits, seed): X, = X random = np.random.RandomState(seed) np_util.strat_split(X, n_splits, inplace=False, random=random) random = np.random.RandomState(seed) np_util.strat_split(X, n_splits, inplace=True, random=random) @given(gufunc_floats("(),()->()", allow_nan=False)) def test_isclose_lte_pass(args): x, y = args x = np.minimum(x, y + 1e-10) assert np_util.isclose_lte(x, y)