mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-20 14:02:03 +00:00
Algorithmic refactor (#383)
* Refactor/document algorithmic environments and add tests. * test for 3 row addition * Fix failing rollout test by reinserting quirk in reversedAddition env * todo regarding addition3-v0 * Fix python 3 division issues * typo fix * Re-generate python3 rollout file to account for ReversedAddition bug fix
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
"""
|
||||
Task is to return every second character from the input tape.
|
||||
Task is to return every nth character from the input tape.
|
||||
http://arxiv.org/abs/1511.07275
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
import numpy as np
|
||||
from gym.envs.algorithmic import algorithmic_env
|
||||
from gym.envs.algorithmic.algorithmic_env import ha
|
||||
|
||||
class DuplicatedInputEnv(algorithmic_env.AlgorithmicEnv):
|
||||
class DuplicatedInputEnv(algorithmic_env.TapeAlgorithmicEnv):
|
||||
def __init__(self, duplication=2, base=5):
|
||||
self.duplication = duplication
|
||||
algorithmic_env.AlgorithmicEnv.__init__(self,
|
||||
inp_dim=1,
|
||||
base=base,
|
||||
chars=True)
|
||||
def set_data(self):
|
||||
self.content = {}
|
||||
self.target = {}
|
||||
copies = int(self.total_len / self.duplication)
|
||||
for i in range(copies):
|
||||
val = self.np_random.randint(self.base)
|
||||
self.target[i] = val
|
||||
for d in range(self.duplication):
|
||||
self.content[ha(np.array([i * self.duplication + d]))] = val
|
||||
self.total_reward = self.total_len / self.duplication
|
||||
super(DuplicatedInputEnv, self).__init__(base=base, chars=True)
|
||||
|
||||
def generate_input_data(self, size):
|
||||
res = []
|
||||
if size < self.duplication:
|
||||
size = self.duplication
|
||||
for i in range(size//self.duplication):
|
||||
char = self.np_random.randint(self.base)
|
||||
for _ in range(self.duplication):
|
||||
res.append(char)
|
||||
return res
|
||||
|
||||
def target_from_input_data(self, input_data):
|
||||
return [input_data[i] for i in range(0, len(input_data), self.duplication)]
|
||||
|
Reference in New Issue
Block a user