Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rpreen committed May 19, 2024
1 parent 82504b8 commit d599605
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
11 changes: 4 additions & 7 deletions nkcs/ea.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ def to_string(self) -> str:

def mutate(self) -> None:
"""Mutate an individual."""
for i in range(len(self.genome)):
for i, gene in enumerate(self.genome):
if np.random.uniform(low=0, high=1) < Cons.P_MUT:
if self.genome[i] == 0:
self.genome[i] = 1
else:
self.genome[i] = 0
self.genome[i] = 1 if gene == 0 else 1

def uniform_crossover(self, parent: Ind) -> None:
"""Perform uniform crossover."""
Expand Down Expand Up @@ -192,9 +189,9 @@ def print_archive(self, s: int) -> None:
def print_pop(self) -> None:
"""Print the current populations."""
for s in range(Cons.S):
logger.info(f"Species {s}")
logger.info("Species %d", s)
for p in self.pop[s]:
logger.info(p.to_string())
logger.info("%s", p.to_string())

def run_ea(
self, nkcs: NKCS, evals: np.ndarray, pbest: np.ndarray, pavg: np.ndarray
Expand Down
4 changes: 1 addition & 3 deletions nkcs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

"""Main script for starting NKCS (co)evolutionary experiments."""
"""Main script for starting NKCS coevolutionary experiments."""

from __future__ import annotations

Expand All @@ -34,8 +34,6 @@
from .plot import plot

if __name__ == "__main__":
"""Run experiment.."""

# results storage
n_res: Final[int] = Cons.F * Cons.E
evals: np.ndarray = np.zeros((n_res, Cons.G))
Expand Down
4 changes: 2 additions & 2 deletions nkcs/nkcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ def display(self) -> None:
"""Print an NKCS species."""
logger.info(f"con: {self.map}")
logger.info("fitness table:")
for i in range(len(self.ftable)):
for i, fitness in enumerate(self.ftable):
logger.info(f"Gene {i}")
logger.info(self.ftable[i])
logger.info(fitness)

0 comments on commit d599605

Please sign in to comment.