Skip to content

Commit

Permalink
Merge branch 'develop' into bobosr
Browse files Browse the repository at this point in the history
  • Loading branch information
gbomarito committed Jan 6, 2025
2 parents 263dc89 + 44fcbfe commit 5212b20
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bingo/symbolic_regression/agraph/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
mutation, node mutation, parameter mutation and pruning.
"""

from random import randint, randrange

import numpy as np

from .operator_definitions import (
Expand Down Expand Up @@ -338,7 +336,7 @@ def _insert_fork(self, stack, fork_size, mutated_command_location, start_i, end_
"""
try: # normal case
arity_2_op = self._get_arity_operator(2)
n_terminals = randint(1, fork_size // 2)
n_terminals = np.random.randint(1, fork_size // 2 + 1)

for i in range(start_i, start_i + fork_size):
if i < start_i + n_terminals:
Expand All @@ -347,7 +345,11 @@ def _insert_fork(self, stack, fork_size, mutated_command_location, start_i, end_
elif i == start_i + fork_size - 1:
# make sure end of the stack is always a utilized command
stack[end_i] = np.array(
[arity_2_op, mutated_command_location, randrange(start_i, i)],
[
arity_2_op,
mutated_command_location,
np.random.randint(start_i, i),
],
dtype=int,
)
# insert an arity 2 operator that
Expand All @@ -356,8 +358,8 @@ def _insert_fork(self, stack, fork_size, mutated_command_location, start_i, end_
stack[i] = np.array(
[
self._component_generator.random_operator(),
randrange(start_i, i),
randrange(start_i, i),
np.random.randint(start_i, i),
np.random.randint(start_i, i),
],
dtype=int,
)
Expand Down

0 comments on commit 5212b20

Please sign in to comment.