我创建了一个自定义的 openai 健身房环境,其中包含离散的动作空间和稍微复杂的状态空间。状态空间被定义为元组,因为它结合了一些连续的维度和其他离散的维度:
import gym
from gym import spaces
class CustomEnv(gym.Env):
def __init__(self):
self.action_space = spaces.Discrete(3)
self.observation_space = spaces.Tuple((spaces.Discrete(16),
spaces.Discrete(2),
spaces.Box(0,20000,shape=(1,)),
spaces.Box(0,1000,shape=(1,)))
...
Run Code Online (Sandbox Code Playgroud)
我很幸运地使用 keras-rl(特别是 DQNAgent)训练了一个代理,但是 keras-rl 的支持不足且文档很少。对于可以处理此类观察空间的强化学习包有什么建议吗?目前看来 openai 基线和 stable-baselines 都无法处理它。
或者,是否有一种不同的方式可以定义我的状态空间,以便将我的环境适应这些定义更好的包之一?
python machine-learning reinforcement-learning openai-gym keras-rl
我在自定义环境中训练了 Ray-RLlib PPOTrainer。如何评估特定州的政策?
完整示例:
from ray.rllib.agents.ppo import PPOTrainer
from cust_env.envs import CustEnv
from ray.tune.logger import pretty_print
ray.init()
config = ppo.DEFAULT_CONFIG.copy()
config["num_workers"] = 2
config["eager"] = False
config["output"] = 'tmp/debug/'
trainer = PPOTrainer(config=config, env=TravelEnv)
# Can optionally call trainer.restore(path) to load a checkpoint.
for i in range(101):
result = trainer.train()
if i % 10 == 0:
print(pretty_print(result))
Run Code Online (Sandbox Code Playgroud)
有没有一种方法,如下所示,我可以在给定状态下返回最佳操作?
policy = trainer.get_policy()
optimal_action_at_state_S = policy.get_optimal_action(S)
Run Code Online (Sandbox Code Playgroud)
该函数policy.compute_actions( )似乎从随机策略中返回随机样本,而不是最优操作。