def crossover_rows(self, rows1: List[List], rows2: List[List]) -> List[List]: num_states = len(rows1) // 2 cross_point = 2 * self._random.randint(0, num_states) new_rows = copy_lists(rows1[:cross_point]) new_rows += copy_lists(rows2[cross_point:]) return new_rows
def __init__(self, transitions_C=None, transitions_D=None, emission_probabilities=None, initial_state=0, initial_action=C) -> None: super().__init__() if not transitions_C: transitions_C = [[1]] transitions_D = [[1]] emission_probabilities = [0.5] # Not stochastic initial_state = 0 self.initial_state = initial_state self.initial_action = initial_action self.hmm = SimpleHMM(copy_lists(transitions_C), copy_lists(transitions_D), list(emission_probabilities), initial_state) assert self.hmm.is_well_formed() self.state = self.hmm.state self.classifier["stochastic"] = self.is_stochastic()
def crossover_rows(rows1, rows2): num_states = len(rows1) // 2 cross_point = 2 * randrange(num_states) new_rows = copy_lists(rows1[:cross_point]) new_rows += copy_lists(rows2[cross_point:]) return new_rows
def test_copy_lists(self): l1 = [list(range(10)), list(range(20))] l2 = copy_lists(l1) self.assertIsNot(l1, l2)