Beispiel #1
0
def test_default_encoder_factory(observation_shape, action_size,
                                 discrete_action):
    factory = DefaultEncoderFactory()

    encoder = factory.create(observation_shape, action_size, discrete_action)

    if len(observation_shape) == 3:
        if action_size is None:
            assert isinstance(encoder, PixelEncoder)
        else:
            assert isinstance(encoder, PixelEncoderWithAction)
    else:
        if action_size is None:
            assert isinstance(encoder, VectorEncoder)
        else:
            assert isinstance(encoder, VectorEncoderWithAction)
    if action_size is not None:
        assert encoder._discrete_action == discrete_action

    assert factory.get_type() == "default"

    params = factory.get_params()
    new_factory = DefaultEncoderFactory(**params)
    assert new_factory.get_params() == params
Beispiel #2
0
import pytest

from d3rlpy.encoders import DefaultEncoderFactory
from d3rlpy.preprocessing.scalers import MinMaxScaler
from d3rlpy.augmentation import AugmentationPipeline, RandomShift
from d3rlpy.augmentation.base import Augmentation
from d3rlpy.gpu import Device
from d3rlpy.argument_utils import check_encoder
from d3rlpy.argument_utils import check_scaler
from d3rlpy.argument_utils import check_augmentation
from d3rlpy.argument_utils import check_use_gpu


@pytest.mark.parametrize('value', ['default', DefaultEncoderFactory()])
def test_check_encoder(value):
    assert isinstance(check_encoder(value), DefaultEncoderFactory)


@pytest.mark.parametrize('value', ['min_max', MinMaxScaler(), None])
def test_check_scaler(value):
    scaler = check_scaler(value)
    if value is None:
        assert scaler is None
    else:
        assert isinstance(scaler, MinMaxScaler)


@pytest.mark.parametrize('value', [['random_shift'], [RandomShift()], None])
def test_check_augmentation(value):
    pipeline = check_augmentation(value)
    assert isinstance(pipeline, AugmentationPipeline)
Beispiel #3
0
import pytest

from d3rlpy.encoders import DefaultEncoderFactory
from d3rlpy.q_functions import MeanQFunctionFactory
from d3rlpy.preprocessing.scalers import MinMaxScaler
from d3rlpy.augmentation import AugmentationPipeline, RandomShift
from d3rlpy.augmentation.base import Augmentation
from d3rlpy.gpu import Device
from d3rlpy.argument_utility import check_encoder
from d3rlpy.argument_utility import check_q_func
from d3rlpy.argument_utility import check_scaler
from d3rlpy.argument_utility import check_augmentation
from d3rlpy.argument_utility import check_use_gpu


@pytest.mark.parametrize("value", ["default", DefaultEncoderFactory()])
def test_check_encoder(value):
    assert isinstance(check_encoder(value), DefaultEncoderFactory)


@pytest.mark.parametrize("value", ["mean", MeanQFunctionFactory()])
def test_check_q_func(value):
    assert isinstance(check_q_func(value), MeanQFunctionFactory)


@pytest.mark.parametrize("value", ["min_max", MinMaxScaler(), None])
def test_check_scaler(value):
    scaler = check_scaler(value)
    if value is None:
        assert scaler is None
    else:
Beispiel #4
0
from tests.algos.algo_test import torch_impl_tester, DummyScaler


@pytest.mark.parametrize('observation_shape', [(100, ), (1, 48, 48)])
@pytest.mark.parametrize('action_size', [2])
@pytest.mark.parametrize('actor_learning_rate', [1e-3])
@pytest.mark.parametrize('critic_learning_rate', [1e-3])
@pytest.mark.parametrize('imitator_learning_rate', [1e-3])
@pytest.mark.parametrize('temp_learning_rate', [1e-3])
@pytest.mark.parametrize('alpha_learning_rate', [1e-3])
@pytest.mark.parametrize('actor_optim_factory', [AdamFactory()])
@pytest.mark.parametrize('critic_optim_factory', [AdamFactory()])
@pytest.mark.parametrize('imitator_optim_factory', [AdamFactory()])
@pytest.mark.parametrize('temp_optim_factory', [AdamFactory()])
@pytest.mark.parametrize('alpha_optim_factory', [AdamFactory()])
@pytest.mark.parametrize('encoder_factory', [DefaultEncoderFactory()])
@pytest.mark.parametrize('gamma', [0.99])
@pytest.mark.parametrize('tau', [0.05])
@pytest.mark.parametrize('n_critics', [2])
@pytest.mark.parametrize('bootstrap', [False])
@pytest.mark.parametrize('share_encoder', [False, True])
@pytest.mark.parametrize('initial_temperature', [1.0])
@pytest.mark.parametrize('initial_alpha', [1.0])
@pytest.mark.parametrize('alpha_threshold', [0.05])
@pytest.mark.parametrize('lam', [0.75])
@pytest.mark.parametrize('n_action_samples', [4])
@pytest.mark.parametrize('mmd_sigma', [20.0])
@pytest.mark.parametrize('q_func_type', ['mean', 'qr', 'iqn', 'fqf'])
@pytest.mark.parametrize('scaler', [None, DummyScaler()])
@pytest.mark.parametrize('augmentation', [AugmentationPipeline()])
@pytest.mark.parametrize('n_augmentations', [1])
Beispiel #5
0
    # check predict_value with standard deviation
    value, std = impl.predict_value(observations, actions, with_std=True)
    assert value.shape == (100, )
    assert std.shape == (100, )

    # check save_model and load_model
    impl.save_model(os.path.join("test_data", "model.pt"))
    impl.load_model(os.path.join("test_data", "model.pt"))


@pytest.mark.parametrize("observation_shape", [(100, ), (4, 84, 84)])
@pytest.mark.parametrize("action_size", [2])
@pytest.mark.parametrize("learning_rate", [1e-3])
@pytest.mark.parametrize("optim_factory", [AdamFactory()])
@pytest.mark.parametrize("encoder_factory", [DefaultEncoderFactory()])
@pytest.mark.parametrize("q_func_factory", ["mean", "qr", "iqn", "fqf"])
@pytest.mark.parametrize("gamma", [0.99])
@pytest.mark.parametrize("n_critics", [1])
@pytest.mark.parametrize("bootstrap", [False])
@pytest.mark.parametrize("share_encoder", [True])
@pytest.mark.parametrize("scaler", [None, DummyScaler()])
def test_fqe_impl(
    observation_shape,
    action_size,
    learning_rate,
    optim_factory,
    encoder_factory,
    q_func_factory,
    gamma,
    n_critics,