Skip to content

Commit

Permalink
feat: merge conflict incoming (add graph and arguments)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vetlets05 committed Oct 24, 2024
1 parent 228be87 commit 2f0798d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
31 changes: 25 additions & 6 deletions gui_with_pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import threading
import os
import argparse

import src.utils.config as conf
import pickle
Expand Down Expand Up @@ -404,7 +405,7 @@ def __init__(self):
self.fitness_graph = ImageSprite("data/fitness/fitness_plot.png", (700, 100))
except:
print("ERROR: Could not find image path")
self.fitness_graph = 0
self.fitness_graph = ImageSprite("genome_frames/genome_0.png", (700, 100))



Expand Down Expand Up @@ -454,7 +455,7 @@ def __init__(self):
self.watch_genes_visualize = ImageSprite("genome_frames/genome_0.png", (700, 50), (600, 400))

## Run button
self.run_button = Button(600, 20, 200, 50, "Run Selected Genomes", st.font, st.text_color, st.button_color, st.hover_color, st.pressed_color, self.start_watching_process)
self.run_button = Button(600, 20, 200, 50, "Run Selected Genomes", st.font, st.text_color, st.button_color, st.hover_color, st.pressed_color, self.run_selected_genomes)
self.watch_back_button = Button(200, 450, 200, 50, "Back", st.font, st.text_color, st.button_color, st.hover_color, st.pressed_color, self.main_menu_scene)

#Visualize best genome
Expand Down Expand Up @@ -586,7 +587,20 @@ def start_training(self):
generations = self.training_input_fields[2].text
print(f"Starting training with Population: {population}, Mutation Rate: {mutation_rate}, Generations: {generations}")
# Insert your training code here (e.g. NEAT training)
neat_test_file.main()


parser = argparse.ArgumentParser(description="Train or Test Genomes")
subparsers = parser.add_subparsers(dest="command", help="Choose 'train', 'test', 'graph', or 'play'")

# Train command (runs main())
train_parser = subparsers.add_parser('train', help="Run the training process")
train_parser.add_argument('-n', '--neat_name', type=str, default='', help="The name of the NEAT object to load from 'trained_population/'")
train_parser.add_argument('-g', '--n_generations', type=int, default=-1, help="The number of generations to train for")

sim_args = ["train", "-g", generations]
args=parser.parse_args(sim_args)

neat_test_file.main(args=args)


def draw_settings_scene(self):
Expand Down Expand Up @@ -617,11 +631,16 @@ def update_screen(self):
element.draw(self.screen)
for element in self.training_UI:
element.draw(self.screen)
#self.fitness_graph.draw(self.screen)

try:
self.fitness_graph = ImageSprite("data/fitness/fitness_plot.png", (700, 100))
except:
pass
self.fitness_graph.draw(self.screen)
gen_data,best_fitness_data,avg_fitness_data,min_fitness_data = util.read_fitness_file("data/fitness/fitness_values.txt")
self.new_fitness_graph = Graph(self.screen, (700, 100), (400, 400), best_fitness_data)
#self.new_fitness_graph = Graph(self.screen, (700, 100), (400, 400), best_fitness_data)

self.new_fitness_graph.draw()
#self.new_fitness_graph.draw()


elif st.sc_selector == 2:
Expand Down
2 changes: 1 addition & 1 deletion src/environments/mario_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from gym.spaces import Box
from gym.core import ObservationWrapper
import numpy as np
# import cv2
import cv2
from skimage.transform import resize

class StepResult(NamedTuple):
Expand Down
3 changes: 3 additions & 0 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from src.genetics.genome import Genome
from src.utils.config import Config
import matplotlib
matplotlib.use("Agg")

import matplotlib.pyplot as plt
import numpy as np
import os
Expand Down
2 changes: 2 additions & 0 deletions src/visualization/colors_visualization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from src.utils.utils import normalize_negative_values, normalize_positive_values
import numpy as np
from typing import List
import matplotlib
matplotlib.use("Agg")
import matplotlib.cm as cm
from src.genetics.node import Node

Expand Down
2 changes: 2 additions & 0 deletions src/visualization/visualize_genome.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import networkx as nx
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.axes import Axes
from src.genetics.genome import Genome
Expand Down

0 comments on commit 2f0798d

Please sign in to comment.