Exemplo n.º 1
0
def test_vector_dataset_with_continuous_action():
    ref, _ = get_pendulum()

    # save as csv
    export_mdp_dataset_as_csv(ref, "test_data/test.csv")

    # load from csv
    dataset = import_csv_as_mdp_dataset("test_data/test.csv")

    assert dataset.get_observation_shape() == ref.get_observation_shape()
    assert dataset.get_action_size() == ref.get_action_size()
    assert np.allclose(dataset.observations, ref.observations)
    assert np.allclose(dataset.actions, ref.actions)
    assert np.allclose(dataset.rewards, ref.rewards)
    assert len(ref) == len(dataset)
    assert not dataset.is_action_discrete()
Exemplo n.º 2
0
def algo_pendulum_tester(algo, n_evaluations=100, n_episodes=500, n_trials=3):
    # load dataset
    dataset, env = get_pendulum()
    upper_bound = env.action_space.high

    # try multiple trials to reduce failures due to random seeds
    trial_count = 0
    for _ in range(n_trials):
        # reset parameters
        algo._impl = None

        # train
        algo.fit(
            dataset.episodes[:n_episodes],
            n_epochs=3,
            logdir="test_data",
            verbose=False,
            tensorboard=False,
        )

        # evaluation loop
        success_count = 0
        evaluation_count = 0
        while evaluation_count < n_evaluations:
            observation = env.reset()
            episode_rew = 0.0
            while True:
                action = algo.predict([observation])[0]
                observation, reward, done, _ = env.step(upper_bound * action)
                episode_rew += reward
                if done:
                    break
            evaluation_count += 1
            if episode_rew >= -600:
                success_count += 1

        if success_count >= n_evaluations * 0.8:
            break

        trial_count += 1
        if trial_count == n_trials:
            assert False, "performance is not good enough: %d." % success_count
Exemplo n.º 3
0
def test_get_pendulum(dataset_type):
    get_pendulum(dataset_type=dataset_type)
Exemplo n.º 4
0
from d3rlpy.datasets import get_pendulum
from minerva.dataset import export_mdp_dataset_as_csv

# prepare MDPDataset
dataset, _ = get_pendulum()

# save as CSV
export_mdp_dataset_as_csv(dataset, 'pendulum.csv')
Exemplo n.º 5
0
from d3rlpy.datasets import get_pendulum
from minerva.dataset import export_mdp_dataset_as_csv

# prepare MDPDataset
dataset, _ = get_pendulum(dataset_type="random")

# save as CSV
export_mdp_dataset_as_csv(dataset, 'pendulum_random.csv')