예제 #1
0
    uniqify = [CmdArgs.optimizer, CmdArgs.data, CmdArgs.classifier, CmdArgs.metric]
    for uu in uniqify:
        assume(all(launcher._is_arg_safe(ss) for ss in args[uu]))
        args[uu] = list(set(args[uu]))

    m_set = set(args[CmdArgs.metric])
    m_lookup = {problem_type: sorted(m_set.intersection(mm)) for problem_type, mm in data.METRICS_LOOKUP.items()}
    ok = all(len(m_lookup[data.get_problem_type(dd)]) > 0 for dd in args[CmdArgs.data])
    assume(ok)

    G = launcher.gen_commands(args, opt_file_lookup, run_uuid)
    L = list(G)
    assert L is not None


@given(launcher_args_and_config(min_jobs=1), uuids(), seeds())
@settings(deadline=None, suppress_health_check=(HealthCheck.too_slow,))
def test_dry_run(args, run_uuid, seed):
    args, opt_file_lookup = args

    assume(all(launcher._is_arg_safe(ss) for ss in args.values() if isinstance(ss, str)))

    uniqify = [CmdArgs.optimizer, CmdArgs.data, CmdArgs.classifier, CmdArgs.metric]
    for uu in uniqify:
        assume(all(launcher._is_arg_safe(ss) for ss in args[uu]))
        args[uu] = list(set(args[uu]))

    m_set = set(args[CmdArgs.metric])
    m_lookup = {problem_type: sorted(m_set.intersection(mm)) for problem_type, mm in data.METRICS_LOOKUP.items()}
    ok = all(len(m_lookup[data.get_problem_type(dd)]) > 0 for dd in args[CmdArgs.data])
    assume(ok)
# 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.
import numpy as np
from hypothesis import given, settings
from hypothesis.strategies import integers

import bayesmark.space as sp
from bayesmark.np_util import linear_rescale
from bayesmark.random_search import suggest_dict
from hypothesis_util import close_enough, gufunc_floats, seeds
from util import space_configs


@given(space_configs(allow_missing=True), integers(min_value=1, max_value=8),
       seeds())
@settings(deadline=None)
def test_random_search_suggest_sanity(api_args, n_suggest, seed):
    meta, X, y, _ = api_args

    # Get the unwarped X
    S = sp.JointSpace(meta)
    lower, upper = S.get_bounds().T
    S.validate(X)

    N = len(X)
    # Split history and call twice with diff histories but same seed
    M = N // 2
    X1, X2 = X[:M], X[M:]
    y1, y2 = y[:M], y[M:]
예제 #3
0
# 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.
import numpy as np
from hypothesis import assume, given, settings
from hypothesis.strategies import sampled_from

from bayesmark import data
from bayesmark import sklearn_funcs as skf
from bayesmark.constants import DATA_LOADER_NAMES, METRICS, MODEL_NAMES
from bayesmark.random_search import suggest_dict
from hypothesis_util import seeds


@given(sampled_from(MODEL_NAMES), sampled_from(DATA_LOADER_NAMES),
       sampled_from(METRICS), seeds(), seeds())
@settings(deadline=None)
def test_sklearn_model(model, dataset, metric, shuffle_seed, rs_seed):
    prob_type = data.get_problem_type(dataset)
    assume(metric in data.METRICS_LOOKUP[prob_type])

    test_prob = skf.SklearnModel(model,
                                 dataset,
                                 metric,
                                 shuffle_seed=shuffle_seed)

    api_config = test_prob.get_api_config()
    x_guess, = suggest_dict([], [],
                            api_config,
                            n_suggestions=1,
                            random=np.random.RandomState(rs_seed))
예제 #4
0
        assert np.allclose(EB, 0.0)


@given(integers(1, 10), sampled_from([np.inf, -np.inf]), probs())
def test_t_EB_inf(N, val, alpha):
    x = np.zeros(N)
    x[0] = val

    EB = stats.t_EB(x, alpha=alpha)
    if N <= 1:
        assert EB == np.inf
    else:
        assert np.isnan(EB)


@given(seeds(), probs(), integers(2, 10))
def test_t_EB_coverage(seed, alpha, N):
    trials = 100

    random_st = np.random.RandomState(seed)

    fail = 0
    for tt in range(trials):
        x = random_st.randn(N)

        EB = stats.t_EB(x, alpha=alpha)
        mu = np.nanmean(x)
        LB, UB = mu - EB, mu + EB
        assert np.isfinite(LB) and np.isfinite(UB)
        fail += (0.0 < LB) or (UB < 0.0)
    pval = sst.binom_test(fail, trials, alpha)
예제 #5
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
import numpy as np
from hypothesis import assume, given
from hypothesis.strategies import floats, integers, lists

from bayesmark import np_util
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