コード例 #1
0
ファイル: test_env.py プロジェクト: Guillemdb/fragile
def function() -> Function:
    return Function.from_bounds_params(
        function=sphere,
        shape=(2, ),
        low=tensor([-10, -5]),
        high=tensor([10, 5]),
    )
コード例 #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]),
     )
コード例 #3
0
ファイル: test_env.py プロジェクト: Guillemdb/fragile
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]),
    )
コード例 #4
0
def function() -> Function:
    return Function.from_bounds_params(
        function=sphere,
        shape=(2, ),
        low=numpy.array([-10, -5]),
        high=numpy.array([10, 5]),
    )
コード例 #5
0
ファイル: test_optim_env.py プロジェクト: vmarkovtsev/fragile
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]),
    )
コード例 #6
0
ファイル: test_env.py プロジェクト: vmarkovtsev/fragile
 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
コード例 #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)
コード例 #8
0
 def test_from_bounds_params_error(self):
     with pytest.raises(TypeError):
         Function.from_bounds_params(function=sphere)
コード例 #9
0
 def test_init_error(self):
     with pytest.raises(TypeError):
         Function(function=sphere, bounds=(True, False))
コード例 #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
コード例 #11
0
def local_minimizer():
    bounds = Bounds(shape=(2,), high=10, low=-5, dtype=float)
    env = Function(function=sphere, bounds=bounds)
    return MinimizerWrapper(env)
コード例 #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
コード例 #13
0
ファイル: test_env.py プロジェクト: Guillemdb/fragile
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