Made final plotting of fitness and parameter history a function.

这个提交包含在:
Craig Warren
2015-12-22 17:37:30 +00:00
父节点 6cb3af53c8
当前提交 ce4eb3299c

查看文件

@@ -31,7 +31,6 @@ from enum import Enum
from collections import OrderedDict from collections import OrderedDict
import numpy as np import numpy as np
import matplotlib.pyplot as plt
from gprMax.constants import c, e0, m0, z0, floattype from gprMax.constants import c, e0, m0, z0, floattype
from gprMax.exceptions import CmdInputError from gprMax.exceptions import CmdInputError
@@ -79,7 +78,7 @@ def main():
# Process for Taguchi optimisation # # Process for Taguchi optimisation #
######################################## ########################################
if args.opt_taguchi: if args.opt_taguchi:
from user_libs.optimisations.taguchi import taguchi_code_blocks, select_OA, calculate_ranges_experiments, calculate_optimal_levels from user_libs.optimisations.taguchi import taguchi_code_blocks, select_OA, calculate_ranges_experiments, calculate_optimal_levels, plot_optimisation_history
# Default maximum number of iterations of optimisation to perform (used if the stopping criterion is not achieved) # Default maximum number of iterations of optimisation to perform (used if the stopping criterion is not achieved)
maxiterations = 20 maxiterations = 20
@@ -97,7 +96,7 @@ def main():
# Store initial parameter ranges # Store initial parameter ranges
optparamsinit = list(optparams.items()) optparamsinit = list(optparams.items())
# Dictionary to hold history of optmised values of parameters # Dictionary to hold history of optmised values of parameters
optparamshist = OrderedDict((key, list()) for key in optparams) optparamshist = OrderedDict((key, list()) for key in optparams)
@@ -250,20 +249,8 @@ def main():
print('\n{}\nTaguchi optimisation completed after {} iteration(s).\nHistory of optimal parameter values {} and of fitness values {}\n{}\n'.format(68*'*', i, dict(optparamshist), fitnessvalueshist, 68*'*')) print('\n{}\nTaguchi optimisation completed after {} iteration(s).\nHistory of optimal parameter values {} and of fitness values {}\n{}\n'.format(68*'*', i, dict(optparamshist), fitnessvalueshist, 68*'*'))
# Plot history of fitness values # Plot the history of fitness values and each optimised parameter values for the optimisation
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Iterations', ylabel='Fitness value'), num='History of fitness values', figsize=(20, 10), facecolor='w', edgecolor='w') plot_optimisation_history(fitnessvalueshist, optparamshist, optparamsinit)
ax.plot(fitnessvalueshist, 'r', marker='x', ms=10, lw=2)
ax.grid()
# Plot history of optimisation parameters
p = 0
for key, value in optparamshist.items():
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Iterations', ylabel='Parameter value'), num='History of ' + key + ' parameter', figsize=(20, 10), facecolor='w', edgecolor='w')
ax.plot(optparamshist[key], 'r', marker='x', ms=10, lw=2)
# ax.set_ylim([optparamsinit[p][1][0], optparamsinit[p][1][1]])
ax.grid()
p += 1
plt.show()
####################################### #######################################