Commit
·
c0124b2
1
Parent(s):
ce771b8
Update automata.py
Browse files- automata.py +6 -9
automata.py
CHANGED
@@ -42,14 +42,12 @@ class MockupDataset(datasets.GeneratorBasedBuilder):
|
|
42 |
VERSION = datasets.Version("0.0.0")
|
43 |
BUILDER_CONFIGS = []
|
44 |
|
45 |
-
def __init__(self, name=
|
46 |
super().__init__(**kwargs)
|
47 |
|
48 |
"""
|
49 |
Set default configs
|
50 |
"""
|
51 |
-
if name is None:
|
52 |
-
name = 'parity'
|
53 |
if 'length' not in data_config:
|
54 |
data_config['length'] = 20
|
55 |
if 'size' not in data_config:
|
@@ -84,7 +82,6 @@ class MockupDataset(datasets.GeneratorBasedBuilder):
|
|
84 |
)
|
85 |
]
|
86 |
|
87 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
88 |
def _generate_examples(self, split):
|
89 |
for i in itertools.count(start=0):
|
90 |
if i == self.data_config['size']:
|
@@ -133,10 +130,10 @@ class ParitySampler(AutomatonSampler):
|
|
133 |
return x, self.f(x)
|
134 |
|
135 |
|
136 |
-
class
|
137 |
def __init__(self, data_config):
|
138 |
super(FlipflopSampler, self).__init__(data_config)
|
139 |
-
self.name = '
|
140 |
self.data_config = data_config
|
141 |
|
142 |
self.n_actions = self.n_states + 1
|
@@ -145,8 +142,8 @@ class FlipflopSampler(AutomatonSampler):
|
|
145 |
def f(self, x):
|
146 |
state, states = 0, []
|
147 |
for action in x:
|
148 |
-
|
149 |
-
|
150 |
return np.array(states)
|
151 |
|
152 |
def sample(self):
|
@@ -159,7 +156,7 @@ class FlipflopSampler(AutomatonSampler):
|
|
159 |
|
160 |
dataset_map = {
|
161 |
'parity': ParitySampler,
|
162 |
-
'flipflop':
|
163 |
# TODO: more datasets
|
164 |
}
|
165 |
|
|
|
42 |
VERSION = datasets.Version("0.0.0")
|
43 |
BUILDER_CONFIGS = []
|
44 |
|
45 |
+
def __init__(self, name='parity', data_config={}, **kwargs):
|
46 |
super().__init__(**kwargs)
|
47 |
|
48 |
"""
|
49 |
Set default configs
|
50 |
"""
|
|
|
|
|
51 |
if 'length' not in data_config:
|
52 |
data_config['length'] = 20
|
53 |
if 'size' not in data_config:
|
|
|
82 |
)
|
83 |
]
|
84 |
|
|
|
85 |
def _generate_examples(self, split):
|
86 |
for i in itertools.count(start=0):
|
87 |
if i == self.data_config['size']:
|
|
|
130 |
return x, self.f(x)
|
131 |
|
132 |
|
133 |
+
class FlipFlopSampler(AutomatonSampler):
|
134 |
def __init__(self, data_config):
|
135 |
super(FlipflopSampler, self).__init__(data_config)
|
136 |
+
self.name = 'flipflop'
|
137 |
self.data_config = data_config
|
138 |
|
139 |
self.n_actions = self.n_states + 1
|
|
|
142 |
def f(self, x):
|
143 |
state, states = 0, []
|
144 |
for action in x:
|
145 |
+
state = self.transition[state, action]
|
146 |
+
states += state,
|
147 |
return np.array(states)
|
148 |
|
149 |
def sample(self):
|
|
|
156 |
|
157 |
dataset_map = {
|
158 |
'parity': ParitySampler,
|
159 |
+
'flipflop': FlipFlopSampler,
|
160 |
# TODO: more datasets
|
161 |
}
|
162 |
|