def create(cls, random_state=None):
"""
Each gene is picked with a uniform distribution from all allowed inputs or functions.
:param random_state: an instance of np.random.RandomState, a seed integer or None
:return: A random new class instance.
"""
random_state = check_random_state(random_state)
n_in = len(cls.pset.terminals)
operator_keys = list(range(n_in, max(cls.pset.mapping) + 1))
code = []
for i in range(cls.n_columns):
column = []
for j in range(cls.n_rows):
index = _code_index(n_in, cls.n_rows, i, j)
in_ = cls._valid_inputs[index]
gene = [random_state.choice(operator_keys)] + [random_state.choice(in_) for _ in range(cls.pset.max_arity)]
column.append(gene)
code.append(column)
outputs = [random_state.choice(cls._valid_inputs[_out_index(cls.n_rows, cls.n_columns, n_in, o)])
for o in range(cls.n_out)]
return cls(code, outputs)
评论列表
文章目录