Skip to content

Commit

Permalink
Black formatting and future imports to solve problem of forward refer…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
mschmidt87 committed Apr 10, 2020
1 parent 3f9086b commit 40d18e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gp/cartesian_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, genome: gp.Genome) -> None:
self.parse_genome(genome)
self._genome = genome

def __repr__(self):
def __repr__(self) -> str:
return "CartesianGraph(" + str(self._nodes) + ")"

def print_active_nodes(self) -> str:
Expand Down
31 changes: 21 additions & 10 deletions gp/genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
class Genome:
"""Genome class for individuals.
"""
def __init__(self, n_inputs: int, n_outputs: int, n_columns: int,
n_rows: int, levels_back: int, primitives: List[gp.CPGNode]) -> None:

def __init__(
self,
n_inputs: int,
n_outputs: int,
n_columns: int,
n_rows: int,
levels_back: int,
primitives: List[gp.CPGNode],
) -> None:
"""Init function.
Parameters
Expand Down Expand Up @@ -97,7 +105,7 @@ def _n_genes(self) -> int:
return self._n_regions * self._length_per_region

def __repr__(self) -> str:
s = self.__class__.__name__ + '('
s = self.__class__.__name__ + "("
for region_idx, input_region in self.iter_input_regions():
s += str(region_idx) + ": " + str(input_region) + " | "
for region_idx, hidden_region in self.iter_hidden_regions():
Expand All @@ -117,8 +125,9 @@ def _create_input_region(self) -> list:
region += [self._non_coding_allele] * self._primitives.max_arity
return region

def _create_random_hidden_region(self, rng: np.random.RandomState,
permissable_inputs: int) -> list:
def _create_random_hidden_region(
self, rng: np.random.RandomState, permissable_inputs: int
) -> list:

# construct dna region consisting of function allele and
# input alleles
Expand All @@ -136,8 +145,9 @@ def _create_random_hidden_region(self, rng: np.random.RandomState,

return region

def _create_random_output_region(self, rng: np.random.RandomState,
permissable_inputs: int) -> list:
def _create_random_output_region(
self, rng: np.random.RandomState, permissable_inputs: int
) -> list:

# fill region with identifier for output node and single
# gene determining input
Expand Down Expand Up @@ -379,9 +389,10 @@ def _mutate_output_region(self, gene_idx, region_idx, rng):

return False

def _mutate_hidden_region(self, gene_idx: int, region_idx: int,
rng: np.random.RandomState) -> bool:
assert(self._is_hidden_region(region_idx))
def _mutate_hidden_region(
self, gene_idx: int, region_idx: int, rng: np.random.RandomState
) -> bool:
assert self._is_hidden_region(region_idx)

if self._is_function_gene(gene_idx):
self._dna[gene_idx] = self._primitives.sample(rng)
Expand Down
2 changes: 1 addition & 1 deletion gp/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def max_arity(self) -> int:

@property
def inputs(self) -> List[int]:
return self._inputs[:self._arity]
return self._inputs[: self._arity]

@property
def idx(self) -> int:
Expand Down
5 changes: 3 additions & 2 deletions gp/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def _generate_random_individuals(self, n: int) -> None:

return individuals

def crossover(self, breeding_pool: List[gp.AbstractIndividual],
n_offsprings: int) -> List[gp.AbstractIndividual]:
def crossover(
self, breeding_pool: List[gp.AbstractIndividual], n_offsprings: int
) -> List[gp.AbstractIndividual]:
"""Create an offspring population via crossover.
Parameters
Expand Down

0 comments on commit 40d18e7

Please sign in to comment.