cyrilzhang commited on
Commit
cf2b634
1 Parent(s): b0d21d5

fix indentation

Browse files
Files changed (1) hide show
  1. automata.py +14 -15
automata.py CHANGED
@@ -250,12 +250,12 @@ class ABABAutomaton(BinaryInputAutomaton):
250
  self.prob_abab_pos_sample = data_config['prob_abab_pos_sample']
251
  self.label_type = data_config['label_type']
252
 
253
- self.transition = np.array(
254
- [[4, 1], # state 0
255
- [2, 4], # state 1
256
- [4, 3], # state 2
257
- [0, 4], # state 3
258
- [4, 4], # state 4
259
  ])
260
 
261
  self.__info__ = "abab: an automaton with 4 states + 1 absorbing state:\n" \
@@ -662,7 +662,7 @@ class QuaternionAutomaton(Automaton):
662
  def __init__(self, data_config):
663
  super().__init__(data_config)
664
 
665
- self.vocab_size = 8 # {-1, 1} x {1, i, j, k}
666
  self.n_actions = 4 # {1, i, j, k}
667
  self.transition_pos = [
668
  0, 1, 2, 3,
@@ -693,7 +693,6 @@ class QuaternionAutomaton(Automaton):
693
  x = self.np_rng.choice(range(self.n_actions), size=T)
694
  return x, self.f(x)
695
 
696
-
697
  class PermutationResetAutomaton(Automaton):
698
  def __init__(self, data_config):
699
  super().__init__(data_config)
@@ -704,9 +703,9 @@ class PermutationResetAutomaton(Automaton):
704
  if type(self.generators[0]) is str:
705
  self.generators = [ np.array(list(map(int, list(g)))) for g in self.generators ]
706
 
707
- self.vocab_size = math.factorial(self.n) # states = permutations; maybe rename
708
  self.n_generators = len(self.generators) # actions = generators
709
- self.n_actions = self.vocab_size + self.n_generators # 1 reset symbol per state, 1 apply symbol per generator
710
 
711
  self.init_state = np.arange(self.n) # identity permutation
712
 
@@ -724,20 +723,20 @@ class PermutationResetAutomaton(Automaton):
724
  curr_state = self.init_state
725
  states = []
726
  for action_id in x:
727
- if action_id >= self.vocab_size:
728
- curr_state = self.generators[action_id - self.vocab_size][curr_state]
729
  else:
730
  curr_state = self.int2perm[action_id]
731
- states.append(self.perm2int[tuple(curr_state)])
732
  return np.array(states, dtype=np.int64)
733
 
734
  def sample(self):
735
  T = self.sample_length()
736
- x = self.np_rng.choice(range(self.n_generators), p=self.perm_probs, size=T) + self.vocab_size
737
 
738
  i = 0
739
  while i < T:
740
- x[i] = self.np_rng.choice(range(self.vocab_size))
741
  i += self.np_rng.choice(self.lags)
742
 
743
  return x, self.f(x)
 
250
  self.prob_abab_pos_sample = data_config['prob_abab_pos_sample']
251
  self.label_type = data_config['label_type']
252
 
253
+ self.transition = np.array([
254
+ [4, 1], # state 0
255
+ [2, 4], # state 1
256
+ [4, 3], # state 2
257
+ [0, 4], # state 3
258
+ [4, 4], # state 4
259
  ])
260
 
261
  self.__info__ = "abab: an automaton with 4 states + 1 absorbing state:\n" \
 
662
  def __init__(self, data_config):
663
  super().__init__(data_config)
664
 
665
+ self.n_states = 8 # {-1, 1} x {1, i, j, k}
666
  self.n_actions = 4 # {1, i, j, k}
667
  self.transition_pos = [
668
  0, 1, 2, 3,
 
693
  x = self.np_rng.choice(range(self.n_actions), size=T)
694
  return x, self.f(x)
695
 
 
696
  class PermutationResetAutomaton(Automaton):
697
  def __init__(self, data_config):
698
  super().__init__(data_config)
 
703
  if type(self.generators[0]) is str:
704
  self.generators = [ np.array(list(map(int, list(g)))) for g in self.generators ]
705
 
706
+ self.n_states = math.factorial(self.n) # states = permutations; maybe rename
707
  self.n_generators = len(self.generators) # actions = generators
708
+ self.n_actions = self.n_states + self.n_generators # 1 reset symbol per state, 1 apply symbol per generator
709
 
710
  self.init_state = np.arange(self.n) # identity permutation
711
 
 
723
  curr_state = self.init_state
724
  states = []
725
  for action_id in x:
726
+ if action_id >= self.n_states:
727
+ curr_state = self.generators[action_id - self.n_states][curr_state]
728
  else:
729
  curr_state = self.int2perm[action_id]
730
+ states.append(self.perm2int[tuple(curr_state)])
731
  return np.array(states, dtype=np.int64)
732
 
733
  def sample(self):
734
  T = self.sample_length()
735
+ x = self.np_rng.choice(range(self.n_generators), p=self.perm_probs, size=T) + self.n_states
736
 
737
  i = 0
738
  while i < T:
739
+ x[i] = self.np_rng.choice(range(self.n_states))
740
  i += self.np_rng.choice(self.lags)
741
 
742
  return x, self.f(x)