mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-30 01:50:19 +00:00
Fix seed
method for spaces.Tuple
and spaces.Dict
(#2365)
* Fix seed method for Tuple and Dict * Improve stochasticity * Update test cases for seed method * Update test cases for seed method Update test cases for seed method Update test cases for seed method
This commit is contained in:
@@ -19,7 +19,24 @@ class Tuple(Space):
|
||||
super(Tuple, self).__init__(None, None)
|
||||
|
||||
def seed(self, seed=None):
|
||||
[space.seed(seed) for space in self.spaces]
|
||||
seed = super().seed(seed)
|
||||
try:
|
||||
subseeds = self.np_random.choice(
|
||||
np.iinfo(int).max,
|
||||
size=len(self.spaces),
|
||||
replace=False, # unique subseed for each subspace
|
||||
)
|
||||
except ValueError:
|
||||
subseeds = self.np_random.choice(
|
||||
np.iinfo(int).max,
|
||||
size=len(self.spaces),
|
||||
replace=True, # we get more than INT_MAX subspaces
|
||||
)
|
||||
|
||||
for subspace, subseed in zip(self.spaces, subseeds):
|
||||
seed.append(subspace.seed(int(subseed))[0])
|
||||
|
||||
return seed
|
||||
|
||||
def sample(self):
|
||||
return tuple([space.sample() for space in self.spaces])
|
||||
|
Reference in New Issue
Block a user