def function_env(): bounds = Bounds(shape=(2, ), high=1, low=1, dtype=int) env = Function(function=lambda x: np.ones(N_WALKERS), bounds=bounds) params = { "actions": { "dtype": np.int64, "size": (2, ) }, "dt": { "dtype": np.float32 } } states = States(state_dict=params, batch_size=N_WALKERS) return env, states
def from_function(cls, function: Callable, bounds: Bounds, *args, **kwargs) -> "FunctionMapper": """ Initialize a :class:`FunctionMapper` using a python callable and a \ :class:`Bounds` instance. Args: function: Callable representing an arbitrary function to be optimized. bounds: Represents the domain of the function to be optimized. *args: Passed to :class:`FunctionMapper` __init__. **kwargs: Passed to :class:`FunctionMapper` __init__. Returns: Instance of :class:`FunctionMapper` that optimizes the target function. """ env = Function(function=function, bounds=bounds) return FunctionMapper(env=lambda: env, *args, **kwargs)
def test_init_error(self): with pytest.raises(TypeError): Function(function=sphere, bounds=(True, False))
def custom_domain_function(): bounds = Bounds(shape=(2,), high=10, low=-5, dtype=float) env = Function( function=sphere, bounds=bounds, custom_domain_check=lambda x: numpy.linalg.norm(x) < 5.0 ) return env
def local_minimizer(): bounds = Bounds(shape=(2,), high=10, low=-5, dtype=float) env = Function(function=sphere, bounds=bounds) return MinimizerWrapper(env)
def test_minimizer_getattr(self): bounds = Bounds(shape=(2,), high=10, low=-5, dtype=float) env = Function(function=sphere, bounds=bounds) minim = MinimizerWrapper(env) assert minim.shape == env.shape
def custom_domain_function(): bounds = Bounds(shape=(2, ), high=10, low=-5, dtype=judo.float) env = Function(function=sphere, bounds=bounds, custom_domain_check=lambda x, *args: judo.norm(x, 1) < 5.0) return env