你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 15:27:57 +08:00
Added some code to plot optimisation results.
这个提交包含在:
@@ -31,6 +31,7 @@ from enum import Enum
|
||||
from collections import OrderedDict
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from gprMax.constants import c, e0, m0, z0, floattype
|
||||
from gprMax.exceptions import CmdInputError
|
||||
@@ -81,7 +82,7 @@ def main():
|
||||
from user_libs.optimisations.taguchi import taguchi_code_blocks, select_OA, calculate_ranges_experiments, calculate_optimal_levels
|
||||
|
||||
# Default maximum number of iterations of optimisation to perform (used if the stopping criterion is not achieved)
|
||||
maxiterations = 15
|
||||
maxiterations = 20
|
||||
|
||||
# Process Taguchi code blocks in the input file; pass in ordered dictionary to hold parameters to optimise
|
||||
tmp = usernamespace.copy()
|
||||
@@ -235,7 +236,7 @@ def main():
|
||||
# Rename confirmation experiment output file so that it is retained for each iteraction
|
||||
os.rename(outputfile, os.path.splitext(outputfile)[0] + '_final' + str(i + 1) + '.out')
|
||||
|
||||
print('\nTaguchi optimisation, iteration {} completed with optimal values {} and fitness value {}'.format(i + 1, dict(optparams), fitnessvalueshist[i], 68*'*'))
|
||||
print('\nTaguchi optimisation, iteration {} completed. History of optimal parameter values {} and of fitness values {}'.format(i + 1, dict(optparamshist), fitnessvalueshist, 68*'*'))
|
||||
|
||||
i += 1
|
||||
|
||||
@@ -243,11 +244,31 @@ def main():
|
||||
if fitnessvalueshist[i - 1] > fitness['stop']:
|
||||
break
|
||||
|
||||
# Stop optimisation if successive fitness values are close to one another
|
||||
if i > 1 and fitnessvalueshist[i - 1] - fitnessvalueshist[i - 2] < 0.0001:
|
||||
break
|
||||
|
||||
# Save optimisation parameters history and fitness values history to file
|
||||
opthistfile = inputfileparts[0] + '_hist'
|
||||
np.savez(opthistfile, dict(optparamshist), fitnessvalueshist)
|
||||
|
||||
print('\n{}\nTaguchi optimisation completed after {} iteration(s).\nConvergence history of optimal 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
|
||||
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Iterations', ylabel='Fitness value'), num='History of fitness values', figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
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()
|
||||
|
||||
|
||||
#######################################
|
||||
# Process for standard simulation #
|
||||
|
在新工单中引用
屏蔽一个用户