在 tensorflow 代理的环境教程(https://www.tensorflow.org/agents/tutorials/2_environments_tutorial)中,状态存储为整数。当需要状态时,将其转换为 numpy 数组:
from tf_agents.environments import py_environment
import numpy as np
class CardGameEnv(py_environment.PyEnvironment):
def __init__(self):
self._state = 0
def _step(self,action):
state_array = np.array([self._state], dtype=np.int32)
return np.transition(state_array, reward=1.0, discount=0.9)
他们这样做有什么理由,而不是直接将状态存储为一个 numpy 数组?所以像这样:
from tf_agents.environments import py_environment
import numpy as np
class CardGameEnv(py_environment.PyEnvironment):
def __init__(self):
self._state = np.array([0], dtype=np.int32)
def _step(self,action):
return np.transition(self._state, reward=1.0, discount=0.9)
使用第二种方法有什么缺点吗?或者这同样有效吗?