1
0
mirror of https://github.com/gryf/coach.git synced 2025-12-17 19:20:19 +01:00

Additional cmd line examples (#377)

Adding command line examples to the Quick Start Guide tutorial
This commit is contained in:
Gal Novik
2019-07-15 12:32:59 +03:00
committed by GitHub
parent 19ad2d60a7
commit 0a4cc7e081
2 changed files with 205 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
import numpy as np
from typing import List
from rl_coach.core_types import ActionType
from rl_coach.spaces import ActionSpace
from rl_coach.exploration_policies.exploration_policy import ExplorationPolicy, ExplorationParameters
class MyExplorationPolicy(ExplorationPolicy):
"""
An exploration policy takes the predicted actions or action values from the agent, and selects the action to
actually apply to the environment using some predefined algorithm.
"""
def __init__(self, action_space: ActionSpace):
#self.phase = RunPhase.HEATUP
self.action_space = action_space
super().__init__(action_space)
def get_action(self, action_values: List[ActionType]) -> ActionType:
if (np.random.rand() < 0.5):
chosen_action = self.action_space.sample()
else:
chosen_action = np.argmax(action_values)
probabilities = np.zeros(len(self.action_space.actions))
probabilities[chosen_action] = 1
return chosen_action, probabilities
def get_control_param(self):
return 0
class MyExplorationParameters(ExplorationParameters):
def __init__(self):
super().__init__()
@property
def path(self):
return 'exploration:MyExplorationPolicy'