0

My agent needs to set an action based on a position which can be represented as a integer value (e.g. np.int32). This integer value will then be used for indexing the certain array. Furthermore, a float number will be assigned to this position. Therefore I would like to specify the action by a list of tuples where the first element for each tuple has an integer dtype and the second element a float dtype. I tried to use a numpy structured array:

self._action_spec = array_spec.ArraySpec(
        shape=(highestCoinIndex,2), dtype=[('id', np.int32), ('value', np.float64)], name='action')

This seems not to work because I get the following error:

TypeError: Cannot convert the argument `type_value`: dtype([('id', '<i4'), ('value', '<f8')]) to a TensorFlow DType. 
In call to configurable 'BoundedArraySpec' (<class 'tf_agents.specs.array_spec.BoundedArraySpec'>)

Is there a way how I can specify a list or tuple with different dtypes for e.g. self._action_spec?

Ling
  • 449
  • 6
  • 21
  • If tensorflow docs don't say anything about structured arrays or compound dtypes, then there probably isn't. While sometimes convenient in `numpy` for dataframe like stuff, structured arrays don'r help with computations. You can't for example do math across fields.. – hpaulj Apr 14 '22 at 00:32
  • Thanks for your answer! I thought to use a cast, but this is also problematic since when I do not use a int as dtyp the agent will assign a random float number instead of a natural number (e.g. by testing via ``utils.validate_py_environment(env, episodes=5)``). Is there another way to restrict the agent to use a natural number for the first element and a float number for the second element directly in the environment? – Ling Apr 14 '22 at 10:02

0 Answers0