Ejemplo n.º 1
0
    def test_render_episodes_to_str(self):
        ppo_agent = PpoAgent( 'CartPole-v0', training_duration=TrainingDurationSingleEpisode(), logging=LoggingVerbose() )
        ppo_agent.train()

        result = ppo_agent.render_episodes_to_str()
        assert isinstance(result,str), "render_episodes_to_str did not return a string"
        return
#
# simple easyagents demo using cartpole

from easyagents.tfagents import PpoAgent
from easyagents.config import TrainingDurationSingleEpisode
from easyagents.config import TrainingDurationFast
from easyagents.config import LoggingVerbose

ppo_agent = PpoAgent(gym_env_name='CartPole-v0',
                     training_duration=TrainingDurationFast(),
                     logging=LoggingVerbose())
ppo_agent.train()

ppo_agent.plot_average_rewards()
ppo_agent.plot_losses()
ppo_agent.render_episodes_to_mp4()
ppo_agent.render_episodes_to_html(fps=20)
Ejemplo n.º 3
0
    def test_plot_with_ylim(self):
        ppo_agent = PpoAgent( 'CartPole-v0', training_duration=TrainingDurationSingleEpisode(), logging=LoggingVerbose() )
        ppo_agent.train()

        ppo_agent.plot_losses(ylim=[10,20])
        return
Ejemplo n.º 4
0
    def test_render_episodes(self):
        ppo_agent = PpoAgent( 'CartPole-v0', training_duration=TrainingDurationSingleEpisode(), logging=LoggingVerbose() )
        ppo_agent.train()

        ppo_agent.render_episodes()
        return
Ejemplo n.º 5
0
    def test_plot_no_ylim(self):
        ppo_agent = PpoAgent( 'CartPole-v0', training_duration=TrainingDurationSingleEpisode(), logging=LoggingVerbose() )
        ppo_agent.train()

        ppo_agent.plot_average_rewards()
        return
Ejemplo n.º 6
0
 def test_ppo_str(self):
     ppo_agent = PpoAgent( self.gym_env_name, training_duration=TrainingDurationFast() )
     result = str(ppo_agent)
     print(result)
     return       
Ejemplo n.º 7
0
 def test_ppo_train(self):
     ppo_agent = PpoAgent( self.gym_env_name, training_duration=TrainingDurationFast() )
     ppo_agent.train()
     return
Ejemplo n.º 8
0
 def test_ppo_create(self):
     ppo_agent = PpoAgent( self.gym_env_name )
     self.assertIsNotNone( ppo_agent, "failed to create a tfagents.Ppo instance for " + self.gym_env_name )
     return
if not 'isEnvRegistered' in locals():
    env_name = "Berater-v1"
    gym.envs.registration.register(id=env_name,
                                   entry_point=BeraterEnv,
                                   max_episode_steps=1000)
    isEnvRegistered = True
    print("Berater registered as '" + env_name + "'")
else:
    print("Already registered")

#%%

from easyagents.tfagents import PpoAgent
from easyagents.config import TrainingDurationFast
from easyagents.config import LoggingVerbose

ppo_agent = PpoAgent(
    gym_env_name='Berater-v1',
    fc_layers=(500, 500, 500),
    training_duration=TrainingDurationFast(max_steps_per_episode=50),
    # logging=LoggingVerbose(),
    learning_rate=1e-4)
ppo_agent.train()

#%%
ppo_agent.render_episodes_to_mp4(num_episodes=1,
                                 filepath='c:\\temp\\_orso.mp4')

#%%