From b655d5c5c73abee273996c026c604b35f2a96aba Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 18 Jun 2022 04:42:20 +0200 Subject: [PATCH] bitten: update bitten.py --- bitten/bitten.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bitten/bitten.py b/bitten/bitten.py index eaf22ff..37c5e38 100644 --- a/bitten/bitten.py +++ b/bitten/bitten.py @@ -2,6 +2,7 @@ # prepend underscores so these don't leak to __all__. from hashlib import sha256 as _sha256 from itertools import chain as _chain +from itertools import repeat as _repeat from os import environ as _environ from pathlib import Path as _Path from traceback import print_exception as _print_exception @@ -161,7 +162,7 @@ def _penalize3(constraints, *x, tol=1e-5, scale=1e10, growth=3.0): penalties = _flatten(cons(*x) for cons in constraints) n_con = len(penalties) growth = growth ** (1.0 / n_con) # "ps" - increment = 1.0 / np.sqrt(n_con) # "pnsi" + increment = n_con**-0.5 # "pnsi" penalty, nominal = 0.0, 0.0 # "pns", "pnsm" for p in penalties: p = max(p - tol, 0.0) @@ -622,7 +623,12 @@ def _bite( linear_bounds = [] for key, hyper in hypers.items(): if isinstance(hyper, BoundArray): # TODO: ArrayMixin or whatever - linear_bounds += [hyper.bounds] * hyper.dims + lower, upper = hyper.bounds + lower = lower if lower.ndim else _repeat(lower) + upper = upper if upper.ndim else _repeat(upper) + new = [(l, u) for _, l, u in zip(range(hyper.dims), lower, upper)] + assert len(new) == hyper.dims, f"length of bounds must equal number of dimensions" + linear_bounds += new elif isinstance(hyper, Bound): linear_bounds.append(hyper.bounds)