Beispiel #1
0
def function() -> Function:
    return Function.from_bounds_params(
        function=sphere,
        shape=(2, ),
        low=tensor([-10, -5]),
        high=tensor([10, 5]),
    )
Beispiel #2
0
 def dummy_env(self) -> Function:
     return Function.from_bounds_params(
         function=lambda x: numpy.ones(len(x)),
         shape=(2,),
         low=numpy.array([-10, -5]),
         high=numpy.array([10, 5]),
     )
Beispiel #3
0
def function_env() -> Function:
    return Function.from_bounds_params(
        function=lambda x: judo.ones(len(x)),
        shape=(2, ),
        low=tensor([-10, -5]),
        high=tensor([10, 5]),
    )
Beispiel #4
0
def function() -> Function:
    return Function.from_bounds_params(
        function=sphere,
        shape=(2, ),
        low=numpy.array([-10, -5]),
        high=numpy.array([10, 5]),
    )
Beispiel #5
0
def env() -> Function:
    return Function.from_bounds_params(
        function=lambda x: np.ones(len(x)),
        shape=(2, ),
        low=np.array([-10, -5]),
        high=np.array([10, 5]),
    )
Beispiel #6
0
 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
Beispiel #7
0
    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)
Beispiel #8
0
 def test_from_bounds_params_error(self):
     with pytest.raises(TypeError):
         Function.from_bounds_params(function=sphere)
Beispiel #9
0
 def test_init_error(self):
     with pytest.raises(TypeError):
         Function(function=sphere, bounds=(True, False))
Beispiel #10
0
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
Beispiel #11
0
def local_minimizer():
    bounds = Bounds(shape=(2,), high=10, low=-5, dtype=float)
    env = Function(function=sphere, bounds=bounds)
    return MinimizerWrapper(env)
Beispiel #12
0
 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
Beispiel #13
0
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