Added all feature to graphing functions
This commit is contained in:
@ -18,21 +18,44 @@ class Matplotlib_Graph:
|
|||||||
self.x = None
|
self.x = None
|
||||||
self.y = None
|
self.y = None
|
||||||
self.yscale = "linear"
|
self.yscale = "linear"
|
||||||
|
self.legend = False
|
||||||
|
|
||||||
|
def all_config_id(self,function):
|
||||||
|
"""Graph each config_id's data stored in the database
|
||||||
|
using multiple different colored lines."""
|
||||||
|
# Get all the config's
|
||||||
|
config_ids = self.database.get_all_config_id()
|
||||||
|
|
||||||
|
# Turn on the legend
|
||||||
|
self.legend = True
|
||||||
|
|
||||||
|
# Get the x and y data for each config_id
|
||||||
|
for config_id in config_ids:
|
||||||
|
|
||||||
|
# Get x and y data
|
||||||
|
x = self.database.get_each_generation_number(config_id)
|
||||||
|
y = function(config_id)
|
||||||
|
# Graph the line but dont show
|
||||||
|
self.type_of_graph(x, y, label=f"Config_id - {config_id}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generation_total_fitness(self, config_id = None):
|
def generation_total_fitness(self, config_id = None):
|
||||||
"""Show a plot of generation by generation total fitness."""
|
"""Show a plot of generation by generation total fitness."""
|
||||||
|
|
||||||
# Query the X data
|
if config_id == "all":
|
||||||
generations = self.database.get_total_generations(config_id)
|
# If the user want to plot all the config_id's
|
||||||
|
self.all_config_id(self.database.get_generation_total_fitness)
|
||||||
|
else:
|
||||||
|
# Query the X data
|
||||||
|
generations = self.database.get_total_generations(config_id)
|
||||||
|
# Create the generations list - [0,1,2,etc]
|
||||||
|
self.x = list(range(generations))
|
||||||
|
# Query for Y data
|
||||||
|
self.y = self.database.get_generation_total_fitness(config_id)
|
||||||
|
self.type_of_graph(self.x, self.y)
|
||||||
|
|
||||||
# Create the generations list - [0,1,2,etc]
|
|
||||||
self.x = list(range(generations))
|
|
||||||
|
|
||||||
# Query for Y data
|
|
||||||
self.y = self.database.get_generation_total_fitness(config_id)
|
|
||||||
|
|
||||||
self.type_of_graph(self.x, self.y)
|
|
||||||
plt.yscale(self.yscale)
|
plt.yscale(self.yscale)
|
||||||
plt.xlabel('Generation')
|
plt.xlabel('Generation')
|
||||||
plt.ylabel('Generation Total Fitness')
|
plt.ylabel('Generation Total Fitness')
|
||||||
@ -42,16 +65,18 @@ class Matplotlib_Graph:
|
|||||||
def highest_value_chromosome(self,config_id = None):
|
def highest_value_chromosome(self,config_id = None):
|
||||||
"""Generation by Max value chromosome """
|
"""Generation by Max value chromosome """
|
||||||
|
|
||||||
# Query the X data
|
if config_id == "all":
|
||||||
generations = self.database.get_total_generations(config_id)
|
# If the user want to plot all the config_id's
|
||||||
|
self.all_config_id(self.database.get_highest_chromosome)
|
||||||
|
else:
|
||||||
|
# Query the X data
|
||||||
|
generations = self.database.get_total_generations(config_id)
|
||||||
|
# Create the generations list - [0,1,2,etc]
|
||||||
|
self.x = list(range(generations))
|
||||||
|
# Query for Y data
|
||||||
|
self.y = self.database.get_highest_chromosome(config_id)
|
||||||
|
self.type_of_graph(self.x, self.y)
|
||||||
|
|
||||||
# Create the generations list - [0,1,2,etc]
|
|
||||||
self.x = list(range(generations))
|
|
||||||
|
|
||||||
# Query for Y data
|
|
||||||
self.y = self.database.get_highest_chromosome(config_id)
|
|
||||||
|
|
||||||
self.type_of_graph(self.x, self.y)
|
|
||||||
plt.yscale(self.yscale)
|
plt.yscale(self.yscale)
|
||||||
plt.xlabel('Generation')
|
plt.xlabel('Generation')
|
||||||
plt.ylabel('Highest Fitness')
|
plt.ylabel('Highest Fitness')
|
||||||
@ -61,16 +86,18 @@ class Matplotlib_Graph:
|
|||||||
def lowest_value_chromosome(self,config_id = None):
|
def lowest_value_chromosome(self,config_id = None):
|
||||||
"""Generation by Min value Chromosome """
|
"""Generation by Min value Chromosome """
|
||||||
|
|
||||||
# Query the X data
|
if config_id == "all":
|
||||||
generations = self.database.get_total_generations(config_id)
|
# If the user want to plot all the config_id's
|
||||||
|
self.all_config_id(self.database.get_lowest_chromosome)
|
||||||
|
else:
|
||||||
|
# Query the X data
|
||||||
|
generations = self.database.get_total_generations(config_id)
|
||||||
|
# Create the generations list - [0,1,2,etc]
|
||||||
|
self.x = list(range(generations))
|
||||||
|
# Query for Y data
|
||||||
|
self.y = self.database.get_lowest_chromosome(config_id)
|
||||||
|
self.type_of_graph(self.x, self.y)
|
||||||
|
|
||||||
# Create the generations list - [0,1,2,etc]
|
|
||||||
self.x = list(range(generations))
|
|
||||||
|
|
||||||
# Query for Y data
|
|
||||||
self.y = self.database.get_lowest_chromosome(config_id)
|
|
||||||
|
|
||||||
self.type_of_graph(self.x, self.y)
|
|
||||||
plt.yscale(self.yscale)
|
plt.yscale(self.yscale)
|
||||||
plt.xlabel('Generation')
|
plt.xlabel('Generation')
|
||||||
plt.ylabel('Lowest Fitness')
|
plt.ylabel('Lowest Fitness')
|
||||||
@ -79,6 +106,9 @@ class Matplotlib_Graph:
|
|||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
"""Used to show the matplot lib graph."""
|
"""Used to show the matplot lib graph."""
|
||||||
|
if self.legend == True:
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -178,7 +178,7 @@ class SQL_Database:
|
|||||||
"""Get the highest fitness of each generation"""
|
"""Get the highest fitness of each generation"""
|
||||||
|
|
||||||
return self.query_all(f"""
|
return self.query_all(f"""
|
||||||
SELECT fitness, max(fitness)
|
SELECT max(fitness)
|
||||||
FROM data
|
FROM data
|
||||||
WHERE config_id={config_id}
|
WHERE config_id={config_id}
|
||||||
GROUP by generation;""")
|
GROUP by generation;""")
|
||||||
@ -189,18 +189,34 @@ class SQL_Database:
|
|||||||
"""Get the lowest fitness of each generation"""
|
"""Get the lowest fitness of each generation"""
|
||||||
|
|
||||||
return self.query_all(f"""
|
return self.query_all(f"""
|
||||||
SELECT fitness, min(fitness)
|
SELECT min(fitness)
|
||||||
FROM data
|
FROM data
|
||||||
WHERE config_id={config_id}
|
WHERE config_id={config_id}
|
||||||
GROUP by generation;""")
|
GROUP by generation;""")
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_config_id(self):
|
||||||
|
"""Get an array of all the DISTINCT config_id in the database"""
|
||||||
|
|
||||||
|
return self.query_all(f"""
|
||||||
|
SELECT DISTINCT config_id
|
||||||
|
FROM config;""")
|
||||||
|
|
||||||
|
def get_each_generation_number(self,config_id):
|
||||||
|
"""Get an array of all the generation numbers"""
|
||||||
|
|
||||||
|
return self.query_all(f"""
|
||||||
|
SELECT DISTINCT generation
|
||||||
|
FROM data
|
||||||
|
WHERE config_id={config_id};""")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#=====================================#
|
#=====================================#
|
||||||
# Input information Queries: #
|
# Input information Queries: #
|
||||||
#=====================================#
|
#=====================================#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def insert_chromosome(self, generation, chromosome):
|
def insert_chromosome(self, generation, chromosome):
|
||||||
""" Insert one chromosome into the database"""
|
""" Insert one chromosome into the database"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user