You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The class MultiOneHot(OneHot) defined at torchrl\data\tensor_specs.py uses the "to_numpy" method from the OneHot class.
The method "to_numpy" from the OneHot class do not support translating multione hot vectors. Therefore an specific to_numpy method should be defined for the MultiOneHot(OneHot) class.
To Reproduce
importtorchfromtorchrl.data.tensor_specsimportMultiOneHot, OneHotval=torch.Tensor([0,0,1,0,0,0,0,0,0,0,0,1,0,0])
ts=MultiOneHot((11,3))
val=ts.to_numpy(val)
#The value of val is a numpy array with the single element of 2 rather than being [2,0]print(type(val)) # <class 'numpy.ndarray'>print(val) # 2
Expected behavior
In the previous code, is expected to obtain a numpy array with values [2,0].
In other words the translation to a numpy should provide a numpy array that matches the number of elements in the tuple provided to the nvec argument of the MultiOneHot class.
Is important to fix this issue because the gym environnements that uses the space MultiDiscrete are translated to MultiOneHot in torchrl (when using the GymWrapper). At some point when interacting with a Gym Environnement, the MultiOneHot needs to be translated back to a sample of the MultiDiscrete space, which needs to be translated correctly.
Reason and Possible fixes
To fix the bug when can use the self.to_categorical method of the MultiOneHot class which correctly translates the data to categorical. We only need to transform it to a numpy array. We can implement a to_numpy method specific to the MultiOneHot class (as shown below)
Describe the bug
The class
MultiOneHot(OneHot)
defined at torchrl\data\tensor_specs.py uses the "to_numpy" method from the OneHot class.The method "to_numpy" from the OneHot class do not support translating multione hot vectors. Therefore an specific to_numpy method should be defined for the MultiOneHot(OneHot) class.
To Reproduce
Expected behavior
In the previous code, is expected to obtain a numpy array with values [2,0].
In other words the translation to a numpy should provide a numpy array that matches the number of elements in the tuple provided to the nvec argument of the MultiOneHot class.
System info
Describe the characteristic of your environment:
Additional context
Is important to fix this issue because the gym environnements that uses the space MultiDiscrete are translated to MultiOneHot in torchrl (when using the GymWrapper). At some point when interacting with a Gym Environnement, the MultiOneHot needs to be translated back to a sample of the MultiDiscrete space, which needs to be translated correctly.
Reason and Possible fixes
To fix the bug when can use the
self.to_categorical
method of the MultiOneHot class which correctly translates the data to categorical. We only need to transform it to a numpy array. We can implement a to_numpy method specific to the MultiOneHot class (as shown below)The text was updated successfully, but these errors were encountered: